2024-07-19 23:01:49 +00:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
2024-07-23 09:41:26 +00:00
|
|
|
@export_group("Skins")
|
|
|
|
@export var CurrentSkin: CanvasTexture
|
|
|
|
@export var CurrentHat: CanvasTexture
|
2024-07-19 23:01:49 +00:00
|
|
|
|
2024-07-23 09:01:03 +00:00
|
|
|
const SPEED = 700.0
|
2024-07-19 23:01:49 +00:00
|
|
|
|
2024-07-23 09:41:26 +00:00
|
|
|
# Change the skin on every sprite
|
|
|
|
func changeSkin(NewSkin:CanvasTexture,_NewHat:CanvasTexture = null):
|
|
|
|
CurrentSkin = NewSkin
|
|
|
|
if (_NewHat):
|
|
|
|
CurrentHat = _NewHat
|
|
|
|
|
|
|
|
for Sprite :Sprite2D in $Skeleton2D.get_children():
|
|
|
|
if (Sprite.has_meta("Type") and Sprite.get_meta("Type") == "Skin"):
|
|
|
|
Sprite.texture = CurrentSkin
|
|
|
|
if (Sprite.has_meta("Type") and Sprite.get_meta("Type") == "Hat"):
|
|
|
|
Sprite.texture = CurrentHat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-23 08:06:01 +00:00
|
|
|
func get_input():
|
2024-07-22 14:48:39 +00:00
|
|
|
var directionX = Input.get_axis("move_left", "move_right")
|
|
|
|
var directionY = Input.get_axis("move_up", "move_down")
|
2024-07-23 09:41:26 +00:00
|
|
|
#region Movement
|
|
|
|
## Get the input direction and handle the movement/deceleration.
|
2024-07-19 23:01:49 +00:00
|
|
|
if directionX :
|
|
|
|
velocity.x = directionX * SPEED
|
|
|
|
else:
|
|
|
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
|
|
if directionY:
|
|
|
|
velocity.y = directionY * SPEED
|
|
|
|
else:
|
|
|
|
velocity.y = move_toward(velocity.y, 0, SPEED)
|
2024-07-23 09:41:26 +00:00
|
|
|
#endregion
|
2024-07-23 08:06:01 +00:00
|
|
|
#region Animation
|
|
|
|
if (directionX < 0):
|
|
|
|
$Skeleton2D/root/Hips.set_scale(Vector2(1, 1))
|
|
|
|
if (directionX > 0):
|
|
|
|
$Skeleton2D/root/Hips.set_scale(Vector2(-1, 1))
|
2024-07-23 09:01:03 +00:00
|
|
|
|
|
|
|
$AnimationTree.set("parameters/WalkRun/blend_position",max(abs(velocity.x),abs(velocity.y)))
|
2024-07-23 08:06:01 +00:00
|
|
|
#endregion
|
2024-07-22 20:14:04 +00:00
|
|
|
|
2024-07-23 08:06:01 +00:00
|
|
|
func _physics_process(delta):
|
|
|
|
get_input()
|
2024-07-19 23:01:49 +00:00
|
|
|
move_and_slide()
|