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

47 lines
1.1 KiB
GDScript

extends Node
class_name PlayerNormal
var keymap
func ready(actor):
var ak = AttackKey.new()
keymap = { KEY_Z: ak.register(actor) }
func input(actor):
var velocity = Vector2() # The player's movement vector.
var keys = keymap.keys()
for i in keys:
if Input.is_key_pressed(i):
keymap[i].trigger(actor)
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * actor.speed
actor.get_animated_sprite().play()
actor.velocity = velocity
func process(actor):
if actor.velocity.x > 0 or actor.velocity.y != 0:
actor.get_animated_sprite().animation = "forward"
elif actor.velocity.x < 0:
actor.get_animated_sprite().animation = "backward"
else:
actor.get_animated_sprite().animation = "idle"
func physics_process(actor, delta):
var collision = actor.move_and_collide(actor.velocity * delta)
if collision:
collision.collider.on_collide(actor)
func sprite_finished(actor):
actor.show()