|
|
|
extends Node
|
|
|
|
class_name PlayerDash
|
|
|
|
|
|
|
|
var keymap
|
|
|
|
|
|
|
|
const speed_scale = 2.5
|
|
|
|
const animation_name = "dash"
|
|
|
|
|
|
|
|
func ready(actor):
|
|
|
|
var ak = AttackKey.new()
|
|
|
|
keymap = { KEY_Z: ak.register(actor) }
|
|
|
|
|
|
|
|
func input(actor):
|
|
|
|
actor.show()
|
|
|
|
pass
|
|
|
|
|
|
|
|
func process(actor):
|
|
|
|
actor.get_animated_sprite().animation = animation_name
|
|
|
|
actor.get_animated_sprite().speed_scale = speed_scale
|
|
|
|
actor.get_animated_sprite().flip_h = actor.velocity.x < 0
|
|
|
|
|
|
|
|
func physics_process(actor, delta):
|
|
|
|
var velocity = actor.velocity
|
|
|
|
velocity = velocity.normalized() * actor.speed
|
|
|
|
if velocity.length() > 0:
|
|
|
|
actor.get_animated_sprite().play()
|
|
|
|
|
|
|
|
var collision = actor.move_and_collide(velocity * delta)
|
|
|
|
if collision:
|
|
|
|
collision.collider.on_collide(actor)
|
|
|
|
|
|
|
|
func sprite_finished(actor):
|
|
|
|
actor.state = actor.PlayerState.STANDING
|
|
|
|
actor.get_animated_sprite().flip_h = false
|
|
|
|
actor.get_animated_sprite().speed_scale = 1
|