godot-demo-projects/2d/dodge_the_creeps/Main.gd

48 lines
992 B
GDScript3
Raw Normal View History

2018-03-12 16:49:09 +01:00
extends Node
export(PackedScene) var Mob
2018-03-12 16:49:09 +01:00
var score
func _ready():
randomize()
2019-03-17 01:26:56 +01:00
func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
$Music.stop()
$DeathSound.play()
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()
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)
var direction = $MobPath/MobSpawnLocation.rotation + TAU / 4
2018-03-12 16:49:09 +01:00
mob.position = $MobPath/MobSpawnLocation.position
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)
# warning-ignore:return_value_discarded
$HUD.connect("start_game", mob, "_on_start_game")
2018-03-12 16:49:09 +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
2019-03-17 01:26:56 +01:00
func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()