gamers be gaming
This commit is contained in:
parent
986a92cd16
commit
65128fcf1f
24 changed files with 827 additions and 2 deletions
100
logic.gd
Normal file
100
logic.gd
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
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
|
||||
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()
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
if gaming:
|
||||
current_time -= delta
|
||||
progress_bar.value = (5-current_time)/allowed_time
|
||||
else:
|
||||
test_break -= delta
|
||||
if test_break <= 0:
|
||||
start_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)
|
||||
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():
|
||||
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
|
||||
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue