game: add hp pickup

This commit is contained in:
2025-08-20 05:36:23 +02:00
parent 1c85c94a9a
commit 2c781e4d2a
9 changed files with 44 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ extends Node2D
const COLOR_CRIT = Color.GOLD
const COLOR_REGULAR = Color.WHITE
const COLOR_PLAYER = Color.CRIMSON
const COLOR_HEAL = Color.CHARTREUSE
func _ready() -> void:
@@ -17,8 +18,10 @@ func _ready() -> void:
label.add_theme_color_override("font_color", COLOR_PLAYER)
if critical_damage:
label.add_theme_color_override("font_color", COLOR_CRIT)
if damage_taken < 0:
label.add_theme_color_override("font_color", COLOR_HEAL)
label.add_theme_font_size_override("font_size", 8)
label.text = "%0.0f" % damage_taken
label.text = "%0.0f" % absf(damage_taken)
animation_player.play("normal_damage")
animation_player.animation_finished.connect(_on_animation_finished)

View File

@@ -54,10 +54,10 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -29.5
offset_top = -31.5
offset_right = -10.5
offset_bottom = -8.5
offset_left = -20.0
offset_top = -268.0
offset_right = -1.0
offset_bottom = -245.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://bjg50n7aab3ng"]
[gd_scene load_steps=8 format=3 uid="uid://bjg50n7aab3ng"]
[ext_resource type="Script" uid="uid://brb4ssksmtq8k" path="res://scenes/main.gd" id="1_jyhfs"]
[ext_resource type="PackedScene" uid="uid://4xha2nhf8fya" path="res://scenes/test_level.tscn" id="1_o5qli"]
@@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://b18uib08hvdpq" path="res://scenes/managers/ui/main_ui.tscn" id="3_sugp2"]
[ext_resource type="PackedScene" uid="uid://dy73qrxcgrwg3" path="res://scenes/managers/enemy_manager.tscn" id="5_tbgi4"]
[ext_resource type="PackedScene" uid="uid://bbev8m5g0p3a3" path="res://scenes/pickups/pickup_magnet.tscn" id="6_tefeu"]
[ext_resource type="PackedScene" uid="uid://cr8gj1dlloamp" path="res://scenes/pickups/pickup_hp.tscn" id="7_o6xl0"]
[node name="Main" type="Node2D"]
script = ExtResource("1_jyhfs")
@@ -28,4 +29,6 @@ target = NodePath("../Player")
[node name="PickupMagnet" parent="." instance=ExtResource("6_tefeu")]
position = Vector2(1697, 414)
duration = 15.0
[node name="PickupHP" parent="." instance=ExtResource("7_o6xl0")]
position = Vector2(1678, 939)

View File

@@ -1,7 +1,6 @@
class_name PickupBase
extends Node2D
@export var value: float
@export var max_speed: float = 100.0
@export var min_speed: float = 10.0

View File

@@ -6,7 +6,7 @@
size = Vector2(10, 10)
[sub_resource type="CircleShape2D" id="CircleShape2D_oto2a"]
radius = 3.16228
radius = 4.0
[node name="PickupBase" type="Node2D" groups=["pickup"]]
script = ExtResource("1_oto2a")

View File

@@ -0,0 +1,14 @@
class_name PickupHP
extends PickupBase
@export var value: float = 25.0
@onready var collision_shape_2d: CollisionShape2D = $Area2D/CollisionShape2D
func pickup() -> void:
if not player:
push_error("pickup called on %s without player set" % self)
return
player.take_damage(-value)
queue_free()

View File

@@ -0,0 +1 @@
uid://c6t222lues8xe

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=4 format=3 uid="uid://cr8gj1dlloamp"]
[ext_resource type="PackedScene" uid="uid://dr80h4envloce" path="res://scenes/pickups/pickup_base.tscn" id="1_f4qop"]
[ext_resource type="Script" uid="uid://c6t222lues8xe" path="res://scenes/pickups/pickup_hp.gd" id="2_264us"]
[ext_resource type="Texture2D" uid="uid://cdsdhrtpbpqd4" path="res://assets/sprites/pickup_heart.png" id="3_264us"]
[node name="PickupHP" instance=ExtResource("1_f4qop")]
script = ExtResource("2_264us")
value = 25.0
[node name="Sprite2D" parent="." index="0"]
texture = ExtResource("3_264us")

View File

@@ -39,6 +39,9 @@ func take_damage(value: float) -> void:
if dead or god_mode:
return
player_stats.current_health -= value
player_stats.current_health = clampf(
player_stats.current_health, -1.0, player_stats.get_final("max_health", modifiers)
)
var dm = preload("res://scenes/damage_numbers.tscn").instantiate()
dm.damage_taken = value
dm.player_damage = false