86 lines
1.9 KiB
GDScript
86 lines
1.9 KiB
GDScript
extends CharacterBody3D
|
|
|
|
signal station_reached
|
|
|
|
const BASE_STAMINA = 50
|
|
const BASE_SPEED = 20
|
|
const SPRINT_MULT = 1.6
|
|
const SLOW_MULT = 0.5
|
|
const STAMINA_COST = 15
|
|
const STAMINA_RECOVER = 10
|
|
|
|
var pedestrian_area_count = 0
|
|
|
|
var max_stamina: float = BASE_STAMINA
|
|
var stamina: float = max_stamina
|
|
|
|
var stage_counter: int = 0
|
|
|
|
func _ready() -> void:
|
|
$Upgrades.update()
|
|
|
|
$FailControl.visible = false
|
|
$TimeLimit.start()
|
|
$HUD.visible = true
|
|
|
|
func _process(delta: float) -> void:
|
|
# On fail screen, ignore further input
|
|
if $FailControl.visible:
|
|
return
|
|
|
|
$HUD/StaminaRect.scale.x = stamina / max_stamina
|
|
$HUD/StageLabel.text = "Stage %d" % [stage_counter + 1]
|
|
|
|
var time_left = int($TimeLimit.time_left)
|
|
@warning_ignore("integer_division")
|
|
$HUD/TimeLimitLabel.text = "%02d:%02d" % [time_left/60, time_left]
|
|
|
|
var dir = Input.get_vector("player_move_left", "player_move_right", "player_move_up", "player_move_down")
|
|
var speed: float = BASE_SPEED
|
|
|
|
if (pedestrian_area_count > 0):
|
|
speed *= SLOW_MULT
|
|
|
|
|
|
if Input.is_action_pressed("player_sprint") and stamina > 0:
|
|
stamina -= STAMINA_COST * delta
|
|
speed *= SPRINT_MULT
|
|
elif stamina <= max_stamina:
|
|
stamina += STAMINA_RECOVER * delta
|
|
|
|
self.velocity = Vector3(dir.x * speed, 0, dir.y * speed)
|
|
|
|
self.move_and_slide()
|
|
|
|
|
|
func _on_area_area_entered(area: Area3D) -> void:
|
|
if area.name == "PedestrianArea":
|
|
pedestrian_area_count += 1
|
|
print(pedestrian_area_count)
|
|
|
|
if area.name == "StationArea":
|
|
stage_counter += 1
|
|
station_reached.emit()
|
|
$TimeLimit.start()
|
|
stamina = max_stamina
|
|
|
|
|
|
func _on_area_area_exited(area: Area3D) -> void:
|
|
if area.name == "PedestrianArea":
|
|
pedestrian_area_count -= 1
|
|
print(pedestrian_area_count)
|
|
|
|
|
|
func _on_time_limit_timeout():
|
|
$FailControl.visible = true
|
|
$HUD.visible = false
|
|
|
|
|
|
func _on_retry_button_pressed():
|
|
stage_counter = 0
|
|
$FailControl.visible = false
|
|
$HUD.visible = true
|
|
station_reached.emit()
|
|
$TimeLimit.start()
|
|
stamina = max_stamina
|