From f19bda7886cdb4e1609f9c5026f52e0234d91dc1 Mon Sep 17 00:00:00 2001 From: RealMelwei Date: Wed, 17 Sep 2025 12:19:19 +0200 Subject: [PATCH] Fixed platform drop, added heal item --- heal_item.gd | 6 ++++++ heal_item.gd.uid | 1 + heal_item.tscn | 17 +++++++++++++++++ item.gd | 20 ++++++++++++++++++++ item.gd.uid | 1 + main.tscn | 10 +++++++++- player/player.gd | 3 +-- 7 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 heal_item.gd create mode 100644 heal_item.gd.uid create mode 100644 heal_item.tscn create mode 100644 item.gd create mode 100644 item.gd.uid diff --git a/heal_item.gd b/heal_item.gd new file mode 100644 index 0000000..9ba04b5 --- /dev/null +++ b/heal_item.gd @@ -0,0 +1,6 @@ +extends Item +@export var heal_amount = 1 + +func collect(): + if(player.current_hp < player.max_hp): + player.current_hp += heal_amount diff --git a/heal_item.gd.uid b/heal_item.gd.uid new file mode 100644 index 0000000..aafba4e --- /dev/null +++ b/heal_item.gd.uid @@ -0,0 +1 @@ +uid://b43fudwi47qfd diff --git a/heal_item.tscn b/heal_item.tscn new file mode 100644 index 0000000..5b50b0e --- /dev/null +++ b/heal_item.tscn @@ -0,0 +1,17 @@ +[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="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_48lih"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_hvhjo"] + +[node name="HealItem" type="Area2D"] +script = ExtResource("1_3vbv8") + +[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("2_48lih") diff --git a/item.gd b/item.gd new file mode 100644 index 0000000..8457022 --- /dev/null +++ b/item.gd @@ -0,0 +1,20 @@ +class_name Item extends Area2D +@onready var player = get_tree().get_root().get_node("main/Player") + +func _ready() -> void: + self.connect("body_entered", _on_body_entered) + +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() + +func collect_animation(): + self.visible = false + +func collect(): + push_error("Please specify item collection behavior") diff --git a/item.gd.uid b/item.gd.uid new file mode 100644 index 0000000..e7fd929 --- /dev/null +++ b/item.gd.uid @@ -0,0 +1 @@ +uid://c0uftljafcroy diff --git a/main.tscn b/main.tscn index 00a5dae..650e5b9 100644 --- a/main.tscn +++ b/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://cxo6bq26huau7"] +[gd_scene load_steps=10 format=3 uid="uid://cxo6bq26huau7"] [ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"] [ext_resource type="Script" uid="uid://vgxh2xdevat7" path="res://world/earth.gd" id="2_lquwl"] @@ -7,6 +7,8 @@ [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://chu67ci7sl488" path="res://enemies/ghost.tscn" id="9_kek77"] [node name="main" type="Node2D"] @@ -47,6 +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) + [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 cc8777d..385b4b0 100644 --- a/player/player.gd +++ b/player/player.gd @@ -99,10 +99,9 @@ func manage_velocity(delta: float) -> void: var dropped = false if(not is_on_floor()): air_jumps_current -= 1; - print("Not Grounded") elif (Input.is_action_pressed("drop")): dropped = true - self.position.y += 3 + self.position += earth_aligner.global_from_local(Vector2(0,3)) if(not dropped): local_velocity.y = -jump_strength