Main.gd 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. $DeathSound.play()
  17. func _ready():
  18. randomize() # Plant seed for random number generation
  19. func _on_StartTimer_timeout():
  20. $MobTimer.start()
  21. $ScoreTimer.start()
  22. func _on_ScoreTimer_timeout():
  23. score += 1
  24. $HUD.update_score(score)
  25. func _on_MobTimer_timeout():
  26. $MobPath/MobSpawnLocation.set_offset(randi())
  27. var newMob = Mob.instance()
  28. var newRotation = $MobPath/MobSpawnLocation.rotation + rand_range(PI / 4, 3 * PI / 4)
  29. newMob.rotation = newRotation
  30. newMob.position = $MobPath/MobSpawnLocation.position
  31. newMob.linear_velocity = Vector2(rand_range(newMob.min_speed, newMob.max_speed), 0).rotated(newRotation)
  32. $HUD.connect("start_game", newMob, "_on_start_game")
  33. add_child(newMob)