27 lines
772 B
GDScript
27 lines
772 B
GDScript
extends CharacterBody2D
|
|
@export var move_speed: float = 100
|
|
@export var hp: int = 10
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
var damage: float = 2
|
|
print(damage)
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
var move_vector: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
|
velocity = move_vector * move_speed
|
|
if velocity == Vector2(0, 0):
|
|
$AnimatedSprite2D.stop()
|
|
elif velocity.x > 0:
|
|
$AnimatedSprite2D.play("move_right")
|
|
elif velocity.x < 0:
|
|
$AnimatedSprite2D.play("move_left")
|
|
elif velocity.y > 0:
|
|
$AnimatedSprite2D.play("move_down")
|
|
elif velocity.y < 0:
|
|
$AnimatedSprite2D.play("move_up")
|
|
|
|
move_and_slide()
|