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.
38 lines
1.1 KiB
GDScript
38 lines
1.1 KiB
GDScript
extends Node
|
|
class_name PlayerNormal
|
|
|
|
func run(actor, delta):
|
|
|
|
var velocity = Vector2() # The player's movement vector.
|
|
if Input.is_key_pressed(KEY_SHIFT):
|
|
actor.setState(actor.PlayerState.DASHING)
|
|
if Input.is_key_pressed(KEY_Z):
|
|
actor.setState(actor.PlayerState.ATTACKING)
|
|
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.getAnimatedSprite().play()
|
|
|
|
actor.position += velocity * delta
|
|
actor.position.x = clamp(actor.position.x, 0, actor.get_viewport_rect().size.x)
|
|
actor.position.y = clamp(actor.position.y, 0, actor.get_viewport_rect().size.y)
|
|
|
|
if velocity.x > 0 or velocity.y != 0:
|
|
actor.getAnimatedSprite().animation = "forward"
|
|
elif velocity.x < 0:
|
|
actor.getAnimatedSprite().animation = "backward"
|
|
else:
|
|
actor.getAnimatedSprite().animation = "idle"
|
|
|
|
actor.last_process_velocity = velocity
|
|
|
|
func spriteFinished(actor):
|
|
pass
|