#37 ajout d'item outils ainsi que de visualisation de leur zone d'effet (avec la classe ActionArea

This commit is contained in:
2025-08-19 11:29:20 +02:00
parent b0efeff809
commit 1f301815be
18 changed files with 233 additions and 89 deletions

View File

@@ -1,7 +1,7 @@
[gd_resource type="Resource" script_class="SeedItem" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
[gd_resource type="Resource" script_class="Seed" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/assets/icons/bolt.svg" id="1_dy25s"]
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed_item.gd" id="2_mgcdi"]
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed.gd" id="2_mgcdi"]
[resource]
script = ExtResource("2_mgcdi")

View File

@@ -31,15 +31,26 @@ func add_items(items_to_add: Array[Item], fillup: bool = false):
func lenght() -> int:
return len(items)
func get_item(ind: int = 0):
func set_item(item : Item, ind: int = 0) -> bool:
if ind >= max_items:
return false
while len(items) <= ind:
items.append(null)
items[ind] = item
emit_signal("inventory_changed", self)
return true
func get_item(ind: int = 0) -> Item:
if len(items) <= ind:
return null;
return items[ind]
func pop_item(ind: int = 0):
func pop_item(ind: int = 0) -> Item:
var item_removed: Item = items.pop_at(ind)
emit_signal("inventory_changed", self)
return item_removed
func swap_items(item_to_add: Item, ind_to_get: int = 0):
func swap_items(item_to_add: Item, ind_to_get: int = 0) -> Item:
var item_to_get := items[ind_to_get]
items[ind_to_get] = item_to_add
emit_signal("inventory_changed", self)

View File

@@ -1,6 +1,6 @@
@tool
extends Item
class_name SeedItem
class_name Seed
@export var plant_type: PlantType :
set(v):

View File

@@ -0,0 +1,12 @@
extends ToolItem
class_name Shovel
func can_use(player : Player) -> bool:
var areas = player.action_area.get_overlapping_areas()
for area in areas :
if area is Plant:
return true
return false
func use(_player : Player) -> bool:
return false

View File

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

View File

@@ -0,0 +1,11 @@
extends Item
class_name ToolItem
@export var area_width: float = 50
@export var area_distance: float = 50
func generate_action_area():
return ActionArea.new(
area_width,
area_distance
)

View File

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