init
This commit is contained in:
48
Scripts/Chair.gd
Normal file
48
Scripts/Chair.gd
Normal file
@@ -0,0 +1,48 @@
|
||||
extends StaticBody2D
|
||||
|
||||
signal on_player_entered_range
|
||||
signal on_player_exited_range
|
||||
|
||||
@onready var sit_marker = $SitMarker
|
||||
@onready var interaction_area = $InteractionArea
|
||||
|
||||
var is_occupied: bool = false
|
||||
var current_player: Node2D = null
|
||||
var player_in_range: Node2D = null
|
||||
|
||||
func _ready():
|
||||
interaction_area.body_entered.connect(_on_body_entered)
|
||||
interaction_area.body_exited.connect(_on_body_exited)
|
||||
|
||||
func _input(event):
|
||||
if is_occupied:
|
||||
return
|
||||
|
||||
if player_in_range and event is InputEventKey and event.pressed and event.keycode == KEY_E:
|
||||
_interact(player_in_range)
|
||||
|
||||
func _interact(player: Node2D):
|
||||
if is_occupied:
|
||||
return
|
||||
|
||||
is_occupied = true
|
||||
current_player = player
|
||||
|
||||
# Assume player has this method (we will implement it next)
|
||||
if player.has_method("start_sitting"):
|
||||
player.start_sitting(sit_marker.global_position, self)
|
||||
|
||||
# Called by player when they stand up
|
||||
func on_player_stand_up():
|
||||
is_occupied = false
|
||||
current_player = null
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body.has_method("start_sitting"):
|
||||
player_in_range = body
|
||||
emit_signal("on_player_entered_range")
|
||||
|
||||
func _on_body_exited(body):
|
||||
if body == player_in_range:
|
||||
player_in_range = null
|
||||
emit_signal("on_player_exited_range")
|
||||
Reference in New Issue
Block a user