2025-05-16 22:13:34 +10:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
signal game_win
|
|
|
|
|
signal game_lose
|
|
|
|
|
|
2025-05-16 22:57:02 +10:00
|
|
|
enum GameStage{
|
|
|
|
|
Warning, # big red highlights (flashing?) show the player where to avoid
|
|
|
|
|
Lasers, # the lasers actively firing
|
|
|
|
|
None # the starting and ending (offline) state where nothing is happening
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@export var warning_duration = 5
|
|
|
|
|
@export var laser_duration = 2
|
2025-05-16 22:13:34 +10:00
|
|
|
@export_group("Node References")
|
|
|
|
|
@export var score_label : Label
|
|
|
|
|
@export var player : CharacterBody2D
|
|
|
|
|
@export var skip_location : Marker2D
|
2025-05-16 22:57:02 +10:00
|
|
|
@export var timer : Timer
|
|
|
|
|
@export var warning_areas : Array[Node2D]
|
|
|
|
|
@export var laser_areas : Array[Area2D]
|
2025-05-17 14:21:38 +10:00
|
|
|
@export var lifebar : TextureProgressBar
|
2025-05-16 22:57:02 +10:00
|
|
|
|
|
|
|
|
var game_active : bool = false
|
|
|
|
|
var stage : GameStage = GameStage.None
|
|
|
|
|
var safe_lane : int # 0,1 or 2 - the others will be hit by lasers
|
2025-05-16 22:13:34 +10:00
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
GameManager.skip_intro.connect(rec_skip_intro)
|
|
|
|
|
GameManager.update_data.connect(update_ui)
|
2025-05-16 22:57:02 +10:00
|
|
|
GameManager.start_platformer.connect(start_game)
|
|
|
|
|
GameManager.end_platformer.connect(end_game)
|
2025-05-16 22:13:34 +10:00
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta: float) -> void:
|
2025-05-16 23:16:29 +10:00
|
|
|
for i in range(3):
|
|
|
|
|
warning_areas[i].visible = stage == GameStage.Warning and safe_lane!=i
|
|
|
|
|
laser_areas[i].visible = stage == GameStage.Lasers and safe_lane!=i
|
|
|
|
|
if(stage == GameStage.Lasers and safe_lane!=i):
|
|
|
|
|
if laser_areas[i].get_overlapping_areas().size()>0:
|
|
|
|
|
end_game()
|
|
|
|
|
game_lose.emit()
|
2025-05-16 22:57:02 +10:00
|
|
|
pass
|
2025-05-16 23:16:29 +10:00
|
|
|
#warning_areas[0].visible = stage == GameStage.Warning
|
|
|
|
|
#laser_areas[0].visible = stage == GameStage.Lasers
|
2025-05-16 22:57:02 +10:00
|
|
|
#todo make sure lasers dont trigger the door/remote/event hitboxes
|
2025-05-16 22:13:34 +10:00
|
|
|
|
|
|
|
|
func update_ui(score : int, lives :int):
|
|
|
|
|
score_label.text = str(score)
|
2025-05-17 14:21:38 +10:00
|
|
|
lifebar.value = lives
|
2025-05-16 22:13:34 +10:00
|
|
|
|
|
|
|
|
func rec_skip_intro():
|
|
|
|
|
#teleport player to doorway
|
|
|
|
|
player.global_position = skip_location.global_position
|
|
|
|
|
#maybe bring up an invis wall behind them but it doesnt matter
|
|
|
|
|
pass
|
2025-05-16 22:57:02 +10:00
|
|
|
|
|
|
|
|
func start_game():
|
|
|
|
|
game_active = true
|
|
|
|
|
timer.start(warning_duration)
|
|
|
|
|
safe_lane = randi_range(0,2)
|
|
|
|
|
stage = GameStage.Warning
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
func end_game():
|
2025-05-16 23:16:29 +10:00
|
|
|
# set stage back to none?
|
2025-05-17 14:21:38 +10:00
|
|
|
stage = GameStage.None
|
2025-05-16 22:57:02 +10:00
|
|
|
game_active = false
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_timer_timeout() -> void:
|
|
|
|
|
if(stage == GameStage.Warning):
|
|
|
|
|
stage = GameStage.Lasers
|
|
|
|
|
timer.start(laser_duration)
|
2025-05-16 23:16:29 +10:00
|
|
|
elif(stage == GameStage.Lasers):
|
2025-05-16 22:57:02 +10:00
|
|
|
stage = GameStage.None
|
2025-05-16 23:16:29 +10:00
|
|
|
if(game_active):
|
|
|
|
|
game_win.emit()
|
|
|
|
|
end_game()
|
|
|
|
|
|
|
|
|
|
#if i havent died yet, then win
|