#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
|
||||
Reference in New Issue
Block a user