Main.gd 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extends Node2D
  2. export (PackedScene) var Mob
  3. var score = 0
  4. func new_game():
  5. score = 0
  6. $Player.spawn($StartPositon.position)
  7. $StartTimer.start()
  8. $HUD.update_score(score)
  9. $HUD.show_message("Get ready")
  10. $Music.play()
  11. func game_over():
  12. $ScoreTimer.stop()
  13. $MobTimer.stop()
  14. $HUD.show_game_over()
  15. $Music.stop()
  16. func _ready():
  17. randomize() # Plant seed for random number generation
  18. func _on_StartTimer_timeout():
  19. $MobTimer.start()
  20. $ScoreTimer.start()
  21. func _on_ScoreTimer_timeout():
  22. score += 1
  23. $HUD.update_score(score)
  24. func _on_MobTimer_timeout():
  25. $MobPath/MobSpawnLocation.set_offset(randi())
  26. var newMob = Mob.instance()
  27. var newRotation = $MobPath/MobSpawnLocation.rotation + rand_range(PI / 4, 3 * PI / 4)
  28. newMob.rotation = newRotation
  29. newMob.position = $MobPath/MobSpawnLocation.position
  30. newMob.linear_velocity = Vector2(rand_range(newMob.min_speed, newMob.max_speed), 0).rotated(newRotation)
  31. $HUD.connect("start_game", newMob, "_on_start_game")
  32. add_child(newMob)