pulse node, shaft strip, constantify, etc.
This commit is contained in:
parent
d4c609e1af
commit
0b6d121986
24 changed files with 645 additions and 245 deletions
230
scenes/screen.gd
230
scenes/screen.gd
|
|
@ -1,14 +1,17 @@
|
|||
extends Panel
|
||||
|
||||
var pulse_speed := 120.0
|
||||
var pulse_speed_initial := 120.0
|
||||
var pulse_speed_per_floor := 8.0
|
||||
var pulse_speed_increase := 15.0
|
||||
var pulse_x := 0.0
|
||||
var pulse_active := false
|
||||
var pulse_gap := 1.0
|
||||
var pulse_gap_decrease := 0.05
|
||||
var pulse_gap_min := 0.3
|
||||
const PULSE_TOP_MARGIN := 0.0
|
||||
const PULSE_BOTTOM_MARGIN := 0.0
|
||||
const BLOCK_ZONE_RIGHT_MARGIN := 4.0
|
||||
const PERFECT_ZONE_RATIO := 0.3
|
||||
const PERFECT_ZONE_COLOR := Color(1.0, 0.95, 0.4, 0.85)
|
||||
const QUOTA_DOT_SIZE := 7.0
|
||||
const QUOTA_DOT_SPACING := 3.0
|
||||
const QUOTA_DOT_Y := 6.0
|
||||
const QUOTA_DOT_RIGHT_MARGIN := 8.0
|
||||
const QUOTA_EMPTY_COLOR := Color(0.07, 0.14, 0.09, 1.0)
|
||||
const QUOTA_EMPTY_BORDER := Color(0.18, 0.35, 0.2, 1.0)
|
||||
const QUOTA_FILLED_COLOR := Color(0.2, 1.0, 0.2, 1.0)
|
||||
|
||||
var block_zone_shrink := 3.0
|
||||
var block_zone_min := 12.0
|
||||
|
|
@ -18,47 +21,36 @@ var block_zone_speed := 0.0
|
|||
var block_zone_direction := -1
|
||||
var block_zone_min_x := 0.0
|
||||
var block_zone_max_x := 0.0
|
||||
const MOVING_RANGE_RATIO := 0.6
|
||||
const PULSE_TOP_MARGIN := 40.0
|
||||
const PULSE_BOTTOM_MARGIN := 16.0
|
||||
|
||||
const TRAIL_GHOSTS := 8
|
||||
const TRAIL_SPACING := 3.0
|
||||
const TRAIL_ALPHAS := [0.5, 0.42, 0.34, 0.27, 0.2, 0.14, 0.09, 0.05]
|
||||
const GLOW_PADDING := Vector2(6, 6)
|
||||
const GLOW_COLOR := Color(1, 0.3, 0.3, 0.35)
|
||||
const PERFECT_ZONE_RATIO := 0.3
|
||||
const PERFECT_ZONE_COLOR := Color(1.0, 0.95, 0.4, 0.85)
|
||||
const QUOTA_DOT_SIZE := 12.0
|
||||
const QUOTA_DOT_SPACING := 8.0
|
||||
const QUOTA_DOT_Y_FROM_BOTTOM := 14.0
|
||||
const QUOTA_EMPTY_COLOR := Color(0.6, 0.1, 0.1, 0.95)
|
||||
const QUOTA_FILLED_COLOR := Color(0.2, 1.0, 0.2, 1.0)
|
||||
|
||||
var base_color: Color
|
||||
|
||||
var active := false
|
||||
var pulses_blocked := 0
|
||||
var _ready_pulse_tween: Tween = null
|
||||
var _trail: Array[ColorRect] = []
|
||||
var _glow: ColorRect
|
||||
var _perfect_zone: ColorRect
|
||||
var _face_scale_tween: Tween
|
||||
var _face_shake_tween: Tween
|
||||
var _flash_tween: Tween
|
||||
var _floor_label: Label
|
||||
var _quota_dots: Array[ColorRect] = []
|
||||
var _quota_dots: Array[Panel] = []
|
||||
var _quota_threshold := 0
|
||||
var _quota_filled_style: StyleBoxFlat
|
||||
var _quota_empty_style: StyleBoxFlat
|
||||
|
||||
@onready var _pulse = $Pulse
|
||||
|
||||
signal pulse_started(duration: float)
|
||||
signal pulse_blocked
|
||||
signal pulse_blocked_perfect
|
||||
signal doors_closing
|
||||
|
||||
var pulse_active: bool:
|
||||
get:
|
||||
return _pulse.pulse_active if _pulse else false
|
||||
|
||||
func _ready():
|
||||
var bz = $TargetZone
|
||||
bz.size = Vector2(50, size.y - PULSE_TOP_MARGIN - PULSE_BOTTOM_MARGIN)
|
||||
bz.position = Vector2((size.x - bz.size.x) / 2, PULSE_TOP_MARGIN)
|
||||
bz.position = Vector2(size.x - bz.size.x - BLOCK_ZONE_RIGHT_MARGIN, PULSE_TOP_MARGIN)
|
||||
|
||||
_perfect_zone = ColorRect.new()
|
||||
_perfect_zone.color = PERFECT_ZONE_COLOR
|
||||
|
|
@ -78,21 +70,11 @@ func _ready():
|
|||
face.text = ">:)"
|
||||
face.pivot_offset = face.size / 2
|
||||
|
||||
_glow = ColorRect.new()
|
||||
_glow.color = GLOW_COLOR
|
||||
_glow.size = Vector2($SweepLine.size.x + GLOW_PADDING.x * 2, $SweepLine.size.y + GLOW_PADDING.y * 2)
|
||||
_glow.visible = false
|
||||
add_child(_glow)
|
||||
move_child(_glow, 0)
|
||||
|
||||
for i in TRAIL_GHOSTS:
|
||||
var ghost := ColorRect.new()
|
||||
ghost.color = Color($SweepLine.color.r, $SweepLine.color.g, $SweepLine.color.b, TRAIL_ALPHAS[i])
|
||||
ghost.size = $SweepLine.size
|
||||
ghost.visible = false
|
||||
add_child(ghost)
|
||||
move_child(ghost, 0)
|
||||
_trail.append(ghost)
|
||||
_pulse.configure(sl, bz, _perfect_zone, size.x)
|
||||
_pulse.pulse_started.connect(_on_pulse_started)
|
||||
_pulse.pulse_blocked.connect(_on_pulse_blocked)
|
||||
_pulse.pulse_blocked_perfect.connect(_on_pulse_blocked_perfect)
|
||||
_pulse.pulse_escaped.connect(_on_pulse_escaped)
|
||||
|
||||
var style = get_theme_stylebox("panel") as StyleBoxFlat
|
||||
if style:
|
||||
|
|
@ -110,36 +92,40 @@ func _ready():
|
|||
|
||||
func start(floor_num: int = EventBus.STARTING_FLOOR):
|
||||
active = true
|
||||
pulses_blocked = 0
|
||||
var floors_descended = EventBus.STARTING_FLOOR - floor_num
|
||||
pulse_speed = pulse_speed_initial + floors_descended * pulse_speed_per_floor
|
||||
pulse_gap = 1.0
|
||||
$AIFace.text = ">:)"
|
||||
$TargetZone.visible = true
|
||||
block_zone_moving = false
|
||||
$TargetZone.position.x = (size.x - $TargetZone.size.x) / 2
|
||||
_pulse.start_floor(floor_num)
|
||||
|
||||
func set_block_zone_movement(speed: float):
|
||||
var bz = $TargetZone
|
||||
block_zone_speed = speed
|
||||
block_zone_moving = speed > 0.0
|
||||
var bz = $TargetZone
|
||||
var range_half = size.x * MOVING_RANGE_RATIO / 2
|
||||
var center_x = size.x / 2
|
||||
block_zone_min_x = center_x - range_half
|
||||
block_zone_max_x = center_x + range_half - bz.size.x
|
||||
bz.position.x = (size.x - bz.size.x) / 2
|
||||
block_zone_direction = -1
|
||||
block_zone_min_x = (size.x - bz.size.x) / 2.0
|
||||
block_zone_max_x = size.x - bz.size.x - BLOCK_ZONE_RIGHT_MARGIN
|
||||
|
||||
func stop():
|
||||
active = false
|
||||
pulse_active = false
|
||||
_hide_pulse_visuals()
|
||||
_pulse.stop()
|
||||
_stop_ready_pulse()
|
||||
|
||||
func launch_pulse():
|
||||
if not active:
|
||||
return
|
||||
$AIFace.text = ">:)"
|
||||
_start_ready_pulse()
|
||||
_pulse.launch()
|
||||
|
||||
func get_pulse_gap() -> float:
|
||||
return _pulse.get_pulse_gap()
|
||||
|
||||
func attempt_block() -> bool:
|
||||
return _pulse.attempt_block()
|
||||
|
||||
func shrink_block_zone():
|
||||
var bz = $TargetZone
|
||||
var new_width = max(bz.size.x - block_zone_shrink, block_zone_min)
|
||||
var new_x = (size.x - new_width) / 2
|
||||
var new_x = bz.position.x + (bz.size.x - new_width) / 2.0
|
||||
var tween = create_tween()
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(bz, "size:x", new_width, 0.3)
|
||||
|
|
@ -159,25 +145,46 @@ func _update_floor_label(floor_num: int):
|
|||
_displayed_floor = floor_num
|
||||
UIUtils.flip_label_text(_floor_label, new_text)
|
||||
|
||||
func _build_quota_styles():
|
||||
var r := int(QUOTA_DOT_SIZE / 2.0)
|
||||
_quota_filled_style = StyleBoxFlat.new()
|
||||
_quota_filled_style.corner_radius_top_left = r
|
||||
_quota_filled_style.corner_radius_top_right = r
|
||||
_quota_filled_style.corner_radius_bottom_left = r
|
||||
_quota_filled_style.corner_radius_bottom_right = r
|
||||
_quota_filled_style.bg_color = QUOTA_FILLED_COLOR
|
||||
_quota_empty_style = StyleBoxFlat.new()
|
||||
_quota_empty_style.corner_radius_top_left = r
|
||||
_quota_empty_style.corner_radius_top_right = r
|
||||
_quota_empty_style.corner_radius_bottom_left = r
|
||||
_quota_empty_style.corner_radius_bottom_right = r
|
||||
_quota_empty_style.bg_color = QUOTA_EMPTY_COLOR
|
||||
_quota_empty_style.border_width_top = 1
|
||||
_quota_empty_style.border_width_bottom = 1
|
||||
_quota_empty_style.border_width_left = 1
|
||||
_quota_empty_style.border_width_right = 1
|
||||
_quota_empty_style.border_color = QUOTA_EMPTY_BORDER
|
||||
|
||||
func _update_quota_dots(count: int, threshold: int):
|
||||
if _quota_filled_style == null:
|
||||
_build_quota_styles()
|
||||
if threshold != _quota_threshold:
|
||||
_quota_threshold = threshold
|
||||
for dot in _quota_dots:
|
||||
dot.queue_free()
|
||||
_quota_dots.clear()
|
||||
var total_w = threshold * QUOTA_DOT_SIZE + max(0, threshold - 1) * QUOTA_DOT_SPACING
|
||||
var start_x = (size.x - total_w) / 2.0
|
||||
var y = size.y - QUOTA_DOT_Y_FROM_BOTTOM
|
||||
var start_x = size.x - total_w - QUOTA_DOT_RIGHT_MARGIN
|
||||
for i in threshold:
|
||||
var dot = ColorRect.new()
|
||||
var dot = Panel.new()
|
||||
dot.size = Vector2(QUOTA_DOT_SIZE, QUOTA_DOT_SIZE)
|
||||
dot.position = Vector2(start_x + i * (QUOTA_DOT_SIZE + QUOTA_DOT_SPACING), y)
|
||||
dot.color = QUOTA_EMPTY_COLOR
|
||||
dot.position = Vector2(start_x + i * (QUOTA_DOT_SIZE + QUOTA_DOT_SPACING), QUOTA_DOT_Y)
|
||||
dot.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(dot)
|
||||
_quota_dots.append(dot)
|
||||
for i in _quota_dots.size():
|
||||
_quota_dots[i].color = QUOTA_FILLED_COLOR if i < count else QUOTA_EMPTY_COLOR
|
||||
var style = _quota_filled_style if i < count else _quota_empty_style
|
||||
_quota_dots[i].add_theme_stylebox_override("panel", style)
|
||||
|
||||
func _update_perfect_zone():
|
||||
var bz = $TargetZone
|
||||
|
|
@ -185,28 +192,10 @@ func _update_perfect_zone():
|
|||
_perfect_zone.size = Vector2(width, bz.size.y)
|
||||
_perfect_zone.position = Vector2((bz.size.x - width) / 2.0, 0)
|
||||
|
||||
func launch_pulse():
|
||||
if not active:
|
||||
return
|
||||
pulse_x = 0.0
|
||||
pulse_active = true
|
||||
$SweepLine.visible = true
|
||||
$SweepLine.position.x = 0
|
||||
_glow.visible = true
|
||||
for ghost in _trail:
|
||||
ghost.visible = true
|
||||
$AIFace.text = ">:)"
|
||||
_start_ready_pulse()
|
||||
pulse_started.emit(size.x / pulse_speed)
|
||||
|
||||
func get_pulse_gap() -> float:
|
||||
return pulse_gap
|
||||
|
||||
func _process(delta):
|
||||
if not active:
|
||||
return
|
||||
|
||||
if block_zone_moving:
|
||||
if block_zone_moving and $TargetZone.visible:
|
||||
var bz = $TargetZone
|
||||
bz.position.x += block_zone_speed * block_zone_direction * delta
|
||||
if bz.position.x >= block_zone_max_x:
|
||||
|
|
@ -216,59 +205,24 @@ func _process(delta):
|
|||
bz.position.x = block_zone_min_x
|
||||
block_zone_direction = 1
|
||||
|
||||
if not pulse_active:
|
||||
return
|
||||
func _on_pulse_started(duration: float):
|
||||
pulse_started.emit(duration)
|
||||
|
||||
pulse_x += pulse_speed * delta
|
||||
$SweepLine.position.x = pulse_x
|
||||
_glow.position = Vector2(pulse_x - GLOW_PADDING.x, $SweepLine.position.y - GLOW_PADDING.y)
|
||||
for i in _trail.size():
|
||||
var gx = pulse_x - (i + 1) * TRAIL_SPACING
|
||||
_trail[i].visible = gx >= 0
|
||||
_trail[i].position = Vector2(gx, $SweepLine.position.y)
|
||||
func _on_pulse_blocked():
|
||||
$AIFace.text = ">:("
|
||||
_punch_face(1.4, 4.0)
|
||||
flash(Color.GREEN)
|
||||
pulse_blocked.emit()
|
||||
|
||||
if pulse_x >= size.x:
|
||||
pulse_active = false
|
||||
_hide_pulse_visuals()
|
||||
$AIFace.text = ":D"
|
||||
_punch_face(1.5, 0.0)
|
||||
flash(Color.RED)
|
||||
active = false
|
||||
doors_closing.emit()
|
||||
func _on_pulse_blocked_perfect():
|
||||
pulse_blocked_perfect.emit()
|
||||
|
||||
func attempt_block() -> bool:
|
||||
if not pulse_active:
|
||||
return false
|
||||
|
||||
var bz = $TargetZone
|
||||
var bz_left = bz.position.x
|
||||
var bz_right = bz.position.x + bz.size.x
|
||||
|
||||
if pulse_x >= bz_left and pulse_x <= bz_right:
|
||||
var perfect_left = bz_left + _perfect_zone.position.x
|
||||
var perfect_right = perfect_left + _perfect_zone.size.x
|
||||
var was_perfect = pulse_x >= perfect_left and pulse_x <= perfect_right
|
||||
pulse_active = false
|
||||
pulses_blocked += 1
|
||||
pulse_speed += pulse_speed_increase
|
||||
pulse_gap = max(pulse_gap - pulse_gap_decrease, pulse_gap_min)
|
||||
_hide_pulse_visuals()
|
||||
$AIFace.text = ">:("
|
||||
_punch_face(1.4, 4.0)
|
||||
flash(Color.GREEN)
|
||||
pulse_blocked.emit()
|
||||
if was_perfect:
|
||||
pulse_blocked_perfect.emit()
|
||||
return true
|
||||
else:
|
||||
pulse_active = false
|
||||
_hide_pulse_visuals()
|
||||
$AIFace.text = ":D"
|
||||
_punch_face(1.5, 0.0)
|
||||
flash(Color.RED)
|
||||
active = false
|
||||
doors_closing.emit()
|
||||
return false
|
||||
func _on_pulse_escaped():
|
||||
$AIFace.text = ":D"
|
||||
_punch_face(1.5, 0.0)
|
||||
flash(Color.RED)
|
||||
active = false
|
||||
doors_closing.emit()
|
||||
|
||||
func flash(color: Color):
|
||||
var style = get_theme_stylebox("panel") as StyleBoxFlat
|
||||
|
|
@ -329,12 +283,6 @@ func _stop_ready_pulse():
|
|||
_ready_pulse_tween = null
|
||||
$TargetZone.modulate.a = 1.0
|
||||
|
||||
func _hide_pulse_visuals():
|
||||
$SweepLine.visible = false
|
||||
_glow.visible = false
|
||||
for ghost in _trail:
|
||||
ghost.visible = false
|
||||
|
||||
func _punch_face(scale_amount: float, shake_amount: float):
|
||||
if _face_scale_tween:
|
||||
_face_scale_tween.kill()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue