SeptemberGameAB/scripts/game_controller.gd

33 lines
995 B
GDScript3
Raw Normal View History

extends Node2D
var coins_collected : int = 0
var total_coins : int = 0
func _on_trigger_fired(intent: Variant, body: PhysicsBody2D) -> void:
print("Game controller knows %s trigger fired " % intent)
match intent:
"destroy":
print("Destroy this thing!")
if body is RigidBody2D:
body.queue_free()
"powerup":
print("Power this thing up!")
func on_coin_collected(_body, coin) -> void:
print_debug("GC knows coin collected")
coins_collected += 1
print_debug("Coins collected: %s" % str(coins_collected))
print_debug("There are %s coins remaining" % str(total_coins - coins_collected))
coin.queue_free()
if coins_collected >= total_coins:
print_debug("You win!")
await get_tree().create_timer(1.0).timeout
get_tree().call_deferred("reload_current_scene")
func on_player_slimed(body, slime) -> void:
print_debug("GC knows player slimed")
func set_total_coins(value) -> void:
total_coins = value
print_debug("There are %s coins in the level" % str(total_coins))