Main.gd 964 B

123456789101112131415161718192021222324252627282930313233343536
  1. extends Node
  2. @export var mob_scene: PackedScene
  3. func _ready():
  4. $UserInterface/Retry.hide()
  5. func _unhandled_input(event):
  6. if event.is_action_pressed("ui_accept") and $UserInterface/Retry.visible:
  7. get_tree().reload_current_scene()
  8. func _on_mob_timer_timeout():
  9. # Create a new instance of the Mob scene.
  10. var mob = mob_scene.instantiate()
  11. # Choose a random location on the SpawnPath.
  12. var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
  13. mob_spawn_location.progress_ratio = randf()
  14. # Communicate the spawn location and the player's location to the mob.
  15. var player_position = $Player.position
  16. mob.initialize(mob_spawn_location.position, player_position)
  17. # Spawn the mob by adding it to the Main scene.
  18. add_child(mob)
  19. # We connect the mob to the score label to update the score upon squashing a mob.
  20. mob.squashed.connect($UserInterface/ScoreLabel._on_Mob_squashed)
  21. func _on_player_hit():
  22. $MobTimer.stop()
  23. $UserInterface/Retry.show()