extends Node2D @export var code_len : int = 2 @export var ghost_tokens : int = 2 @export var allowed_time : float = 5 @export var starting_lives : int = 3 @export var icon_container: HBoxContainer @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 var code : Array[int] var code_rects : Array[TextureRect] var gaming : bool = false var codepos : int = 0 #current position in the code to check against var test_break : float = 1.5 var target_scroll : float # start scrolling at codepos == 11 # 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 progress_bar.value = (5-current_time)/allowed_time else: 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"): process_input(1) elif Input.is_action_just_pressed("down"): process_input(2) elif Input.is_action_just_pressed("left"): process_input(3) func start_round(): current_time = allowed_time codepos = 0 generate_code() gaming = true #scroll_container.scroll_horizontal = 0 pass 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: #incorrect input codepos = 0 #scroll_container.scroll_horizontal = 0 for i in range(code_len): 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() for child in icon_container.get_children(): child.queue_free() for i in range(code_len): var ran_dir : int = randi_range(0,3) code.append(ran_dir) var new_texture_rect : TextureRect = TextureRect.new() new_texture_rect.texture = icons[ran_dir] icon_container.add_child(new_texture_rect) for i in range(ghost_tokens): var new_texture_rect : TextureRect = TextureRect.new() new_texture_rect.texture = icons[4] new_texture_rect.modulate = Color(1,1,1,0.25) icon_container.add_child(new_texture_rect) print(code)