Godot Version
4.6.0
Question
So I made a simple rhythm game with arrows and you tap the keys to get points. i want to know how would i make a win condition. Basically it would be if your score is 10,000 then you win and it would take you to the win scene. How would i make that.
Note: for the transition to scene you can just add the code and the part where the scene is supposed to go you can leave it blank. also The game include multiple gd so i will include at the code part a text that says which gd is which.
#level_3_signals
extends Node2D
signal IncrementScore(incr: int)
signal IncrementCombo()
signal ResetCombo()
signal CreateFallingKey(button_name: String)
signal KeyListenerPress(button_name: String, array_num: int)
#level_3_ui.gd
extends Control
var score: int = 0
var combo_count: int = 0
# Called when the node enters the scene tree for the first time.
func _ready():
Level3Signals.IncrementScore.connect(IncrementScore)
Level3Signals.IncrementCombo.connect(IncrementCombo)
Level3Signals.ResetCombo.connect(ResetCombo)
ResetCombo()
func IncrementScore(incr: int):
score += incr
%ScoreLabel.text = " " + str(score) + " pts"
func IncrementCombo():
combo_count += 1
%ComboLabel.text = " " + str(combo_count) + "x combo"
func ResetCombo():
combo_count = 0
%ComboLabel.text = ""
#key_listener
extends Sprite2D
@onready var falling_key = preload("res://Scenes/Level Scenes/Level 3 Scenes/falling_key.tscn")
@onready var score_text = preload("res://Scenes/Level Scenes/Level 3 Scenes/score_press_text.tscn")
@export var key_name: String = ""
var falling_key_queue = []
# If distance_from_pass is less than threshold, give that score
var perfect_press_threshold: float = 30
var great_press_threshold: float = 50
var good_press_threshold: float = 60
var ok_press_threshold: float = 80
# otherwise, miss
var perfect_press_score: float = 250
var great_press_score: float = 100
var good_press_score: float = 50
var ok_press_score: float = 20
func _ready():
Level3Signals.CreateFallingKey.connect(CreateFallingKey)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_just_pressed(key_name):
Level3Signals.KeyListenerPress.emit(key_name, frame)
# Make sure there is a falling key to check for this given key
if falling_key_queue.size() > 0:
# If that falling key has passed, remove it from the queue
if falling_key_queue.front().has_passed:
falling_key_queue.pop_front()
# PRINT MISS
var st_inst = score_text.instantiate()
get_tree().get_root().call_deferred("add_child", st_inst)
st_inst.SetTextInfo("MISS")
st_inst.global_position = global_position + Vector2(0, -20)
Level3Signals.ResetCombo.emit()
# If key is pressed, pop from the queue and calculate distance from critical point
if Input.is_action_just_pressed(key_name):
var key_to_pop = falling_key_queue.pop_front()
var distance_from_pass = abs(key_to_pop.pass_threshold - key_to_pop.global_position.y)
var press_score_text: String = ""
if distance_from_pass < perfect_press_threshold:
Level3Signals.IncrementScore.emit(perfect_press_score)
press_score_text = "PERFECT"
Level3Signals.IncrementCombo.emit()
elif distance_from_pass < great_press_threshold:
Level3Signals.IncrementScore.emit(great_press_score)
press_score_text = "GREAT"
Level3Signals.IncrementCombo.emit()
elif distance_from_pass < good_press_threshold:
Level3Signals.IncrementScore.emit(good_press_score)
press_score_text = "GOOD"
Level3Signals.IncrementCombo.emit()
elif distance_from_pass < ok_press_threshold:
Level3Signals.IncrementScore.emit(ok_press_score)
press_score_text = "OK"
Level3Signals.IncrementCombo.emit()
else:
press_score_text = "MISS"
Level3Signals.ResetCombo.emit()
key_to_pop.queue_free()
var st_inst = score_text.instantiate()
get_tree().get_root().call_deferred("add_child", st_inst)
st_inst.SetTextInfo(press_score_text)
st_inst.global_position = global_position + Vector2(0, -20)
func CreateFallingKey(button_name: String):
if button_name == key_name:
var fk_inst = falling_key.instantiate()
get_tree().get_root().call_deferred("add_child", fk_inst)
fk_inst.Setup(position.x, frame + 4)
falling_key_queue.push_back(fk_inst)
func _on_random_spawn_timer_timeout():
#CreateFallingKey()
$RandomSpawnTimer.wait_time = randf_range(0.4, 3)
$RandomSpawnTimer.start()