score and lives partially implemented

This commit is contained in:
Tabby 2025-06-09 14:43:22 +10:00
parent 39ae7beeee
commit bb8d2a7b97
11 changed files with 250 additions and 3 deletions

View file

@ -8,6 +8,9 @@ extends Node2D
@export var icons : Array[Texture]
@export var progress_bar : ProgressBar
@export var scroll_container : ScrollContainer
@export var score_label : Label
@export var life_container : HBoxContainer
@export var life_texture : Texture
var current_time : float = 5
var score : int = 0
var lives : int = 3
@ -23,14 +26,29 @@ var target_scroll : float
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#start_round()
draw_lives()
pass # Replace with function body.
func draw_lives():
for child in life_container.get_children():
child.queue_free()
for i in range(lives):
var new_tex = TextureRect.new()
new_tex.texture = life_texture
life_container.add_child(new_tex)
func lose_life():
lives -= 1
draw_lives()
if lives <= 0:
#end game
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
target_scroll = (codepos*50) - 550
scroll_container.scroll_horizontal = lerpf(scroll_container.scroll_horizontal,target_scroll,0.05)
score_label.text = str(score)
if gaming:
current_time -= delta
@ -39,6 +57,10 @@ func _process(delta: float) -> void:
test_break -= delta
if test_break <= 0:
start_round()
if gaming and current_time <= 0:
lose_round()
if Input.is_action_just_pressed("up"):
process_input(0)
elif Input.is_action_just_pressed("right"):
@ -61,7 +83,9 @@ func process_input(direction : int):
if(code[codepos] == direction):
#correct input
icon_container.get_child(codepos).modulate = Color(0,1,0)
score += codepos+1
codepos += 1
if(codepos == code_len):
win_round()
else:
@ -72,15 +96,24 @@ func process_input(direction : int):
icon_container.get_child(i).modulate = Color(1,1,1)
func win_round():
#todo: bous for remaining time?
gaming = false
codepos = 0
test_break = 1.5 # todo: replace with gamer samurai animation stuff
if ghost_tokens > 0:
ghost_tokens -= 1
code_len += 1
else:
ghost_tokens = 2
code_len -= 1
score += 100
func lose_round():
gaming = false
codepos = 0
test_break = 1.5
lose_life()
func generate_code():
code.clear()