Main.gd 1006 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. # warning-ignore:return_value_discarded
  8. get_tree().reload_current_scene()
  9. func _on_mob_timer_timeout():
  10. # Create a new instance of the Mob scene.
  11. var mob = mob_scene.instantiate()
  12. # Choose a random location on the SpawnPath.
  13. var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
  14. mob_spawn_location.progress_ratio = randf()
  15. # Communicate the spawn location and the player's location to the mob.
  16. var player_position = $Player.position
  17. mob.initialize(mob_spawn_location.position, player_position)
  18. # Spawn the mob by adding it to the Main scene.
  19. add_child(mob)
  20. # We connect the mob to the score label to update the score upon squashing a mob.
  21. mob.squashed.connect($UserInterface/ScoreLabel._on_Mob_squashed)
  22. func _on_player_hit():
  23. $MobTimer.stop()
  24. $UserInterface/Retry.show()