GodotCourse/week1/GodotSpeedRun/scripts/gamecontroller.gd

32 lines
714 B
GDScript3
Raw Normal View History

2024-07-15 17:09:25 +00:00
extends Node2D
2025-02-24 16:07:59 +00:00
var totalCrates = 2
var cratesCollected = 0
var timeLimit = 10
var timer:= Timer.new()
2024-07-15 17:09:25 +00:00
# Called when the node enters the scene tree for the first time.
func _ready():
2025-02-24 16:07:59 +00:00
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
timer.connect("timeout", secondCounter)
timer.start()
2024-07-15 17:09:25 +00:00
2025-02-24 16:07:59 +00:00
func secondCounter():
timeLimit -= 1
if timeLimit <=0:
print("You lose baby!")
get_tree().reload_current_scene()
2024-07-15 17:09:25 +00:00
2025-02-24 16:07:59 +00:00
func _on_area_2d_areatrigger(effect, body):
2024-07-15 17:09:25 +00:00
print("Game Controller sees the trigger")
2025-02-24 16:07:59 +00:00
if body is RigidBody2D:
print("a crate entered trigger")
cratesCollected +=1
body.queue_free()
if cratesCollected>=totalCrates:
print("You win baby!")
get_tree().reload_current_scene()