#13 suite du developpement d'inventaire avec le rajout des ItemObjects, description sur le GUI, items d'exemple et corrections mineures
This commit was merged in pull request #35.
This commit is contained in:
52
entities/interactables/item_object/assets/sprites/shadow.svg
Normal file
52
entities/interactables/item_object/assets/sprites/shadow.svg
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="#ffffff"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="icon icon-tabler icons-tabler-outline icon-tabler-shovel"
|
||||
version="1.1"
|
||||
id="svg4"
|
||||
sodipodi:docname="shadow.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="namedview4"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#ffffff"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="1"
|
||||
inkscape:deskcolor="#505050"
|
||||
inkscape:zoom="26.162951"
|
||||
inkscape:cx="12.479479"
|
||||
inkscape:cy="16.320789"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1009"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg4" />
|
||||
<path
|
||||
stroke="none"
|
||||
d="M0 0h24v24H0z"
|
||||
fill="none"
|
||||
id="path1" />
|
||||
<ellipse
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:square"
|
||||
id="path4"
|
||||
cx="12"
|
||||
cy="12"
|
||||
rx="11.73415"
|
||||
ry="3.9113834" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c1eiu5ag7lcp8"
|
||||
path="res://.godot/imported/shadow.svg-3484c898461c709704cdbeef0cc1d3c3.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/interactables/item_object/assets/sprites/shadow.svg"
|
||||
dest_files=["res://.godot/imported/shadow.svg-3484c898461c709704cdbeef0cc1d3c3.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=2.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
6
entities/interactables/item_object/item_object.tscn
Normal file
6
entities/interactables/item_object/item_object.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cd3re3552pt7m"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dedg615xudpoq" path="res://entities/interactables/item_object/script/item_object.gd" id="1_hxea8"]
|
||||
|
||||
[node name="ItemObject" type="Area2D"]
|
||||
script = ExtResource("1_hxea8")
|
||||
106
entities/interactables/item_object/item_object_sprite.tscn
Normal file
106
entities/interactables/item_object/item_object_sprite.tscn
Normal file
@@ -0,0 +1,106 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bcj812ox8xv2t"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/inventory/assets/icons/shovel.svg" id="1_7u8ru"]
|
||||
[ext_resource type="Texture2D" uid="uid://c1eiu5ag7lcp8" path="res://entities/interactables/item_object/assets/sprites/shadow.svg" id="2_ng201"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ng201"]
|
||||
resource_name = "default"
|
||||
length = 2.0
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:position")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1, 2),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -5), Vector2(0, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Shadow:position")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 1, 2),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 23), Vector2(0, 28), Vector2(0, 23)]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Shadow:scale")
|
||||
tracks/2/interp = 2
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0, 1, 2),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0.875, 0.875), Vector2(0.7, 0.7), Vector2(0.875, 0.875)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_wing4"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Shadow:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 23)]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Shadow:scale")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0.875, 0.875)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_ng3e4"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_wing4"),
|
||||
&"default": SubResource("Animation_ng201")
|
||||
}
|
||||
|
||||
[node name="ItemObjectSprite" type="Sprite2D"]
|
||||
texture = ExtResource("1_7u8ru")
|
||||
|
||||
[node name="Shadow" type="Sprite2D" parent="."]
|
||||
modulate = Color(1, 1, 1, 0.227451)
|
||||
z_index = -1
|
||||
position = Vector2(0, 23)
|
||||
scale = Vector2(0.875, 0.875)
|
||||
texture = ExtResource("2_ng201")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_ng3e4")
|
||||
}
|
||||
autoplay = "default"
|
||||
48
entities/interactables/item_object/script/item_object.gd
Normal file
48
entities/interactables/item_object/script/item_object.gd
Normal file
@@ -0,0 +1,48 @@
|
||||
extends Interactable
|
||||
class_name ItemObject
|
||||
|
||||
const ITEM_AREA_WIDTH = 10
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/interactables/item_object/item_object_sprite.tscn")
|
||||
|
||||
@export var item : Item :
|
||||
set(_item):
|
||||
item = _item
|
||||
if sprite:
|
||||
sprite.texture = item.icon
|
||||
|
||||
@onready var sprite : Sprite2D = generate_sprite()
|
||||
|
||||
func _init(_item = null):
|
||||
if _item:
|
||||
item = _item
|
||||
|
||||
func _ready():
|
||||
generate_collision(10)
|
||||
|
||||
func interact(player : Player) -> bool:
|
||||
if player.inventory.lenght() < player.inventory.max_items:
|
||||
player.inventory.add_item(item)
|
||||
pickup_animation(player)
|
||||
else :
|
||||
var swaped_item = player.inventory.swap_items(item)
|
||||
item = swaped_item
|
||||
|
||||
return true
|
||||
|
||||
func pickup_animation(player : Player):
|
||||
available = false
|
||||
var tween : Tween = get_tree().create_tween()
|
||||
|
||||
tween.tween_property(self, "position", player.position, 0.2)
|
||||
tween.tween_callback(
|
||||
func():
|
||||
queue_free()
|
||||
)
|
||||
|
||||
func generate_sprite() -> Sprite2D:
|
||||
var s = SPRITE_SCENE.instantiate() as Sprite2D
|
||||
add_child(s)
|
||||
|
||||
s.texture = item.icon
|
||||
|
||||
return s
|
||||
@@ -0,0 +1 @@
|
||||
uid://dedg615xudpoq
|
||||
@@ -1,7 +0,0 @@
|
||||
[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"
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_resource type="Resource" script_class="WaterPlantAction" load_steps=2 format=3 uid="uid://bk0kop0m75pjy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb38yqsd072ws" path="res://entities/interactables/scripts/actions/water_plant.gd" id="1_ghdb0"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ghdb0")
|
||||
metadata/_custom_type_script = "uid://bb38yqsd072ws"
|
||||
@@ -1,8 +0,0 @@
|
||||
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")
|
||||
@@ -1 +0,0 @@
|
||||
uid://j5xvcabrspyb
|
||||
@@ -1,8 +0,0 @@
|
||||
extends InteractableAction
|
||||
class_name WaterPlantAction
|
||||
|
||||
func action(_p: Player, i : Interactable):
|
||||
if i is Plant:
|
||||
i.watered = true
|
||||
else :
|
||||
printerr("No plant selected or interactable is not a plant")
|
||||
@@ -1 +0,0 @@
|
||||
uid://bb38yqsd072ws
|
||||
@@ -1,8 +1,19 @@
|
||||
extends Area2D
|
||||
class_name Interactable
|
||||
|
||||
@export var actions : Array[InteractableAction] = []
|
||||
var available : bool = true
|
||||
|
||||
func interact(p : Player):
|
||||
for a in actions:
|
||||
a.action(p, self)
|
||||
func _ready():
|
||||
printerr("Abstract Interactable class used")
|
||||
|
||||
func interact(_p : Player) -> bool:
|
||||
printerr("Interact function called on abstract Interactable class")
|
||||
return false
|
||||
|
||||
func generate_collision(area_width : float):
|
||||
var collision = CollisionShape2D.new()
|
||||
var collision_shape = CircleShape2D.new()
|
||||
collision_shape.radius = area_width
|
||||
|
||||
collision.shape = collision_shape
|
||||
add_child(collision)
|
||||
@@ -1,6 +0,0 @@
|
||||
# Classe abstraite permettant de développer diverses actions
|
||||
extends Resource
|
||||
class_name InteractableAction
|
||||
|
||||
func action(_p: Player, _i : Interactable):
|
||||
printerr("Méthode action de la classe abstraite InteractableAction appelée")
|
||||
@@ -1 +0,0 @@
|
||||
uid://yutflvdgdk04
|
||||
@@ -1,6 +1,8 @@
|
||||
extends Resource
|
||||
class_name PlantType
|
||||
|
||||
@export var name : String
|
||||
|
||||
@export var growing_time : int
|
||||
|
||||
@export var seed_texture : Texture
|
||||
|
||||
@@ -13,16 +13,16 @@ radius = 40.0
|
||||
script = ExtResource("1_abrql")
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
position = Vector2(2, -20)
|
||||
position = Vector2(2, -55)
|
||||
scale = Vector2(0.084375, 0.084375)
|
||||
texture = ExtResource("1_symyc")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-2, 15)
|
||||
position = Vector2(-2, -20)
|
||||
shape = SubResource("CircleShape2D_sglur")
|
||||
|
||||
[node name="InteractArea2D" type="Area2D" parent="."]
|
||||
position = Vector2(0, 21)
|
||||
position = Vector2(0, -14)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractArea2D"]
|
||||
shape = SubResource("CircleShape2D_abrql")
|
||||
|
||||
@@ -3,14 +3,26 @@ class_name Player
|
||||
|
||||
signal player_updated(player: Player)
|
||||
|
||||
var controlling_player : bool = true
|
||||
var planet : Planet # mis à jour par la classe Planet
|
||||
@export var speed = 400
|
||||
|
||||
@export var testPlantType : PlantType
|
||||
|
||||
@onready var inventory : Inventory = Inventory.new()
|
||||
|
||||
var max_energy : int = 10
|
||||
|
||||
var controlling_player : bool = true :
|
||||
set(v):
|
||||
controlling_player = v
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
var closest_interactable : Interactable = null :
|
||||
set(v):
|
||||
var old = closest_interactable
|
||||
closest_interactable = v
|
||||
if old != closest_interactable:
|
||||
player_updated.emit(self)
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
@@ -29,6 +41,11 @@ func get_input():
|
||||
|
||||
if Input.is_action_just_pressed("action") and energy > 0:
|
||||
action()
|
||||
if Input.is_action_just_pressed("interact") and closest_interactable:
|
||||
closest_interactable.interact(self)
|
||||
if Input.is_action_just_pressed("drop") and inventory.lenght() > 0:
|
||||
var item_to_drop = inventory.pop_item()
|
||||
planet.drop_item(item_to_drop, global_position)
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
@@ -46,9 +63,26 @@ func action():
|
||||
func pass_day():
|
||||
energy = max_energy
|
||||
|
||||
func _physics_process(_delta):
|
||||
func detect_closest_interactable():
|
||||
var in_range_interactables : Array[Interactable] = []
|
||||
for area in $InteractArea2D.get_overlapping_areas():
|
||||
if area is Interactable and area.available:
|
||||
in_range_interactables.append(area)
|
||||
|
||||
in_range_interactables.sort_custom(
|
||||
func(a : Node2D, b : Node2D) :
|
||||
return a.global_position.distance_to(global_position) > b.global_position.distance_to(global_position)
|
||||
)
|
||||
|
||||
if len(in_range_interactables) > 0:
|
||||
closest_interactable = in_range_interactables[0]
|
||||
else :
|
||||
closest_interactable = null
|
||||
|
||||
func _process(_delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
detect_closest_interactable()
|
||||
|
||||
func _on_root_gui_day_pass_pressed():
|
||||
controlling_player = false
|
||||
|
||||
Reference in New Issue
Block a user