feat: add a chest node; add logic for random scroll in the chest; add a timer t hide the scroll after;

This commit is contained in:
2026-09-20 16:06:58 +02:00
parent d8d342ab56
commit fc007ca71a
6 changed files with 253 additions and 135 deletions
+23
View File
@@ -0,0 +1,23 @@
extends StaticBody2D
var can_interact: bool = false
var is_open: bool = false
@export var scrolls: Array[Sprite2D]
var scroll_number = 0
func _ready() -> void:
scroll_number = randi_range(1, 4)
func _process(delta: float) -> void:
if Input.is_action_just_pressed("Interact") and can_interact:
if !is_open:
$AudioStreamPlayer.play()
$AnimatedSprite2D.play("open")
scrolls[scroll_number].visible = true
$Timer.start()
is_open = true
func _on_timer_timeout(scroll_number: int) -> void:
scrolls[scroll_number].visible = false
@@ -0,0 +1 @@
uid://h2y2p3dcj4ne
+85
View File
@@ -0,0 +1,85 @@
[gd_scene format=3 uid="uid://bqcsg2t581j7b"]
[ext_resource type="Script" uid="uid://h2y2p3dcj4ne" path="res://Scenes/TreasureChest/treasure_chest.gd" id="1_2tkyh"]
[ext_resource type="Texture2D" uid="uid://crewi6wldd7od" path="res://Ninja Adventure - Asset Pack/Items/Treasure/BigTreasureChest.png" id="1_v1qrq"]
[ext_resource type="AudioStream" uid="uid://ug5n4ca2cc77" path="res://Ninja Adventure - Asset Pack/Sounds/Game/Success3.wav" id="3_sdjdt"]
[ext_resource type="Texture2D" uid="uid://fybqrl1dbdao" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollIce.png" id="4_vnph0"]
[ext_resource type="Texture2D" uid="uid://c1coi2k1hgv5b" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollFire.png" id="5_2b3qj"]
[ext_resource type="Texture2D" uid="uid://d1his3w8n84aa" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollPlant.png" id="6_n2as5"]
[ext_resource type="Texture2D" uid="uid://d1vovcdepn1w5" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollRock.png" id="7_lh1s0"]
[ext_resource type="Texture2D" uid="uid://6dmy1j0t5mqy" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollEmpty.png" id="8_lh1s0"]
[sub_resource type="AtlasTexture" id="AtlasTexture_2tkyh"]
atlas = ExtResource("1_v1qrq")
region = Rect2(0, 0, 16, 14)
[sub_resource type="AtlasTexture" id="AtlasTexture_sdjdt"]
atlas = ExtResource("1_v1qrq")
region = Rect2(16, 0, 16, 14)
[sub_resource type="SpriteFrames" id="SpriteFrames_chgu2"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_2tkyh")
}],
"loop": 1,
"name": &"closed",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_sdjdt")
}],
"loop": 1,
"name": &"open",
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_chgu2"]
size = Vector2(16, 12)
[node name="TreasureChest" type="StaticBody2D" unique_id=2069908436 node_paths=PackedStringArray("scrolls") groups=["interactable"]]
script = ExtResource("1_2tkyh")
scrolls = [NodePath("EmptyScroll"), NodePath("IceScroll"), NodePath("FireScroll"), NodePath("PlantScroll"), NodePath("RockScroll")]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=990575183]
sprite_frames = SubResource("SpriteFrames_chgu2")
animation = &"open"
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=104658718]
position = Vector2(0, 1)
shape = SubResource("RectangleShape2D_chgu2")
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="." unique_id=1922945704]
stream = ExtResource("3_sdjdt")
[node name="IceScroll" type="Sprite2D" parent="." unique_id=1614825692]
visible = false
position = Vector2(0, -13)
texture = ExtResource("4_vnph0")
[node name="FireScroll" type="Sprite2D" parent="." unique_id=55522702]
visible = false
position = Vector2(0, -13)
texture = ExtResource("5_2b3qj")
[node name="PlantScroll" type="Sprite2D" parent="." unique_id=1806015749]
visible = false
position = Vector2(0, -13)
texture = ExtResource("6_n2as5")
[node name="RockScroll" type="Sprite2D" parent="." unique_id=1276385957]
visible = false
position = Vector2(0, -13)
texture = ExtResource("7_lh1s0")
[node name="Timer" type="Timer" parent="." unique_id=647285700]
one_shot = true
[node name="EmptyScroll" type="Sprite2D" parent="." unique_id=699932407]
visible = false
position = Vector2(0, -13)
texture = ExtResource("8_lh1s0")
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]