ajout des particules de roche et changement de l'écran de chargement
This commit is contained in:
@@ -99,25 +99,23 @@ func calculate_direction():
|
||||
func turn_animate(input_direction):
|
||||
if input_direction.x > TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
if input_direction.y > TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("front_right")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.FRONT_RIGHT
|
||||
elif input_direction.y < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("back_right")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.BACK_RIGHT
|
||||
else:
|
||||
%Sprite.play("right")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.RIGHT
|
||||
elif input_direction.x < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
if input_direction.y > TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("front_left")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.FRONT_LEFT
|
||||
elif input_direction.y < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("back_left")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.BACK_LEFT
|
||||
else:
|
||||
%Sprite.play("left")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.LEFT
|
||||
else:
|
||||
if input_direction.y > TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("front")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.FRONT
|
||||
elif input_direction.y < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("back")
|
||||
else:
|
||||
%Sprite.play("front")
|
||||
%PlayerSprite.wanted_orientation = PlayerSprite.ROrient.BACK
|
||||
|
||||
func can_interact(interactable : Interactable):
|
||||
return interactable.can_interact(self)
|
||||
|
||||
113
entities/player/scripts/player_sprite.gd
Normal file
113
entities/player/scripts/player_sprite.gd
Normal file
@@ -0,0 +1,113 @@
|
||||
@tool
|
||||
extends AnimatedSprite2D
|
||||
class_name PlayerSprite
|
||||
|
||||
const ORIENTATION_TIME = 0.1
|
||||
|
||||
enum ROrient {
|
||||
FRONT,
|
||||
FRONT_RIGHT,
|
||||
FRONT_LEFT,
|
||||
BACK,
|
||||
BACK_RIGHT,
|
||||
BACK_LEFT,
|
||||
RIGHT,
|
||||
LEFT,
|
||||
}
|
||||
|
||||
@export var wanted_orientation : ROrient
|
||||
var orientation : ROrient : set = set_orientation
|
||||
|
||||
var time_since_last_orientation = 10.
|
||||
|
||||
func _process(delta):
|
||||
time_since_last_orientation += delta
|
||||
|
||||
if time_since_last_orientation > ORIENTATION_TIME and wanted_orientation != orientation:
|
||||
time_since_last_orientation = 0.
|
||||
if is_closest_clockwise(orientation, wanted_orientation):
|
||||
orientation = clock_wise(orientation)
|
||||
else :
|
||||
orientation = counter_clock_wise(orientation)
|
||||
|
||||
|
||||
func set_orientation(o : ROrient = orientation):
|
||||
orientation = o
|
||||
if is_node_ready() and animation != orientation_to_str(o):
|
||||
play(orientation_to_str(o))
|
||||
|
||||
|
||||
static func orientation_to_str(o : ROrient) -> String:
|
||||
match o:
|
||||
ROrient.FRONT:
|
||||
return "front"
|
||||
ROrient.FRONT_RIGHT:
|
||||
return "front_right"
|
||||
ROrient.FRONT_LEFT:
|
||||
return "front_left"
|
||||
ROrient.BACK:
|
||||
return "back"
|
||||
ROrient.BACK_RIGHT:
|
||||
return "back_right"
|
||||
ROrient.BACK_LEFT:
|
||||
return "back_left"
|
||||
ROrient.RIGHT:
|
||||
return "right"
|
||||
ROrient.LEFT:
|
||||
return "left"
|
||||
_:
|
||||
return "front"
|
||||
|
||||
static func clock_wise(o : ROrient) -> ROrient:
|
||||
match o:
|
||||
ROrient.FRONT:
|
||||
return ROrient.FRONT_LEFT
|
||||
ROrient.FRONT_LEFT:
|
||||
return ROrient.LEFT
|
||||
ROrient.LEFT:
|
||||
return ROrient.BACK_LEFT
|
||||
ROrient.BACK_LEFT:
|
||||
return ROrient.BACK
|
||||
ROrient.BACK:
|
||||
return ROrient.BACK_RIGHT
|
||||
ROrient.BACK_RIGHT:
|
||||
return ROrient.RIGHT
|
||||
ROrient.RIGHT:
|
||||
return ROrient.FRONT_RIGHT
|
||||
ROrient.FRONT_RIGHT:
|
||||
return ROrient.FRONT
|
||||
_:
|
||||
return ROrient.FRONT
|
||||
|
||||
static func counter_clock_wise(o : ROrient) -> ROrient:
|
||||
match o:
|
||||
ROrient.FRONT:
|
||||
return ROrient.FRONT_RIGHT
|
||||
ROrient.FRONT_RIGHT:
|
||||
return ROrient.RIGHT
|
||||
ROrient.RIGHT:
|
||||
return ROrient.BACK_RIGHT
|
||||
ROrient.BACK_RIGHT:
|
||||
return ROrient.BACK
|
||||
ROrient.BACK:
|
||||
return ROrient.BACK_LEFT
|
||||
ROrient.BACK_LEFT:
|
||||
return ROrient.LEFT
|
||||
ROrient.LEFT:
|
||||
return ROrient.FRONT_LEFT
|
||||
ROrient.FRONT_LEFT:
|
||||
return ROrient.FRONT
|
||||
_:
|
||||
return ROrient.FRONT
|
||||
|
||||
static func is_closest_clockwise(
|
||||
current : ROrient,
|
||||
wanted : ROrient,
|
||||
):
|
||||
var move := current
|
||||
var step := 0
|
||||
while move != wanted:
|
||||
step += 1
|
||||
move = clock_wise(move)
|
||||
return step < 4
|
||||
|
||||
1
entities/player/scripts/player_sprite.gd.uid
Normal file
1
entities/player/scripts/player_sprite.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b1mmtgmi5oq86
|
||||
Reference in New Issue
Block a user