giants-godot/characters/kabuto.gd

47 lines
1.2 KiB
GDScript

extends Character
class_name Kabuto
export var max_sprint_units: float = 1000
export var sprint_reload_units: float = 2000
var sprint_units_left: float = 0
var sprint_reload_units_left: float = 0
signal sprint_available
signal sprint_ended
signal sprint_used
func echo_signal(s):
print("Kabuto: %s" % s)
func _ready():
connect("sprint_available", self, "echo_signal", ["sprint_available"])
connect("sprint_used", self, "echo_signal", ["sprint_used"])
connect("sprint_ended", self, "echo_signal", ["sprint_ended"])
func is_sprinting() -> bool:
return sprint_units_left > 0
func sprint_available() -> bool:
return not is_sprinting() and sprint_reload_units_left <= 0
func start_sprint():
if sprint_available():
sprint_units_left = max_sprint_units
sprint_reload_units_left = sprint_reload_units
emit_signal("sprint_used")
func walk(delta):
.walk(delta)
return
var floor_vel = get_floor_velocity()
if is_on_floor() and sprint_units_left > 0:
sprint_units_left -= floor_vel.length()
if sprint_units_left <= 0:
emit_signal("sprint_ended")
if is_on_floor() and sprint_reload_units_left > 0:
sprint_reload_units_left -= floor_vel.length()
if sprint_reload_units_left <= 0:
emit_signal("sprint_available")