warmup/main.gd

56 lines
1.1 KiB
GDScript

extends Node
@export var mob_scene: PackedScene
var score
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
new_game()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_player_hit() -> void:
pass # Replace with function body.
func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
func _on_mob_timer_timeout() -> void:
var mob = mob_scene.instantiate()
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
mob.position = mob_spawn_location.position
var direction = mob_spawn_location.rotation + PI/2
direction += randf_range(-PI/4, PI/4)
mob.rotation = direction
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
add_child(mob)
func _on_score_timer_timeout() -> void:
score += 1
func _on_start_timer_timeout() -> void:
$MobTimer.start()
$ScoreTimer.start()