47 lines
1.2 KiB
GDScript3
47 lines
1.2 KiB
GDScript3
|
extends CharacterBody2D
|
||
|
|
||
|
signal interact
|
||
|
signal interact2
|
||
|
const SPEED = 300.0
|
||
|
|
||
|
@export var moving = true
|
||
|
|
||
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||
|
|
||
|
func handle_layer(direction):
|
||
|
if round(direction.y) == -1:
|
||
|
$character/body/tail.z_index = 1
|
||
|
$character/body/face.visible = false
|
||
|
elif round(direction.y) == 1:
|
||
|
$character/body/tail.z_index = 0
|
||
|
$character/body/face.visible = true
|
||
|
|
||
|
|
||
|
func _physics_process(_delta):
|
||
|
if Input.is_action_just_pressed("interact"):
|
||
|
interact.emit()
|
||
|
if Input.is_action_just_pressed("interact 2"):
|
||
|
interact2.emit()
|
||
|
if not moving: return
|
||
|
|
||
|
# Get the input direction and handle the movement/deceleration.
|
||
|
# As good practice, you should replace UI actions with custom gawameplay actions.
|
||
|
var direction = Input.get_vector("left","right","up","down")
|
||
|
if direction == Vector2(0,0):
|
||
|
$AnimationPlayer.current_animation = "idle"
|
||
|
else:
|
||
|
handle_layer(direction)
|
||
|
|
||
|
print(direction.x)
|
||
|
if not direction.x == 0:
|
||
|
|
||
|
$character.scale.x = round(direction.x)
|
||
|
$AnimationPlayer.current_animation = "walk"
|
||
|
else:
|
||
|
$AnimationPlayer.current_animation = "vmove"
|
||
|
|
||
|
velocity = direction * SPEED
|
||
|
|
||
|
|
||
|
move_and_slide()
|