wild jam prototype
This commit is contained in:
41
scripts/rocket.gd
Normal file
41
scripts/rocket.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Node2D
|
||||
|
||||
signal game_over
|
||||
|
||||
@onready var leave_timer: Timer = $LeaveTimer
|
||||
@onready var collection_zone: Area2D = $CollectionZone
|
||||
@onready var countdown_label: Label = $CountdownLabel
|
||||
|
||||
var countdown = 5
|
||||
var count = -1
|
||||
|
||||
func _on_collection_zone_body_entered(body: Node2D) -> void:
|
||||
leave_timer.start()
|
||||
count = countdown
|
||||
countdown_label.text = str(count)
|
||||
countdown_label.show()
|
||||
if body is Enemy:
|
||||
body.reach_rocket()
|
||||
|
||||
|
||||
func _on_collection_zone_body_exited(body: Node2D) -> void:
|
||||
if collection_zone.get_overlapping_bodies().size() == 0:
|
||||
leave_timer.stop()
|
||||
countdown_label.hide()
|
||||
|
||||
|
||||
func _on_leave_timer_timeout() -> void:
|
||||
count -= 1
|
||||
countdown_label.text = str(count)
|
||||
|
||||
if count == 0:
|
||||
for clr in Buff.colors:
|
||||
HasWon.escaped[clr] = 0
|
||||
var escaped: Array[Node2D] = collection_zone.get_overlapping_bodies()
|
||||
HasWon.won = false
|
||||
for entity: Entity in escaped:
|
||||
HasWon.escaped[Buff.colors.keys()[entity.alliance]] += 1
|
||||
if entity is Player:
|
||||
HasWon.won = true
|
||||
game_over.emit()
|
||||
|
||||
Reference in New Issue
Block a user