peak
This commit is contained in:
parent
28766d0a84
commit
46212a7e06
207 changed files with 3998 additions and 31 deletions
70
logic.gd
70
logic.gd
|
|
@ -6,12 +6,16 @@ extends Node2D
|
|||
@export var starting_lives : int = 3
|
||||
@export var icon_container: HBoxContainer
|
||||
@export var icons : Array[Texture]
|
||||
@export var sounds : Dictionary[String, AudioStream]
|
||||
@export var progress_bar : TextureProgressBar
|
||||
@export var scroll_container : ScrollContainer
|
||||
@export var score_label : Label
|
||||
@export var life_container : HBoxContainer
|
||||
@export var life_texture : Texture
|
||||
@export var round_label : Label
|
||||
@export var sound_player : AudioStreamPlayer
|
||||
@export var finish_screen : Control
|
||||
@export var sam_sprite : AnimatedSprite2D
|
||||
var current_time : float = 5
|
||||
var score : int = 0
|
||||
var lives : int = 3
|
||||
|
|
@ -21,6 +25,7 @@ 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
|
||||
var finished : bool = false
|
||||
|
||||
# start scrolling at codepos == 11
|
||||
|
||||
|
|
@ -40,10 +45,13 @@ func draw_lives():
|
|||
|
||||
func lose_life():
|
||||
lives -= 1
|
||||
|
||||
draw_lives()
|
||||
if lives <= 0:
|
||||
#end game
|
||||
pass
|
||||
end_game()
|
||||
|
||||
func end_game():
|
||||
finished = true
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
|
|
@ -51,17 +59,20 @@ func _process(delta: float) -> void:
|
|||
scroll_container.scroll_horizontal = lerpf(scroll_container.scroll_horizontal,target_scroll,0.05)
|
||||
score_label.text = str(score)
|
||||
round_label.text = str(code_len) + " of " + str(code_len+ghost_tokens)
|
||||
finish_screen.visible = finished
|
||||
if not gaming:
|
||||
round_label.text = "Get Ready!"
|
||||
if finished:
|
||||
round_label.text = "Length " + str(code_len+ghost_tokens)
|
||||
|
||||
if gaming:
|
||||
current_time -= delta
|
||||
progress_bar.value = (5-current_time)/allowed_time
|
||||
progress_bar.value = (allowed_time-current_time)/allowed_time
|
||||
|
||||
else:
|
||||
test_break -= delta
|
||||
progress_bar.value -= delta/1.5
|
||||
if test_break <= 0:
|
||||
if test_break <= 0 and not finished:
|
||||
start_round()
|
||||
|
||||
progress_bar.modulate = Color(1,1,1,progress_bar.value)
|
||||
|
|
@ -83,31 +94,43 @@ func start_round():
|
|||
codepos = 0
|
||||
generate_code()
|
||||
gaming = true
|
||||
sound_player.stream = sounds["reveal"]
|
||||
sound_player.play()
|
||||
sam_sprite.play("default")
|
||||
|
||||
#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)
|
||||
if gaming:
|
||||
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:
|
||||
sound_player.stream = sounds["success"]
|
||||
sound_player.play()
|
||||
else:
|
||||
#incorrect input
|
||||
codepos = 0
|
||||
sound_player.stream = sounds["error"]
|
||||
sound_player.play()
|
||||
#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?
|
||||
sam_sprite.play("bow")
|
||||
sound_player.stream = sounds["roundSuccess"]
|
||||
sound_player.play()
|
||||
gaming = false
|
||||
codepos = 0
|
||||
test_break = 1.5 # todo: replace with gamer samurai animation stuff
|
||||
test_break = 1.7 # todo: replace with gamer samurai animation stuff
|
||||
if ghost_tokens > 0:
|
||||
ghost_tokens -= 1
|
||||
code_len += 1
|
||||
|
|
@ -119,8 +142,11 @@ func win_round():
|
|||
|
||||
func lose_round():
|
||||
gaming = false
|
||||
sam_sprite.play("tan")
|
||||
codepos = 0
|
||||
test_break = 1.5
|
||||
test_break = 2.5
|
||||
sound_player.stream = sounds["tant"]
|
||||
sound_player.play()
|
||||
lose_life()
|
||||
|
||||
func generate_code():
|
||||
|
|
@ -139,3 +165,7 @@ func generate_code():
|
|||
new_texture_rect.modulate = Color(1,1,1,0.25)
|
||||
icon_container.add_child(new_texture_rect)
|
||||
print(code)
|
||||
|
||||
|
||||
func _on_menu_button_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://menu.tscn")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue