From 68b7c1a298d112d3002e6b94fa07f9d7de2b22d1 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 17 Sep 2025 12:17:32 +0200 Subject: [PATCH 1/3] Added ItemSpawn --- buildings/Building 1x2 fixed.png.import | 6 ++++ buildings/Building 2x1 downside.png.import | 6 ++++ buildings/Building 2x1 fixed.png.import | 6 ++++ items/item_spawn.gd | 34 ++++++++++++++++++++++ items/item_spawn.gd.uid | 1 + items/item_spawn.tscn | 7 +++++ player/Player_Walk/Walk 1.png.import | 6 ++++ player/Player_Walk/Walk 2.png.import | 6 ++++ player/Player_Walk/Walk 3.png.import | 6 ++++ player/Player_Walk/Walk 4.png.import | 6 ++++ player/Player_Walk/Walk 5.png.import | 6 ++++ player/Player_Walk/Walk 6.png.import | 6 ++++ project.godot | 2 +- 13 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 items/item_spawn.gd create mode 100644 items/item_spawn.gd.uid create mode 100644 items/item_spawn.tscn diff --git a/buildings/Building 1x2 fixed.png.import b/buildings/Building 1x2 fixed.png.import index 0ac93ca..39a81c9 100644 --- a/buildings/Building 1x2 fixed.png.import +++ b/buildings/Building 1x2 fixed.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Building 1x2 fixed.png-e90afc0d25a8919ada5700 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 @@ -25,6 +27,10 @@ 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 diff --git a/buildings/Building 2x1 downside.png.import b/buildings/Building 2x1 downside.png.import index 52d9ce5..0e57d53 100644 --- a/buildings/Building 2x1 downside.png.import +++ b/buildings/Building 2x1 downside.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Building 2x1 downside.png-4b432eb4152bab7dd59 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 @@ -25,6 +27,10 @@ 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 diff --git a/buildings/Building 2x1 fixed.png.import b/buildings/Building 2x1 fixed.png.import index a78eae3..e7fdbe6 100644 --- a/buildings/Building 2x1 fixed.png.import +++ b/buildings/Building 2x1 fixed.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Building 2x1 fixed.png-b02748fa52aebae62f987c 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 @@ -25,6 +27,10 @@ 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 diff --git a/items/item_spawn.gd b/items/item_spawn.gd new file mode 100644 index 0000000..fb093b8 --- /dev/null +++ b/items/item_spawn.gd @@ -0,0 +1,34 @@ +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(): + 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: + remove_after_spawn = true + return unique_items + elif random < unique_chance + rare_chance || guarantee_rare: + return rare_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()) + 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..2951808 --- /dev/null +++ b/items/item_spawn.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://xj0of571aur1"] + +[ext_resource type="Script" uid="uid://b8em61mqgdi58" path="res://items/item_spawn.gd" id="1_ms6tn"] + +[node name="ItemSpawn" type="Node2D"] +script = ExtResource("1_ms6tn") +metadata/_custom_type_script = "uid://b8em61mqgdi58" diff --git a/player/Player_Walk/Walk 1.png.import b/player/Player_Walk/Walk 1.png.import index 97cf918..7803358 100644 --- a/player/Player_Walk/Walk 1.png.import +++ b/player/Player_Walk/Walk 1.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 1.png-47c623e9d3540b4a00d2bddf52ae0b2a.c 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 @@ -25,6 +27,10 @@ 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 diff --git a/player/Player_Walk/Walk 2.png.import b/player/Player_Walk/Walk 2.png.import index 48f18ef..3fac54f 100644 --- a/player/Player_Walk/Walk 2.png.import +++ b/player/Player_Walk/Walk 2.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 2.png-5dea4fdec55fa43e26680e08090fd654.c 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 @@ -25,6 +27,10 @@ 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 diff --git a/player/Player_Walk/Walk 3.png.import b/player/Player_Walk/Walk 3.png.import index 285ace3..c65053d 100644 --- a/player/Player_Walk/Walk 3.png.import +++ b/player/Player_Walk/Walk 3.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 3.png-27890c0cb512383b8ecbd848c73efee1.c 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 @@ -25,6 +27,10 @@ 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 diff --git a/player/Player_Walk/Walk 4.png.import b/player/Player_Walk/Walk 4.png.import index 03aa90d..c12f6b8 100644 --- a/player/Player_Walk/Walk 4.png.import +++ b/player/Player_Walk/Walk 4.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 4.png-232b1eae2acf3ad82130431014262cde.c 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 @@ -25,6 +27,10 @@ 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 diff --git a/player/Player_Walk/Walk 5.png.import b/player/Player_Walk/Walk 5.png.import index fe3ebef..47122be 100644 --- a/player/Player_Walk/Walk 5.png.import +++ b/player/Player_Walk/Walk 5.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 5.png-cfb8eb15ace876127c083283fe74cdc0.c 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 @@ -25,6 +27,10 @@ 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 diff --git a/player/Player_Walk/Walk 6.png.import b/player/Player_Walk/Walk 6.png.import index 22d7868..5b2bdef 100644 --- a/player/Player_Walk/Walk 6.png.import +++ b/player/Player_Walk/Walk 6.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 6.png-f243f98e182be67eb8681a11d34ee554.c 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 @@ -25,6 +27,10 @@ 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 diff --git a/project.godot b/project.godot index 4184826..035e24c 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="The Dark Side of Earth" run/main_scene="uid://cxo6bq26huau7" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.5", "Forward Plus") config/icon="res://icon.svg" [display] From 5fe2772097d868819ff40a46e15a4a5eaa1a7e40 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 17 Sep 2025 12:37:09 +0200 Subject: [PATCH 2/3] 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"] From bb0fda15d46910f2942b1ca60e29cf68d45c3ecd Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 17 Sep 2025 12:53:16 +0200 Subject: [PATCH 3/3] Fixed Item Alignment --- buildings/building.gdshader | 2 +- items/heal_item.tscn | 5 ++++- items/item_spawn.gd | 2 +- utils/earth_aligner.gd | 4 ++++ utils/earth_aligner.tscn | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/buildings/building.gdshader b/buildings/building.gdshader index 4463040..4c7f0f6 100644 --- a/buildings/building.gdshader +++ b/buildings/building.gdshader @@ -14,7 +14,7 @@ void vertex() location = ivec2(128. * COLOR.xy); dimension = ivec2(128. * COLOR.zw); - vec2 myloc = vec2(location) + UV * (vec2(dimension) + vec2(0., .5)); + vec2 myloc = vec2(location) + UV * (vec2(dimension) + vec2(0., .7)) - vec2(0, .2); float angle = float(myloc.x) * TAU / 60.; float height = float(myloc.y) * cell_height + ground_height; VERTEX = vec2(cos(angle), sin(angle)) * height; diff --git a/items/heal_item.tscn b/items/heal_item.tscn index 5eb8954..ed70383 100644 --- a/items/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://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/items/item_spawn.gd b/items/item_spawn.gd index 2a8aadd..af9d37a 100644 --- a/items/item_spawn.gd +++ b/items/item_spawn.gd @@ -34,5 +34,5 @@ func _ready(): pool.remove_at(index) var object = packed_scene.instantiate() add_child.call_deferred(object) - object.reparent(get_parent()) + object.reparent.call_deferred(get_parent()) 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")