Main.gd 621 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. extends Node2D
  2. # Manage game cycles
  3. signal game_started
  4. signal game_over
  5. var score = 0
  6. var music_position = 0.0
  7. func new_game():
  8. score = 0
  9. $Player.spawn($StartPositon.position)
  10. $StartTimer.start()
  11. $HUD.update_score(score)
  12. $HUD.show_message("Get ready")
  13. $Music.play(music_position)
  14. func game_over():
  15. $ScoreTimer.stop()
  16. $HUD.show_game_over()
  17. music_position = $Music.get_playback_position()
  18. $Music.stop()
  19. $DeathSound.play()
  20. emit_signal("game_over")
  21. func _on_StartTimer_timeout():
  22. $ScoreTimer.start()
  23. emit_signal("game_started")
  24. func _on_ScoreTimer_timeout():
  25. score += 1
  26. $HUD.update_score(score)