inventaire fonctionnel #13

This commit is contained in:
Altaezio
2025-08-03 19:38:46 +02:00
committed by Zacharie Guet
parent b164141d00
commit bca2300443
16 changed files with 112 additions and 46 deletions

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="GetSeedInteraction" load_steps=2 format=3 uid="uid://chmmu2jlo2eu0"]
[ext_resource type="Script" uid="uid://j5xvcabrspyb" path="res://entities/interactables/scripts/actions/get_seed.gd" id="1_ys78p"]
[resource]
script = ExtResource("1_ys78p")
metadata/_custom_type_script = "uid://j5xvcabrspyb"

View File

@@ -0,0 +1,8 @@
extends InteractableAction
class_name GetSeedInteraction
func action(p: Player, i : Interactable):
if i is Plant:
p.inventory.add_item(i.seed_item)
else :
printerr("No plant selected or interactable is not a plant")

View File

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

View File

@@ -1,8 +1,8 @@
extends InteractableAction
class_name WaterPlantAction
func action(_p: Player, _i : Interactable):
if _i is Plant:
_i.watered = true
func action(_p: Player, i : Interactable):
if i is Plant:
i.watered = true
else :
printerr("No plant selected or interactable is not a plant")

View File

@@ -1,7 +1,7 @@
extends Area2D
class_name Interactable
@export var actions : Array[InteractableAction] = [];
@export var actions : Array[InteractableAction] = []
func interact(p : Player):
for a in actions:

View File

@@ -1,37 +0,0 @@
[gd_scene load_steps=6 format=3 uid="uid://clpcqkdlj3d8e"]
[ext_resource type="Script" uid="uid://cega715smavh3" path="res://entities/plants/scripts/plant.gd" id="1_d8u7e"]
[ext_resource type="Texture2D" uid="uid://c6vby5r0pfni2" path="res://entities/plants/assets/sprites/default_plant.png" id="4_dq24f"]
[ext_resource type="Texture2D" uid="uid://b3wom2xu26g43" path="res://entities/plants/assets/sprites/default_plant_glowing.png" id="5_2gcie"]
[sub_resource type="CircleShape2D" id="CircleShape2D_cdbrd"]
[sub_resource type="SpriteFrames" id="SpriteFrames_ocwgi"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("4_dq24f")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("5_2gcie")
}],
"loop": true,
"name": &"watered",
"speed": 5.0
}]
[node name="DefaultPlant" type="Area2D"]
script = ExtResource("1_d8u7e")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
scale = Vector2(4.01154, 4.01154)
shape = SubResource("CircleShape2D_cdbrd")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.160462, 0.160462)
sprite_frames = SubResource("SpriteFrames_ocwgi")

View File

@@ -1,7 +1,7 @@
extends CharacterBody2D
class_name Player
signal player_stats_updated(player : Player)
signal player_updated(player: Player)
var controlling_player : bool = true
var planet : Planet # mis à jour par la classe Planet
@@ -14,10 +14,14 @@ var max_energy : int = 10
var energy : int = max_energy :
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():
if controlling_player:
@@ -27,7 +31,7 @@ func get_input():
action()
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)