channel-switcher/games/ddr/ddr.gd

55 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

2025-05-13 15:56:51 +10:00
extends Node
2025-05-16 22:13:34 +10:00
signal game_win
signal game_lose
2025-05-13 15:56:51 +10:00
@export var win_amount : int = 5
@export var note_frequency : float = 3
2025-05-13 15:56:51 +10:00
@export var paths : Array[Node2D]
var next_note : float = 99
@export_group("Node References")
2025-05-17 14:21:38 +10:00
@export var score_label : Label
var score: int = 0
2025-05-13 15:56:51 +10:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
next_note = note_frequency
for path in paths:
path.note_hit.connect(hit_note)
path.note_miss.connect(miss_note)
2025-05-13 15:56:51 +10:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
next_note -= delta
if(next_note <= 0):
next_note = note_frequency
spawn_note()
if(Input.is_action_just_pressed("ddr_left")):
detect_hit(0)
if(Input.is_action_just_pressed("ddr_down")):
detect_hit(1)
if(Input.is_action_just_pressed("ddr_up")):
detect_hit(2)
if(Input.is_action_just_pressed("ddr_right")):
detect_hit(3)
2025-05-17 14:21:38 +10:00
score_label.text = str(score) + "/" + str(win_amount)
2025-05-13 15:56:51 +10:00
func spawn_note():
var ran_path = randi_range(0, paths.size()-1)
paths[ran_path].spawn_note()
func detect_hit(lane : int):
paths[lane].check_hit()
func hit_note():
score += 1
if score >= win_amount:
game_win.emit()
func miss_note():
game_lose.emit()