Main.gd 1.1 KB

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