#13 inventaire fonctionnel
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
extends CharacterBody2D
|
||||
class_name Player
|
||||
|
||||
signal player_stats_updated(player : Player)
|
||||
signal player_updated(player: Player)
|
||||
|
||||
@export var speed = 400
|
||||
|
||||
var energy : int = 10 :
|
||||
@onready var inventory: Inventory = Inventory.new()
|
||||
|
||||
var energy: int = 10:
|
||||
set(v):
|
||||
energy = v
|
||||
emit_signal("player_stats_updated", self)
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
func _ready():
|
||||
emit_signal("player_stats_updated", self)
|
||||
emit_signal("player_updated", self)
|
||||
inventory.inventory_changed.connect(_on_inventory_updated)
|
||||
|
||||
func _on_inventory_updated(_inventory: Inventory):
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
func get_input():
|
||||
calculate_direction()
|
||||
@@ -20,13 +26,13 @@ func get_input():
|
||||
try_interact()
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = input_direction * speed
|
||||
if input_direction.x:
|
||||
$Sprite.flip_h = (input_direction.x < 0)
|
||||
|
||||
func try_interact():
|
||||
var interactables : Array[Interactable]
|
||||
var interactables: Array[Interactable]
|
||||
|
||||
for area2D in $InteractArea2D.get_overlapping_areas():
|
||||
if area2D is Interactable:
|
||||
@@ -36,7 +42,7 @@ func try_interact():
|
||||
if len(interactables) > 1:
|
||||
# Sort them to the closer
|
||||
interactables.sort_custom(
|
||||
func (el1 : Interactable, el2 : Interactable):
|
||||
func(el1: Interactable, el2: Interactable):
|
||||
return el1.global_position.distance_to(global_position) > el2.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user