You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

39 lines
1.1 KiB

extends Node
class_name PlayerAttack
const speed_scale = 4
const animation_name = "slash"
func input(actor):
actor.get_node("PlayerAttack/Area2D").show()
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)
## BAD #### \/
if collision.collider.has_method("on_attack"):
collision.collider.on_attack()
func sprite_finished(actor):
actor.get_node("PlayerAttack/Area2D").hide()
actor.state = actor.PlayerState.NORMAL
actor.get_animated_sprite().flip_h = false
actor.get_animated_sprite().speed_scale = 1
# WHY DOESN'T WORK?!?!?!?!?!?!?1?
func _on_Area2D_body_entered(body):
if body.has_method("on_attack"):
body.on_attack()