extends Node2D

export (PackedScene) var Mob

var score = 0

func new_game():
	score = 0
	$Player.spawn($StartPositon.position)
	$StartTimer.start()
	$HUD.update_score(score)
	$HUD.show_message("Get ready")

func game_over():
	$ScoreTimer.stop()
	$MobTimer.stop()
	$HUD.show_game_over()

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)

	add_child(newMob)
