From 4be01c1aa15c05544456d6fcc7a0699279dc8c18 Mon Sep 17 00:00:00 2001 From: RealMelwei Date: Wed, 17 Sep 2025 12:57:04 +0200 Subject: [PATCH 1/2] Added Active Items, an Updash Item and the possibility for items to not be immediately connected --- active_item.gd | 7 +++++++ active_item.gd.uid | 1 + heal_item.gd | 4 +++- item.gd | 11 +++++------ main.tscn | 8 ++++---- player/player.gd | 10 ++++++++++ project.godot | 5 +++++ updash.gd | 9 +++++++++ updash.gd.uid | 1 + updash.tscn | 18 ++++++++++++++++++ 10 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 active_item.gd create mode 100644 active_item.gd.uid create mode 100644 updash.gd create mode 100644 updash.gd.uid create mode 100644 updash.tscn diff --git a/active_item.gd b/active_item.gd new file mode 100644 index 0000000..2d7d09b --- /dev/null +++ b/active_item.gd @@ -0,0 +1,7 @@ +class_name ActiveItem extends Item + +func collect() -> bool: + if (player.active_item == null): + player.active_item = self + return true + return false diff --git a/active_item.gd.uid b/active_item.gd.uid new file mode 100644 index 0000000..2f67e05 --- /dev/null +++ b/active_item.gd.uid @@ -0,0 +1 @@ +uid://dyu8r5dt6qk8k diff --git a/heal_item.gd b/heal_item.gd index 9ba04b5..d4d63cf 100644 --- a/heal_item.gd +++ b/heal_item.gd @@ -1,6 +1,8 @@ extends Item @export var heal_amount = 1 -func collect(): +func collect() -> bool: if(player.current_hp < player.max_hp): player.current_hp += heal_amount + return true + return false diff --git a/item.gd b/item.gd index 8457022..befe8ab 100644 --- a/item.gd +++ b/item.gd @@ -6,12 +6,11 @@ func _ready() -> void: func _on_body_entered(body: Node2D): if(body.name == "Player"): - set_deferred("monitoring", false) - set_deferred("monitorable", false) - call_deferred("reparent", player) - collect_animation() - if(self.has_method("collect")): - collect() + if(self.has_method("collect") and collect()): + set_deferred("monitoring", false) + set_deferred("monitorable", false) + call_deferred("reparent", player) + collect_animation() func collect_animation(): self.visible = false diff --git a/main.tscn b/main.tscn index 650e5b9..de87209 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://ennu3lalstdr" path="res://updash.tscn" id="9_4c57u"] [ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="9_kek77"] [node name="main" type="Node2D"] @@ -49,12 +49,12 @@ visible = false position = Vector2(900, -3000) scale = Vector2(5, 3.1) -[node name="HealItem" parent="." instance=ExtResource("8_5vw27")] -position = Vector2(0, -3150) - [node name="Ghost" parent="." instance=ExtResource("9_kek77")] position = Vector2(0, -3000) +[node name="Updash" parent="." instance=ExtResource("9_4c57u")] +position = Vector2(0, -3100) + [connection signal="health_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_health_changed"] [connection signal="player_died" from="Player" to="CanvasLayer/DeathScreen" method="_on_player_player_died"] [connection signal="timeout" from="Building Generator/Timer" to="Building Generator" method="_on_timer_timeout"] diff --git a/player/player.gd b/player/player.gd index 385b4b0..0193ec2 100644 --- a/player/player.gd +++ b/player/player.gd @@ -42,9 +42,14 @@ var damage_knockup = 500 var atk_cooldown = 0.5 var atk_timer = 0 +# Active Item +var active_item = null +var item_cooldown = 0 + func _physics_process(delta: float) -> void: manage_iframes(delta) manage_movement_options() + manage_active(delta) manage_animation() manage_attack(delta) manage_velocity(delta) @@ -61,6 +66,11 @@ func manage_attack(delta : float): sword.swing() atk_timer = atk_cooldown +func manage_active(delta : float): + item_cooldown = max(item_cooldown - delta, 0) + if(active_item != null and Input.is_action_just_pressed("item") and item_cooldown <= 0): + active_item.activate() + func manage_movement_options() -> void: if(is_on_floor()): air_jumps_current = air_jumps_max diff --git a/project.godot b/project.godot index 4184826..6f8803f 100644 --- a/project.godot +++ b/project.godot @@ -48,6 +48,11 @@ drop={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +item={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) +] +} [layer_names] diff --git a/updash.gd b/updash.gd new file mode 100644 index 0000000..09b04b7 --- /dev/null +++ b/updash.gd @@ -0,0 +1,9 @@ +extends ActiveItem +var cooldown = 10 + + +func activate(): + player.item_cooldown = cooldown + player.reset_to_velocity = Vector2(0,1) + await get_tree().create_timer(0.1).timeout + player.reset_to_velocity = Vector2(0, -2400) diff --git a/updash.gd.uid b/updash.gd.uid new file mode 100644 index 0000000..8f1a1ff --- /dev/null +++ b/updash.gd.uid @@ -0,0 +1 @@ +uid://bbwsc2a2hd0ow diff --git a/updash.tscn b/updash.tscn new file mode 100644 index 0000000..aa9ab7c --- /dev/null +++ b/updash.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=3 uid="uid://ennu3lalstdr"] + +[ext_resource type="Script" uid="uid://bbwsc2a2hd0ow" path="res://updash.gd" id="1_ghbl6"] +[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_ptc3l"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_ghbl6"] + +[node name="Updash" type="Area2D"] +script = ExtResource("1_ghbl6") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +scale = Vector2(3, 3) +shape = SubResource("CircleShape2D_ghbl6") + +[node name="Sprite2D" type="Sprite2D" parent="."] +modulate = Color(1, 0, 1, 1) +scale = Vector2(0.45, 0.45) +texture = ExtResource("1_ptc3l") From 40217226b9c84bcb627a4197f769914fe002bd52 Mon Sep 17 00:00:00 2001 From: RealMelwei Date: Wed, 17 Sep 2025 14:03:37 +0200 Subject: [PATCH 2/2] Fixed Heal Item, added Healthup Item, Folder structure improvements --- buildings/building.tscn | 4 ++-- buildings/haunted_house.tscn | 2 +- active_item.gd => items/active_item.gd | 0 .../active_item.gd.uid | 0 items/heal_item.gd | 2 +- items/healthup.gd | 8 +++++++ items/healthup.gd.uid | 1 + items/healthup.tscn | 21 +++++++++++++++++++ updash.gd => items/updash.gd | 0 updash.gd.uid => items/updash.gd.uid | 0 updash.tscn => items/updash.tscn | 4 ++-- main.tscn | 6 +++--- platform.gd => utils/platform.gd | 0 platform.gd.uid => utils/platform.gd.uid | 0 platform.tscn => utils/platform.tscn | 2 +- 15 files changed, 40 insertions(+), 10 deletions(-) rename active_item.gd => items/active_item.gd (100%) rename active_item.gd.uid => items/active_item.gd.uid (100%) create mode 100644 items/healthup.gd create mode 100644 items/healthup.gd.uid create mode 100644 items/healthup.tscn rename updash.gd => items/updash.gd (100%) rename updash.gd.uid => items/updash.gd.uid (100%) rename updash.tscn => items/updash.tscn (86%) rename platform.gd => utils/platform.gd (100%) rename platform.gd.uid => utils/platform.gd.uid (100%) rename platform.tscn => utils/platform.tscn (96%) diff --git a/buildings/building.tscn b/buildings/building.tscn index 8b7e604..1b058c7 100644 --- a/buildings/building.tscn +++ b/buildings/building.tscn @@ -7,7 +7,7 @@ [ext_resource type="Texture2D" uid="uid://3weywjfsapax" path="res://buildings/Building 2x1 downside.png" id="5_pfkkr"] [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://4l3elvxpghw8" path="res://utils/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"] @@ -16,7 +16,7 @@ shader_parameter/ground_height = 3000.0 shader_parameter/cell_height = 300.0 shader_parameter/num_cells = 60 -[node name="Building" type="Node2D"] +[node name="Building2" type="Node2D"] script = ExtResource("1_5j34s") [node name="Sprite2D" type="Sprite2D" parent="."] diff --git a/buildings/haunted_house.tscn b/buildings/haunted_house.tscn index 69315b2..c77c51a 100644 --- a/buildings/haunted_house.tscn +++ b/buildings/haunted_house.tscn @@ -5,7 +5,7 @@ [ext_resource type="Texture2D" uid="uid://djir4ehm8kif" path="res://buildings/Building 1x2 fixed.png" id="3_uv7v8"] [ext_resource type="Script" uid="uid://dj7d4d2xs3nci" path="res://buildings/building_mesh.gd" id="4_bl5jt"] [ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="5_23fi7"] -[ext_resource type="PackedScene" uid="uid://4l3elvxpghw8" path="res://platform.tscn" id="6_e6j05"] +[ext_resource type="PackedScene" uid="uid://4l3elvxpghw8" path="res://utils/platform.tscn" id="6_e6j05"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_qnfc1"] resource_local_to_scene = true diff --git a/active_item.gd b/items/active_item.gd similarity index 100% rename from active_item.gd rename to items/active_item.gd diff --git a/active_item.gd.uid b/items/active_item.gd.uid similarity index 100% rename from active_item.gd.uid rename to items/active_item.gd.uid diff --git a/items/heal_item.gd b/items/heal_item.gd index d4d63cf..c7eee45 100644 --- a/items/heal_item.gd +++ b/items/heal_item.gd @@ -3,6 +3,6 @@ extends Item func collect() -> bool: if(player.current_hp < player.max_hp): - player.current_hp += heal_amount + player.current_hp = min(player.max_hp, player.current_hp + heal_amount) return true return false diff --git a/items/healthup.gd b/items/healthup.gd new file mode 100644 index 0000000..ac890d0 --- /dev/null +++ b/items/healthup.gd @@ -0,0 +1,8 @@ +extends Item +@export var heal_amount = 1 +@export var max_health_increase = 1 + +func collect() -> bool: + player.max_hp += max_health_increase + player.current_hp = min(player.max_hp, player.current_hp + heal_amount) + return true diff --git a/items/healthup.gd.uid b/items/healthup.gd.uid new file mode 100644 index 0000000..2bc8c3e --- /dev/null +++ b/items/healthup.gd.uid @@ -0,0 +1 @@ +uid://ce6fxbjarlvtk diff --git a/items/healthup.tscn b/items/healthup.tscn new file mode 100644 index 0000000..c97dec2 --- /dev/null +++ b/items/healthup.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=5 format=3 uid="uid://gwctb2xqsbj"] + +[ext_resource type="Script" uid="uid://ce6fxbjarlvtk" path="res://items/healthup.gd" id="1_ivtxh"] +[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://utils/earth_aligner.tscn" id="2_lolop"] +[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="3_v056v"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_hvhjo"] + +[node name="HealthUp" type="Area2D"] +scale = Vector2(1, -1) +script = ExtResource("1_ivtxh") + +[node name="EarthAligner" parent="." instance=ExtResource("2_lolop")] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +scale = Vector2(7, 7) +shape = SubResource("CircleShape2D_hvhjo") + +[node name="Sprite2D" type="Sprite2D" parent="."] +modulate = Color(1, 1, 0, 1) +texture = ExtResource("3_v056v") diff --git a/updash.gd b/items/updash.gd similarity index 100% rename from updash.gd rename to items/updash.gd diff --git a/updash.gd.uid b/items/updash.gd.uid similarity index 100% rename from updash.gd.uid rename to items/updash.gd.uid diff --git a/updash.tscn b/items/updash.tscn similarity index 86% rename from updash.tscn rename to items/updash.tscn index aa9ab7c..799aa98 100644 --- a/updash.tscn +++ b/items/updash.tscn @@ -1,6 +1,6 @@ -[gd_scene load_steps=4 format=3 uid="uid://ennu3lalstdr"] +[gd_scene load_steps=4 format=3 uid="uid://ewe36lqcjojk"] -[ext_resource type="Script" uid="uid://bbwsc2a2hd0ow" path="res://updash.gd" id="1_ghbl6"] +[ext_resource type="Script" uid="uid://bbwsc2a2hd0ow" path="res://items/updash.gd" id="1_ghbl6"] [ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_ptc3l"] [sub_resource type="CircleShape2D" id="CircleShape2D_ghbl6"] diff --git a/main.tscn b/main.tscn index de87209..a0394c8 100644 --- a/main.tscn +++ b/main.tscn @@ -6,8 +6,8 @@ [ext_resource type="Script" uid="uid://colvx6wq0e8n7" path="res://world/building_generator.gd" id="4_1bvp3"] [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://ennu3lalstdr" path="res://updash.tscn" id="9_4c57u"] +[ext_resource type="PackedScene" uid="uid://4l3elvxpghw8" path="res://utils/platform.tscn" id="7_272bh"] +[ext_resource type="PackedScene" uid="uid://gwctb2xqsbj" path="res://items/healthup.tscn" id="9_4c57u"] [ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://enemies/ghost.tscn" id="9_kek77"] [node name="main" type="Node2D"] @@ -52,7 +52,7 @@ scale = Vector2(5, 3.1) [node name="Ghost" parent="." instance=ExtResource("9_kek77")] position = Vector2(0, -3000) -[node name="Updash" parent="." instance=ExtResource("9_4c57u")] +[node name="HealthUp" parent="." instance=ExtResource("9_4c57u")] position = Vector2(0, -3100) [connection signal="health_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_health_changed"] diff --git a/platform.gd b/utils/platform.gd similarity index 100% rename from platform.gd rename to utils/platform.gd diff --git a/platform.gd.uid b/utils/platform.gd.uid similarity index 100% rename from platform.gd.uid rename to utils/platform.gd.uid diff --git a/platform.tscn b/utils/platform.tscn similarity index 96% rename from platform.tscn rename to utils/platform.tscn index 586dd28..6757013 100644 --- a/platform.tscn +++ b/utils/platform.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://4l3elvxpghw8"] -[ext_resource type="Script" uid="uid://dwmquoam37sve" path="res://platform.gd" id="1_c1gtx"] +[ext_resource type="Script" uid="uid://dwmquoam37sve" path="res://utils/platform.gd" id="1_c1gtx"] [ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_s8bxr"] [ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://utils/earth_aligner.tscn" id="2_c1gtx"]