1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- extends Node2D
- export (PackedScene) var Mob
- var score = 0
- var music_position = 0.0
- func new_game():
- score = 0
- $Player.spawn($StartPositon.position)
- $StartTimer.start()
- $HUD.update_score(score)
- $HUD.show_message("Get ready")
- $Music.play(music_position)
- func game_over():
- $ScoreTimer.stop()
- $MobTimer.stop()
- $HUD.show_game_over()
- music_position = $Music.get_playback_position()
- $Music.stop()
- $DeathSound.play()
- func _ready():
- randomize() # Plant seed for random number generation
- func _on_StartTimer_timeout():
- $MobTimer.start()
- $ScoreTimer.start()
- func _on_ScoreTimer_timeout():
- score += 1
- $HUD.update_score(score)
- func _on_MobTimer_timeout():
- $MobPath/MobSpawnLocation.set_offset(randi())
- var newMob = Mob.instance()
- var newRotation = $MobPath/MobSpawnLocation.rotation + rand_range(PI / 4, 3 * PI / 4)
- newMob.rotation = newRotation
- newMob.position = $MobPath/MobSpawnLocation.position
- newMob.linear_velocity = Vector2(rand_range(newMob.min_speed, newMob.max_speed), 0).rotated(newRotation)
-
- $HUD.connect("start_game", newMob, "_on_start_game")
- add_child(newMob)
|