2018-03-12 16:49:09 +01:00
|
|
|
extends Node
|
|
|
|
|
2020-10-06 11:28:27 +02:00
|
|
|
export(PackedScene) var _mob_scene
|
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():
|
2020-10-06 11:28:27 +02:00
|
|
|
get_tree().call_group("mobs", "queue_free")
|
2018-03-12 16:49:09 +01:00
|
|
|
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():
|
2020-10-06 11:28:27 +02:00
|
|
|
# Choose a random location on Path2D.
|
|
|
|
var mob_spawn_location = get_node("MobPath/MobSpawnLocation");
|
|
|
|
mob_spawn_location.offset = randi()
|
|
|
|
|
|
|
|
# Create a Mob instance and add it to the scene.
|
|
|
|
var mob_instance = _mob_scene.instance()
|
|
|
|
add_child(mob_instance)
|
|
|
|
|
|
|
|
# Set the mob's direction perpendicular to the path direction.
|
|
|
|
var direction = mob_spawn_location.rotation + TAU / 4
|
|
|
|
|
|
|
|
# Set the mob's position to a random location.
|
|
|
|
mob_instance.position = mob_spawn_location.position
|
|
|
|
|
|
|
|
# Add some randomness to the direction.
|
2020-06-28 09:29:20 +02:00
|
|
|
direction += rand_range(-TAU / 8, TAU / 8)
|
2020-10-06 11:28:27 +02:00
|
|
|
mob_instance.rotation = direction
|
|
|
|
|
|
|
|
# Choose the velocity.
|
|
|
|
mob_instance.linear_velocity = Vector2(rand_range(mob_instance.min_speed, mob_instance.max_speed), 0).rotated(direction)
|
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()
|