89 lines
1.8 KiB
GDScript
89 lines
1.8 KiB
GDScript
extends Button
|
|
|
|
|
|
const INFINITY_SIGIL := "▬↨"
|
|
|
|
|
|
var delay := 1.0
|
|
var cooldown := 0.0
|
|
|
|
|
|
onready var back_arrow: TextureRect = $"../BackArrow"
|
|
onready var next_arrow: TextureRect = $"../NextArrow"
|
|
|
|
|
|
func _ready() -> void:
|
|
_update_display()
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if not has_focus():
|
|
return
|
|
if Input.is_action_pressed("ui_left"):
|
|
if cooldown <= 0.0:
|
|
cooldown = delay
|
|
delay *= 0.5
|
|
if Game.use_lives:
|
|
Game.marathon_lives -= 1
|
|
if Game.marathon_lives < 0:
|
|
Game.use_lives = false
|
|
cooldown = INF
|
|
else:
|
|
Game.use_lives = true
|
|
Game.marathon_lives = 999
|
|
cooldown -= delta
|
|
_update_display()
|
|
elif Input.is_action_pressed("ui_right"):
|
|
if cooldown <= 0.0:
|
|
cooldown = delay
|
|
delay *= 0.5
|
|
if Game.use_lives:
|
|
Game.marathon_lives += 1
|
|
if Game.marathon_lives > 999:
|
|
Game.use_lives = false
|
|
cooldown = INF
|
|
else:
|
|
Game.use_lives = true
|
|
Game.marathon_lives = 0
|
|
cooldown -= delta
|
|
_update_display()
|
|
else:
|
|
cooldown = 0.0
|
|
delay = 1.0
|
|
|
|
|
|
func _update_display() -> void:
|
|
if Game.use_lives:
|
|
text = "%03d" % Game.marathon_lives
|
|
else:
|
|
text = INFINITY_SIGIL
|
|
|
|
|
|
#func _gui_input(event: InputEvent) -> void:
|
|
# if event.is_action_pressed("ui_left"):
|
|
# if Game.use_lives:
|
|
# Game.marathon_lives -= 1
|
|
# if Game.marathon_lives < 0:
|
|
# Game.use_lives = false
|
|
# else:
|
|
# Game.use_lives = true
|
|
# Game.marathon_lives = 999
|
|
# if event.is_action_pressed("ui_right"):
|
|
# if Game.use_lives:
|
|
# Game.marathon_lives += 1
|
|
# if Game.marathon_lives > 999:
|
|
# Game.use_lives = false
|
|
# else:
|
|
# Game.use_lives = true
|
|
# Game.marathon_lives = 0
|
|
# _update_display()
|
|
|
|
|
|
func _on_focus_entered() -> void:
|
|
back_arrow.visible = true
|
|
next_arrow.visible = true
|
|
|
|
|
|
func _on_focus_exited() -> void:
|
|
back_arrow.visible = false
|
|
next_arrow.visible = false
|