From 5fe2772097d868819ff40a46e15a4a5eaa1a7e40 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 17 Sep 2025 12:37:09 +0200 Subject: [PATCH] Intergrated ItemSpawn into the game --- buildings/building.tscn | 6 +++++- heal_item.gd => items/heal_item.gd | 0 heal_item.gd.uid => items/heal_item.gd.uid | 0 heal_item.tscn => items/heal_item.tscn | 2 +- item.gd => items/item.gd | 0 item.gd.uid => items/item.gd.uid | 0 items/item_spawn.gd | 10 +++++++--- items/item_spawn.tscn | 9 ++++++++- main.tscn | 2 +- 9 files changed, 22 insertions(+), 7 deletions(-) rename heal_item.gd => items/heal_item.gd (100%) rename heal_item.gd.uid => items/heal_item.gd.uid (100%) rename heal_item.tscn => items/heal_item.tscn (94%) rename item.gd => items/item.gd (100%) rename item.gd.uid => items/item.gd.uid (100%) diff --git a/buildings/building.tscn b/buildings/building.tscn index c91c395..8b7e604 100644 --- a/buildings/building.tscn +++ b/buildings/building.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://djawvtdwp423v"] +[gd_scene load_steps=11 format=3 uid="uid://djawvtdwp423v"] [ext_resource type="Script" uid="uid://b2ji03ekijjnn" path="res://buildings/building.gd" id="1_5j34s"] [ext_resource type="Shader" uid="uid://c7gb1nqwvkr37" path="res://buildings/building.gdshader" id="2_xx8ra"] @@ -8,6 +8,7 @@ [ext_resource type="PackedScene" uid="uid://dpv1w56yr1xue" path="res://traps/morning_star.tscn" id="5_xr4t5"] [ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="7_35wcg"] [ext_resource type="PackedScene" uid="uid://4l3elvxpghw8" path="res://platform.tscn" id="8_sifiv"] +[ext_resource type="PackedScene" uid="uid://xj0of571aur1" path="res://items/item_spawn.tscn" id="9_i1qmw"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_pfkkr"] shader = ExtResource("2_xx8ra") @@ -59,6 +60,9 @@ position = Vector2(525, -285) position = Vector2(300, -150) scale = Vector2(2.688, 3) +[node name="ItemSpawn" parent="EnemyList" instance=ExtResource("9_i1qmw")] +position = Vector2(300, -200) + [node name="DebugSprite" type="Sprite2D" parent="."] visible = false position = Vector2(300, -150) diff --git a/heal_item.gd b/items/heal_item.gd similarity index 100% rename from heal_item.gd rename to items/heal_item.gd diff --git a/heal_item.gd.uid b/items/heal_item.gd.uid similarity index 100% rename from heal_item.gd.uid rename to items/heal_item.gd.uid diff --git a/heal_item.tscn b/items/heal_item.tscn similarity index 94% rename from heal_item.tscn rename to items/heal_item.tscn index 5b50b0e..5eb8954 100644 --- a/heal_item.tscn +++ b/items/heal_item.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://b00185vygcka1"] -[ext_resource type="Script" uid="uid://b43fudwi47qfd" path="res://heal_item.gd" id="1_3vbv8"] +[ext_resource type="Script" uid="uid://b43fudwi47qfd" path="res://items/heal_item.gd" id="1_3vbv8"] [ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_48lih"] [sub_resource type="CircleShape2D" id="CircleShape2D_hvhjo"] diff --git a/item.gd b/items/item.gd similarity index 100% rename from item.gd rename to items/item.gd diff --git a/item.gd.uid b/items/item.gd.uid similarity index 100% rename from item.gd.uid rename to items/item.gd.uid diff --git a/items/item_spawn.gd b/items/item_spawn.gd index fb093b8..2a8aadd 100644 --- a/items/item_spawn.gd +++ b/items/item_spawn.gd @@ -14,21 +14,25 @@ class_name ItemSpawn extends Node2D var remove_after_spawn = false -func choose_pool(): +func choose_pool() -> Array[PackedScene]: var unique_chance = unique_base_chance + unique_bonus_multiplier * rarity_bonus var rare_chance = unique_base_chance + unique_bonus_multiplier * rarity_bonus var random = randf() - if random < unique_chance: + if random < unique_chance && unique_items.size() > 0: remove_after_spawn = true return unique_items elif random < unique_chance + rare_chance || guarantee_rare: return rare_items + return common_items + func _ready(): var pool = choose_pool() var index = randi_range(0, pool.size() - 1) var packed_scene : PackedScene = pool[index] pool.remove_at(index) - add_sibling(packed_scene.instantiate()) + var object = packed_scene.instantiate() + add_child.call_deferred(object) + object.reparent(get_parent()) diff --git a/items/item_spawn.tscn b/items/item_spawn.tscn index 2951808..3956358 100644 --- a/items/item_spawn.tscn +++ b/items/item_spawn.tscn @@ -1,7 +1,14 @@ -[gd_scene load_steps=2 format=3 uid="uid://xj0of571aur1"] +[gd_scene load_steps=4 format=3 uid="uid://xj0of571aur1"] [ext_resource type="Script" uid="uid://b8em61mqgdi58" path="res://items/item_spawn.gd" id="1_ms6tn"] +[ext_resource type="PackedScene" uid="uid://b00185vygcka1" path="res://items/heal_item.tscn" id="2_w6i8k"] +[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://utils/earth_aligner.tscn" id="3_5pwuf"] [node name="ItemSpawn" type="Node2D"] script = ExtResource("1_ms6tn") +common_items = Array[PackedScene]([ExtResource("2_w6i8k")]) +rare_items = Array[PackedScene]([ExtResource("2_w6i8k")]) +unique_items = Array[PackedScene]([ExtResource("2_w6i8k")]) metadata/_custom_type_script = "uid://b8em61mqgdi58" + +[node name="EarthAligner" parent="." instance=ExtResource("3_5pwuf")] diff --git a/main.tscn b/main.tscn index 650e5b9..0c386ab 100644 --- a/main.tscn +++ b/main.tscn @@ -7,7 +7,7 @@ [ext_resource type="PackedScene" uid="uid://cjsrtswk4vgf2" path="res://healthbar/healthbar.tscn" id="6_7mycd"] [ext_resource type="PackedScene" uid="uid://dpdn2php3ydsv" path="res://death_screen/death_screen.tscn" id="7_5vw27"] [ext_resource type="PackedScene" uid="uid://4l3elvxpghw8" path="res://platform.tscn" id="7_272bh"] -[ext_resource type="PackedScene" uid="uid://b00185vygcka1" path="res://heal_item.tscn" id="8_5vw27"] +[ext_resource type="PackedScene" uid="uid://b00185vygcka1" path="res://items/heal_item.tscn" id="8_5vw27"] [ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="9_kek77"] [node name="main" type="Node2D"]