2018-03-12 16:49:09 +01:00
|
|
|
extends Node
|
|
|
|
|
2020-06-28 09:29:20 +02:00
|
|
|
export(PackedScene) var Mob
|
2018-03-12 16:49:09 +01:00
|
|
|
var score
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
randomize()
|
|
|
|
|
2020-01-31 08:47:17 +01:00
|
|
|
|
2019-03-17 01:26:56 +01:00
|
|
|
func game_over():
|
|
|
|
$ScoreTimer.stop()
|
|
|
|
$MobTimer.stop()
|
|
|
|
$HUD.show_game_over()
|
|
|
|
$Music.stop()
|
|
|
|
$DeathSound.play()
|
|
|
|
|
2020-01-31 08:47:17 +01:00
|
|
|
|
2018-03-12 16:49:09 +01:00
|
|
|
func new_game():
|
|
|
|
score = 0
|
|
|
|
$Player.start($StartPosition.position)
|
|
|
|
$StartTimer.start()
|
2019-03-17 01:26:56 +01:00
|
|
|
$HUD.update_score(score)
|
2018-03-12 16:49:09 +01:00
|
|
|
$HUD.show_message("Get Ready")
|
|
|
|
$Music.play()
|
|
|
|
|
2020-01-31 08:47:17 +01:00
|
|
|
|
2018-03-12 16:49:09 +01:00
|
|
|
func _on_MobTimer_timeout():
|
2019-03-17 01:26:56 +01:00
|
|
|
$MobPath/MobSpawnLocation.offset = randi()
|
2018-03-12 16:49:09 +01:00
|
|
|
var mob = Mob.instance()
|
|
|
|
add_child(mob)
|
2020-06-28 09:29:20 +02:00
|
|
|
var direction = $MobPath/MobSpawnLocation.rotation + TAU / 4
|
2018-03-12 16:49:09 +01:00
|
|
|
mob.position = $MobPath/MobSpawnLocation.position
|
2020-06-28 09:29:20 +02:00
|
|
|
direction += rand_range(-TAU / 8, TAU / 8)
|
2018-03-12 16:49:09 +01:00
|
|
|
mob.rotation = direction
|
2019-03-17 01:26:56 +01:00
|
|
|
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0).rotated(direction)
|
2020-04-03 18:35:35 +02:00
|
|
|
# warning-ignore:return_value_discarded
|
|
|
|
$HUD.connect("start_game", mob, "_on_start_game")
|
2018-03-12 16:49:09 +01:00
|
|
|
|
2020-01-31 08:47:17 +01:00
|
|
|
|
2018-03-12 16:49:09 +01:00
|
|
|
func _on_ScoreTimer_timeout():
|
|
|
|
score += 1
|
|
|
|
$HUD.update_score(score)
|
2019-03-17 01:26:56 +01:00
|
|
|
|
2020-01-31 08:47:17 +01:00
|
|
|
|
2019-03-17 01:26:56 +01:00
|
|
|
func _on_StartTimer_timeout():
|
|
|
|
$MobTimer.start()
|
2020-01-31 08:47:17 +01:00
|
|
|
$ScoreTimer.start()
|