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 65% rename from heal_item.tscn rename to items/heal_item.tscn index 5b50b0e..ed70383 100644 --- a/heal_item.tscn +++ b/items/heal_item.tscn @@ -1,13 +1,16 @@ -[gd_scene load_steps=4 format=3 uid="uid://b00185vygcka1"] +[gd_scene load_steps=5 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"] +[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://utils/earth_aligner.tscn" id="2_evqwq"] [sub_resource type="CircleShape2D" id="CircleShape2D_hvhjo"] [node name="HealItem" type="Area2D"] script = ExtResource("1_3vbv8") +[node name="EarthAligner" parent="." instance=ExtResource("2_evqwq")] + [node name="CollisionShape2D" type="CollisionShape2D" parent="."] scale = Vector2(7, 7) shape = SubResource("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 new file mode 100644 index 0000000..af9d37a --- /dev/null +++ b/items/item_spawn.gd @@ -0,0 +1,38 @@ +class_name ItemSpawn extends Node2D + +@export var common_items : Array[PackedScene] +@export var rare_items : Array[PackedScene] +@export var unique_items : Array[PackedScene] + +@export var rarity_bonus = 0 +@export var guarantee_rare : bool = false + +@export var unique_base_chance = .05 +@export var rare_base_chance = .2 +@export var unique_bonus_multiplier = .025 +@export var rare_bonus_multiplier = .1 + +var remove_after_spawn = false + +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 && 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) + var object = packed_scene.instantiate() + add_child.call_deferred(object) + object.reparent.call_deferred(get_parent()) + diff --git a/items/item_spawn.gd.uid b/items/item_spawn.gd.uid new file mode 100644 index 0000000..fbdc0ee --- /dev/null +++ b/items/item_spawn.gd.uid @@ -0,0 +1 @@ +uid://b8em61mqgdi58 diff --git a/items/item_spawn.tscn b/items/item_spawn.tscn new file mode 100644 index 0000000..3956358 --- /dev/null +++ b/items/item_spawn.tscn @@ -0,0 +1,14 @@ +[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/utils/earth_aligner.gd b/utils/earth_aligner.gd index 547efde..94cb1e0 100644 --- a/utils/earth_aligner.gd +++ b/utils/earth_aligner.gd @@ -6,8 +6,12 @@ var angle = 0 func _ready() -> void: parent = get_parent() + align() func _physics_process(_delta: float) -> void: + align() + +func align(): angle = -(parent.position - center).angle_to(Vector2.UP) parent.rotation = angle; diff --git a/utils/earth_aligner.tscn b/utils/earth_aligner.tscn index 57687e9..bc5a15d 100644 --- a/utils/earth_aligner.tscn +++ b/utils/earth_aligner.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://chs0u61f45nau"] -[ext_resource type="Script" uid="uid://ciehyjlxjvrvb" path="res://earth_aligner.gd" id="1_sx2xq"] +[ext_resource type="Script" uid="uid://ciehyjlxjvrvb" path="res://utils/earth_aligner.gd" id="1_sx2xq"] [node name="EarthAligner" type="Node2D"] script = ExtResource("1_sx2xq")