init: initial commit
This commit is contained in:
15
scripts/coin.gd
Normal file
15
scripts/coin.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Area2D
|
||||
|
||||
@export var coin_id: String
|
||||
|
||||
func _ready():
|
||||
if coin_id == "":
|
||||
coin_id = name
|
||||
|
||||
if GameManager.collected_coins.has(coin_id):
|
||||
queue_free()
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
GameManager.add_score()
|
||||
GameManager.collected_coins[coin_id] = true
|
||||
queue_free()
|
||||
1
scripts/coin.gd.uid
Normal file
1
scripts/coin.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ct437mnkqt5dw
|
||||
22
scripts/game_manager.gd
Normal file
22
scripts/game_manager.gd
Normal file
@@ -0,0 +1,22 @@
|
||||
extends Node
|
||||
|
||||
var score = 0
|
||||
var hearts = 3
|
||||
var collected_coins = {}
|
||||
|
||||
@onready var score_node = HUD.get_node("Coins/ScoreLabel")
|
||||
@onready var hearts_node = HUD.get_node("Hearts/HeartsLabel")
|
||||
|
||||
func _ready() -> void:
|
||||
score = 0
|
||||
score_node.text = str(score)
|
||||
hearts = 3
|
||||
hearts_node.text = str(hearts)
|
||||
|
||||
func add_score():
|
||||
score += 1
|
||||
score_node.text = str(score)
|
||||
|
||||
func reduce_hearts():
|
||||
hearts -= 1
|
||||
hearts_node.text = str(hearts)
|
||||
1
scripts/game_manager.gd.uid
Normal file
1
scripts/game_manager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bd0bxlq84buib
|
||||
13
scripts/killzone.gd
Normal file
13
scripts/killzone.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
extends Area2D
|
||||
|
||||
@onready var timer: Timer = $Timer
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
Engine.time_scale = 0.5
|
||||
timer.start()
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
Engine.time_scale = 1.0
|
||||
GameManager.reduce_hearts()
|
||||
get_tree().reload_current_scene()
|
||||
1
scripts/killzone.gd.uid
Normal file
1
scripts/killzone.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dt7a05678o5nm
|
||||
10
scripts/main_menu.gd
Normal file
10
scripts/main_menu.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
HUD.hide()
|
||||
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
HUD.show()
|
||||
get_tree().change_scene_to_file("res://scenes/game.tscn")
|
||||
1
scripts/main_menu.gd.uid
Normal file
1
scripts/main_menu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c1q1fvipjgngb
|
||||
47
scripts/player.gd
Normal file
47
scripts/player.gd
Normal file
@@ -0,0 +1,47 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
const SPEED = 130.0
|
||||
const JUMP_VELOCITY = -300.0
|
||||
|
||||
@onready var animator = $AnimatedSprite2D
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_axis("ui_left", "ui_right")
|
||||
|
||||
# animations
|
||||
if direction == 0:
|
||||
if animator.animation != "idle":
|
||||
animator.play("idle")
|
||||
else:
|
||||
if animator.animation != "run":
|
||||
animator.play("run")
|
||||
if direction > 0:
|
||||
animator.flip_h = false
|
||||
elif direction < 0:
|
||||
animator.flip_h = true
|
||||
|
||||
#if direction:
|
||||
#velocity.x = direction * SPEED
|
||||
#else:
|
||||
#velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
const ACCEL = 800.0
|
||||
const FRICTION = 1000.0
|
||||
|
||||
if direction != 0:
|
||||
velocity.x = move_toward(velocity.x, direction * SPEED, ACCEL * delta)
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, FRICTION * delta)
|
||||
|
||||
move_and_slide()
|
||||
1
scripts/player.gd.uid
Normal file
1
scripts/player.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bhqlgaeisqull
|
||||
1
scripts/start_button.gd
Normal file
1
scripts/start_button.gd
Normal file
@@ -0,0 +1 @@
|
||||
extends Control
|
||||
1
scripts/start_button.gd.uid
Normal file
1
scripts/start_button.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cfddmwyklvxjk
|
||||
Reference in New Issue
Block a user