modification du sprite du robot et fix en tout genre
This commit is contained in:
@@ -4,6 +4,7 @@ class_name Player
|
||||
const ACTION_AREA_UPDATE_TIME=0.05 # When creating an action_zone, we make sure that the area setup correctly by waiting a little
|
||||
const MAX_REACH = 100
|
||||
const HOLDING_ITEM_SPRITE_SIZE = 20.
|
||||
const TURN_ANIMATION_MINIMUM_THRESHOLD = 0.2
|
||||
|
||||
signal player_updated(player: Player)
|
||||
signal upgraded
|
||||
@@ -73,19 +74,8 @@ func _process(delta):
|
||||
|
||||
func _on_inventory_updated(_inventory: Inventory):
|
||||
setup_preview_zone(data.inventory.get_item())
|
||||
var item : Item = data.inventory.get_item()
|
||||
if item:
|
||||
var item_texture = item.icon
|
||||
%ItemSprite.texture = item_texture
|
||||
%ItemSprite.scale = Vector2(
|
||||
1./(item_texture.get_width()/HOLDING_ITEM_SPRITE_SIZE),
|
||||
1./(item_texture.get_height()/HOLDING_ITEM_SPRITE_SIZE)
|
||||
)
|
||||
%HideEyes.visible = item != null
|
||||
%ItemSprite.visible = item != null
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
@@ -102,14 +92,32 @@ func calculate_direction():
|
||||
input_direction = self.global_position.direction_to(instruction.position)
|
||||
|
||||
velocity = input_direction * speed
|
||||
if input_direction.x:
|
||||
flip_character(input_direction.x > 0)
|
||||
|
||||
turn_animate(input_direction)
|
||||
|
||||
|
||||
func flip_character(face_right = true):
|
||||
$Sprite.flip_h = not face_right
|
||||
%ItemSprite.position.x = abs(%ItemSprite.position.x) * (1 if face_right else -1)
|
||||
%HideEyes.position.x = abs(%ItemSprite.position.x) * (1 if face_right else -1)
|
||||
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")
|
||||
elif input_direction.y < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("back_right")
|
||||
else:
|
||||
%Sprite.play("right")
|
||||
elif input_direction.x < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
if input_direction.y > TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("front_left")
|
||||
elif input_direction.y < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("back_left")
|
||||
else:
|
||||
%Sprite.play("left")
|
||||
else:
|
||||
if input_direction.y > TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("front")
|
||||
elif input_direction.y < -TURN_ANIMATION_MINIMUM_THRESHOLD:
|
||||
%Sprite.play("back")
|
||||
else:
|
||||
%Sprite.play("front")
|
||||
|
||||
func can_interact(interactable : Interactable):
|
||||
return interactable.can_interact(self)
|
||||
|
||||
Reference in New Issue
Block a user