This commit is contained in:
2025-10-26 02:57:00 +02:00
parent 1fe75a871e
commit eea9c18358
18 changed files with 216 additions and 41 deletions

View File

@@ -20,5 +20,6 @@ func run_event(event: Events, player_postion: Vector2 = Vector2.ZERO):
match event:
Events.PUMPKIN_CARVE:
get_tree().change_scene_to_file("uid://ccfdsdgaon63m") # scenes/levels/home.tscn
pass
await get_tree().scene_changed
player.animated_sprite.animation = "sit" # should be replaced with chair interaction trigger
transition_end()

View File

@@ -1,6 +1,6 @@
class_name Interactable
extends Area2D
signal interacted
signal interacted(player: Player)
func interact() -> void: interacted.emit()
func interact(player: Player) -> void: interacted.emit(player)

View File

@@ -0,0 +1,62 @@
@tool
extends StaticBody2D
enum Direction { LEFT, RIGHT, FRONT }
@onready var sprite: Sprite2D = $Sprite2D
const SEAT_HEIGHT_OFFSET := 8
var player: Player
var input_released: bool = true
var move_input: Vector2 = Vector2.ZERO
@export var direction: Direction = Direction.RIGHT:
set(value):
direction = value
flip_chair()
func _ready() -> void:
flip_chair()
func flip_chair() -> void:
if !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
func _on_interacted(p_player: Player) -> void:
if player:
unmount()
else:
player = p_player
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)
func _process(_delta: float) -> void:
if 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()
func unmount() -> void:
if direction == Direction.FRONT:
player.position = Vector2(position.x -16, position.y)
else:
player.position = Vector2(position.x, position.y + 8)
player.animated_sprite.animation = "down"
player = null
input_released = true

View File

@@ -0,0 +1 @@
uid://c1xp6fm2mh83g

View File

@@ -2,5 +2,5 @@ extends Node2D
@export var scene: PackedScene
func _on_interactable_interacted() -> void:
func _on_interacted(_player: Player) -> void:
get_tree().change_scene_to_packed(scene)

View File

@@ -12,6 +12,7 @@ const RAYCAST_RAGE: int = 32
@export var tilemap: TileMapLayer
var tilesize: int = 32
var position_limit_rect: Rect2
const STILL_POSITIONS: Array[String] = ["sit", "hand_down", "hand_side", "hand_up"]
func _ready() -> void:
EventManager.player = self
@@ -36,10 +37,10 @@ func _ready() -> void:
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("interact") && raycast.is_colliding() && raycast.get_collider() is Interactable:
var interactable: Interactable = raycast.get_collider()
interactable.interact()
interactable.interact(self)
func _physics_process(delta: float) -> void:
if EventManager.player_free:
if !STILL_POSITIONS.has(animated_sprite.animation) && EventManager.player_free:
var input := Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
var raycast_input := Vector2.ZERO
@@ -52,18 +53,18 @@ func _physics_process(delta: float) -> void:
velocity = input * delta * SPEED * 3
move_and_slide()
position = position.clamp(position_limit_rect.position, position_limit_rect.end)
move_and_slide()
position = position.clamp(position_limit_rect.position, position_limit_rect.end)
if velocity.length() != 0:
animated_sprite.play()
animated_sprite.flip_h = false
if abs(velocity.x) > abs(velocity.y):
animated_sprite.animation = "side"
animated_sprite.flip_h = velocity.x < 0
elif velocity.y < 0:
animated_sprite.animation = "up"
if velocity.length() != 0:
animated_sprite.play()
animated_sprite.flip_h = false
if abs(velocity.x) > abs(velocity.y):
animated_sprite.animation = "side"
animated_sprite.flip_h = velocity.x < 0
elif velocity.y < 0:
animated_sprite.animation = "up"
else:
animated_sprite.animation = "down"
else:
animated_sprite.animation = "down"
else:
animated_sprite.stop()
animated_sprite.stop()