Add HUD scene with elevator hack timing minigame
- elevator panel w/ a screen and close button - screen.gd timing minigame: sweep line bounces across a shrinking target zone - hud wiring to move down floors on successful hacks, countdown/win states, and speed up AI on misses
This commit is contained in:
parent
d0c9fe4fc0
commit
164d0f76be
6 changed files with 245 additions and 0 deletions
99
screen.gd
Normal file
99
screen.gd
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
extends Panel
|
||||
|
||||
var sweep_speed := 150.0
|
||||
var sweep_direction := 1
|
||||
var sweep_x := 0.0
|
||||
var is_hacked := true
|
||||
|
||||
var style_box: StyleBoxFlat
|
||||
var base_color: Color
|
||||
|
||||
var target_shrink := 4.0
|
||||
var target_min_width := 8.0
|
||||
|
||||
signal hack_defeated
|
||||
signal hack_failed
|
||||
|
||||
func _ready():
|
||||
style_box = get_theme_stylebox("panel").duplicate()
|
||||
add_theme_stylebox_override("panel", style_box)
|
||||
base_color = style_box.bg_color
|
||||
|
||||
var tz = $TargetZone
|
||||
tz.position = Vector2((size.x - tz.size.x) / 2, 20)
|
||||
tz.size = Vector2(40, size.y - 40)
|
||||
|
||||
var sl = $SweepLine
|
||||
sl.position = Vector2(0, 20)
|
||||
sl.size = Vector2(4, size.y - 40)
|
||||
sweep_x = 0.0
|
||||
|
||||
var face = $AIFace
|
||||
face.position = Vector2(0, 0)
|
||||
face.size = Vector2(size.x, 30)
|
||||
face.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
|
||||
func _process(delta):
|
||||
if not is_hacked:
|
||||
return
|
||||
|
||||
sweep_x += sweep_speed * sweep_direction * delta
|
||||
|
||||
if sweep_x >= size.x:
|
||||
sweep_direction = -1
|
||||
elif sweep_x <= 0:
|
||||
sweep_direction = 1
|
||||
|
||||
$SweepLine.position.x = sweep_x
|
||||
|
||||
func flash(color: Color):
|
||||
style_box.bg_color = color
|
||||
var tween = create_tween()
|
||||
tween.tween_property(style_box, "bg_color", base_color, 0.3)
|
||||
|
||||
func reset_hack():
|
||||
is_hacked = true
|
||||
sweep_x = 0.0
|
||||
sweep_direction = 1
|
||||
$SweepLine.visible = true
|
||||
$SweepLine.position.x = 0
|
||||
$AIFace.text = ">:)"
|
||||
|
||||
var tz = $TargetZone
|
||||
tz.size.x = max(tz.size.x - target_shrink, target_min_width)
|
||||
tz.position.x = (size.x - tz.size.x) / 2
|
||||
|
||||
# messtastic
|
||||
func show_countdown():
|
||||
var tween = create_tween()
|
||||
$AIFace.text = "3"
|
||||
tween.tween_callback(func(): $AIFace.text = "2").set_delay(0.6)
|
||||
tween.tween_callback(func(): $AIFace.text = "1").set_delay(0.6)
|
||||
tween.tween_callback(func(): $AIFace.text = "CLOSED").set_delay(0.6)
|
||||
|
||||
func show_win():
|
||||
is_hacked = false
|
||||
$SweepLine.visible = false
|
||||
$TargetZone.visible = false
|
||||
$AIFace.text = "ESCAPED"
|
||||
flash(Color.GREEN)
|
||||
|
||||
# target zones
|
||||
func attempt_hack() -> bool:
|
||||
var tz = $TargetZone
|
||||
var tz_left = tz.position.x
|
||||
var tz_right = tz.position.x + tz.size.x
|
||||
|
||||
if sweep_x >= tz_left and sweep_x <= tz_right:
|
||||
is_hacked = false
|
||||
$AIFace.text = ">:("
|
||||
$SweepLine.visible = false
|
||||
flash(Color.GREEN)
|
||||
hack_defeated.emit()
|
||||
return true
|
||||
else:
|
||||
sweep_speed += 20.0
|
||||
$AIFace.text = ":D"
|
||||
flash(Color.RED)
|
||||
hack_failed.emit()
|
||||
return false
|
||||
Loading…
Add table
Add a link
Reference in a new issue