init
This commit is contained in:
BIN
interactables/treasure_chest/treasure-chest.png
Normal file
BIN
interactables/treasure_chest/treasure-chest.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
40
interactables/treasure_chest/treasure-chest.png.import
Normal file
40
interactables/treasure_chest/treasure-chest.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://belvmab75wgor"
|
||||
path="res://.godot/imported/treasure-chest.png-6bac5dc046c7950f8613f4ad91682045.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://interactables/treasure_chest/treasure-chest.png"
|
||||
dest_files=["res://.godot/imported/treasure-chest.png-6bac5dc046c7950f8613f4ad91682045.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
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/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
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
|
||||
BIN
interactables/treasure_chest/treasure-open.wav
Normal file
BIN
interactables/treasure_chest/treasure-open.wav
Normal file
Binary file not shown.
24
interactables/treasure_chest/treasure-open.wav.import
Normal file
24
interactables/treasure_chest/treasure-open.wav.import
Normal file
@@ -0,0 +1,24 @@
|
||||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://dq3fm4jon368t"
|
||||
path="res://.godot/imported/treasure-open.wav-ce3a473c1e590530356d5c80459f2325.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://interactables/treasure_chest/treasure-open.wav"
|
||||
dest_files=["res://.godot/imported/treasure-open.wav-ce3a473c1e590530356d5c80459f2325.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=2
|
||||
69
interactables/treasure_chest/treasure_chest.gd
Normal file
69
interactables/treasure_chest/treasure_chest.gd
Normal file
@@ -0,0 +1,69 @@
|
||||
@tool
|
||||
class_name TreasureChest extends Node2D
|
||||
|
||||
@export var item_data: ItemData :
|
||||
set = set_item_data
|
||||
@export var quantity: int = 1 :
|
||||
set = set_quantity
|
||||
|
||||
@onready var item_sprite: Sprite2D = $ItemSprite
|
||||
@onready var label: Label = $ItemSprite/Label
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
@onready var area: Area2D = $Area2D
|
||||
@onready var is_open_save: PersistentDataHandler = $IsOpen
|
||||
|
||||
var is_open := false
|
||||
|
||||
func _ready() -> void:
|
||||
update_texture()
|
||||
update_label()
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
|
||||
area.area_entered.connect(on_area_entered)
|
||||
area.area_exited.connect(on_area_exited)
|
||||
is_open_save.data_loaded.connect(set_chest_state)
|
||||
set_chest_state()
|
||||
|
||||
func set_item_data(new_item_data: ItemData) -> void:
|
||||
item_data = new_item_data
|
||||
update_texture()
|
||||
|
||||
func set_quantity(new_quantity: int) -> void:
|
||||
quantity = new_quantity
|
||||
update_label()
|
||||
|
||||
func on_area_entered(_body: Area2D) -> void:
|
||||
PlayerManager.interact_pressed.connect(on_player_interaction)
|
||||
|
||||
func on_area_exited(_body: Area2D) -> void:
|
||||
PlayerManager.interact_pressed.disconnect(on_player_interaction)
|
||||
|
||||
func on_player_interaction() -> void:
|
||||
if is_open:
|
||||
return
|
||||
is_open = true
|
||||
is_open_save.set_value()
|
||||
animation_player.play("open_chest")
|
||||
if item_data and quantity > 0:
|
||||
PlayerManager.INVENTORY_DATA.add_item(item_data, quantity)
|
||||
else:
|
||||
printerr("Chest has not items")
|
||||
push_error("Chest has not items")
|
||||
|
||||
func update_texture() -> void:
|
||||
if !item_data or !item_sprite:
|
||||
return
|
||||
item_sprite.texture = item_data.texture
|
||||
|
||||
func update_label() -> void:
|
||||
if !label:
|
||||
return
|
||||
label.text = "x%d" % quantity if quantity > 1 else ""
|
||||
|
||||
func set_chest_state() -> void:
|
||||
is_open = is_open_save.value
|
||||
if is_open:
|
||||
animation_player.play("opened")
|
||||
else:
|
||||
animation_player.play("closed")
|
||||
1
interactables/treasure_chest/treasure_chest.gd.uid
Normal file
1
interactables/treasure_chest/treasure_chest.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dj8hud3qb815u
|
||||
247
interactables/treasure_chest/treasure_chest.tscn
Normal file
247
interactables/treasure_chest/treasure_chest.tscn
Normal file
@@ -0,0 +1,247 @@
|
||||
[gd_scene format=3 uid="uid://ca44wdgnsovkt"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dj8hud3qb815u" path="res://interactables/treasure_chest/treasure_chest.gd" id="1_opwty"]
|
||||
[ext_resource type="Texture2D" uid="uid://belvmab75wgor" path="res://interactables/treasure_chest/treasure-chest.png" id="2_rolan"]
|
||||
[ext_resource type="Texture2D" uid="uid://dxf00vjmse6ab" path="res://items/sprites/items.png" id="3_xjfm2"]
|
||||
[ext_resource type="AudioStream" uid="uid://dq3fm4jon368t" path="res://interactables/treasure_chest/treasure-open.wav" id="4_wqj8h"]
|
||||
[ext_resource type="PackedScene" uid="uid://dqwuowiyehr7d" path="res://general/persistent_data/persistent_data_handler.tscn" id="5_5t0pk"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wqj8h"]
|
||||
atlas = ExtResource("3_xjfm2")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_5t0pk"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("ItemSprite:visible")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("ItemSprite:position")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, -8)]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("ItemSprite:modulate")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_0epee"]
|
||||
resource_name = "closed"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("ItemSprite:visible")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [false]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_icwpr"]
|
||||
resource_name = "open_chest"
|
||||
length = 1.5
|
||||
step = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("ItemSprite:visible")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 1,
|
||||
"values": [false, true]
|
||||
}
|
||||
tracks/2/type = "audio"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("AudioStreamPlayer2D")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"clips": [{
|
||||
"end_offset": 0.0,
|
||||
"start_offset": 0.0,
|
||||
"stream": ExtResource("4_wqj8h")
|
||||
}],
|
||||
"times": PackedFloat32Array(0.1)
|
||||
}
|
||||
tracks/2/use_blend = true
|
||||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("ItemSprite:position")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
"times": PackedFloat32Array(0.1, 0.3, 0.5, 1.5),
|
||||
"transitions": PackedFloat32Array(0.5, -2, 2, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, -8), Vector2(0, -48), Vector2(0, -18), Vector2(0, -18)]
|
||||
}
|
||||
tracks/4/type = "value"
|
||||
tracks/4/imported = false
|
||||
tracks/4/enabled = true
|
||||
tracks/4/path = NodePath("ItemSprite:modulate")
|
||||
tracks/4/interp = 1
|
||||
tracks/4/loop_wrap = true
|
||||
tracks/4/keys = {
|
||||
"times": PackedFloat32Array(0.2, 0.3, 0.5, 1, 1.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1), Color(1.353256, 1.353256, 1.353256, 1), Color(1, 1, 1, 1), Color(1.353256, 1.353256, 1.353256, 1), Color(1.353256, 1.353256, 1.353256, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_twix2"]
|
||||
resource_name = "opened"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [1]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("ItemSprite:visible")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [false]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_yw2ot"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_5t0pk"),
|
||||
&"closed": SubResource("Animation_0epee"),
|
||||
&"open_chest": SubResource("Animation_icwpr"),
|
||||
&"opened": SubResource("Animation_twix2")
|
||||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5t0pk"]
|
||||
size = Vector2(32, 16)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_xjfm2"]
|
||||
size = Vector2(48, 26)
|
||||
|
||||
[node name="TreasureChest" type="Node2D" unique_id=477439269]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_opwty")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=521742318]
|
||||
position = Vector2(0, -8)
|
||||
texture = ExtResource("2_rolan")
|
||||
hframes = 2
|
||||
|
||||
[node name="ItemSprite" type="Sprite2D" parent="." unique_id=1824118910]
|
||||
position = Vector2(0, -8)
|
||||
texture = SubResource("AtlasTexture_wqj8h")
|
||||
|
||||
[node name="Label" type="Label" parent="ItemSprite" unique_id=193055326]
|
||||
offset_left = 8.0
|
||||
offset_top = -8.0
|
||||
offset_right = 48.0
|
||||
offset_bottom = 15.0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 4
|
||||
theme_override_font_sizes/font_size = 10
|
||||
text = "x99"
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=629460590]
|
||||
libraries/ = SubResource("AnimationLibrary_yw2ot")
|
||||
autoplay = &"closed"
|
||||
|
||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="." unique_id=54490691]
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=1307513908]
|
||||
collision_layer = 16
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1422331012]
|
||||
position = Vector2(0, 8)
|
||||
shape = SubResource("RectangleShape2D_5t0pk")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="." unique_id=572471651]
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=145918165]
|
||||
position = Vector2(0, 8)
|
||||
shape = SubResource("RectangleShape2D_xjfm2")
|
||||
debug_color = Color(5.583167e-06, 0.6433983, 0.3063715, 0.41960785)
|
||||
|
||||
[node name="IsOpen" parent="." unique_id=2132709116 instance=ExtResource("5_5t0pk")]
|
||||
Reference in New Issue
Block a user