better animations
This commit is contained in:
@@ -4,63 +4,67 @@ extends StaticBody2D
|
||||
enum Direction { LEFT, RIGHT, FRONT }
|
||||
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
const SEAT_HEIGHT_OFFSET := 8
|
||||
@onready var collision_shape: CollisionShape2D = $CollisionShape2D
|
||||
|
||||
var seat_height_offset = 8
|
||||
var player: Player
|
||||
var input_released: bool = true
|
||||
var move_input: Vector2 = Vector2.ZERO
|
||||
var input_released = true
|
||||
var move_input = Vector2.ZERO
|
||||
|
||||
@export var direction: Direction = Direction.RIGHT:
|
||||
set(value):
|
||||
direction = value
|
||||
flip_chair()
|
||||
update_chair_visuals()
|
||||
|
||||
func _ready() -> void:
|
||||
flip_chair()
|
||||
update_chair_visuals()
|
||||
|
||||
func flip_chair() -> void:
|
||||
if !sprite:
|
||||
func update_chair_visuals() -> void:
|
||||
if not sprite:
|
||||
return
|
||||
var atlas_tex := sprite.texture as AtlasTexture
|
||||
match direction:
|
||||
Direction.LEFT:
|
||||
atlas_tex.region.position.x = 32
|
||||
sprite.flip_h = true
|
||||
Direction.RIGHT:
|
||||
atlas_tex.region.position.x = 32
|
||||
sprite.flip_h = false
|
||||
Direction.FRONT:
|
||||
atlas_tex.region.position.x = -3
|
||||
sprite.flip_h = false
|
||||
var atlas_tex = sprite.texture as AtlasTexture
|
||||
if direction == Direction.FRONT:
|
||||
atlas_tex.region.position.x = -3
|
||||
seat_height_offset = -5
|
||||
sprite.flip_h = false
|
||||
else:
|
||||
atlas_tex.region.position.x = 32
|
||||
seat_height_offset = 8
|
||||
sprite.flip_h = direction == Direction.LEFT
|
||||
|
||||
func _on_interacted(p_player: Player) -> void:
|
||||
if player:
|
||||
unmount()
|
||||
unmount_player()
|
||||
else:
|
||||
y_sort_enabled = false
|
||||
player = p_player
|
||||
player.z_index = 2
|
||||
input_released = move_input.length() == 0
|
||||
player.animated_sprite.animation = "sit"
|
||||
player.animated_sprite.flip_h = direction == Direction.LEFT
|
||||
player.position = Vector2(position.x, position.y - SEAT_HEIGHT_OFFSET)
|
||||
mount_player(p_player)
|
||||
|
||||
func mount_player(p_player: Player) -> void:
|
||||
collision_shape.disabled = true
|
||||
y_sort_enabled = false
|
||||
z_index = -1
|
||||
player = p_player
|
||||
input_released = move_input.length() == 0
|
||||
player.animated_sprite.flip_h = direction == Direction.LEFT
|
||||
player.position = Vector2(position.x, position.y - seat_height_offset)
|
||||
player.animated_sprite.animation = "sit_down" if direction == Direction.FRONT else "sit_side"
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if !Engine.is_editor_hint() && EventManager.player_free && player:
|
||||
move_input = Input.get_vector("move_left","move_right","move_up","move_down")
|
||||
if move_input.length() == 0:
|
||||
input_released = true
|
||||
elif input_released:
|
||||
unmount()
|
||||
if Engine.is_editor_hint() || !EventManager.player_free || !player:
|
||||
return
|
||||
move_input = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
if move_input.length() == 0:
|
||||
input_released = true
|
||||
elif input_released:
|
||||
unmount_player()
|
||||
|
||||
|
||||
func unmount() -> void:
|
||||
func unmount_player() -> void:
|
||||
if direction == Direction.FRONT:
|
||||
player.position = Vector2(position.x -16, position.y)
|
||||
player.position = Vector2(position.x - 16, position.y)
|
||||
else:
|
||||
player.position = Vector2(position.x, position.y + 8)
|
||||
player.animated_sprite.animation = "down"
|
||||
player.z_index = 0
|
||||
z_index = 0
|
||||
player = null
|
||||
input_released = true
|
||||
y_sort_enabled = true
|
||||
collision_shape.disabled = false
|
||||
|
||||
Reference in New Issue
Block a user