Merge pull request 'Add HP pickup' (#6) from 2-hp-pickup into master

Reviewed-on: #6
This commit is contained in:
2025-08-20 03:38:15 +00:00
12 changed files with 84 additions and 9 deletions

BIN
assets/sprites/pickup_heart.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/sprites/pickup_heart.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cdsdhrtpbpqd4"
path="res://.godot/imported/pickup_heart.png-d700d2e299dde55dcfafc550f860d66c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/pickup_heart.png"
dest_files=["res://.godot/imported/pickup_heart.png-d700d2e299dde55dcfafc550f860d66c.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -10,6 +10,7 @@ extends Node2D
const COLOR_CRIT = Color.GOLD const COLOR_CRIT = Color.GOLD
const COLOR_REGULAR = Color.WHITE const COLOR_REGULAR = Color.WHITE
const COLOR_PLAYER = Color.CRIMSON const COLOR_PLAYER = Color.CRIMSON
const COLOR_HEAL = Color.CHARTREUSE
func _ready() -> void: func _ready() -> void:
@@ -17,8 +18,10 @@ func _ready() -> void:
label.add_theme_color_override("font_color", COLOR_PLAYER) label.add_theme_color_override("font_color", COLOR_PLAYER)
if critical_damage: if critical_damage:
label.add_theme_color_override("font_color", COLOR_CRIT) 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.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.play("normal_damage")
animation_player.animation_finished.connect(_on_animation_finished) animation_player.animation_finished.connect(_on_animation_finished)

View File

@@ -54,10 +54,10 @@ anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
offset_left = -29.5 offset_left = -20.0
offset_top = -31.5 offset_top = -268.0
offset_right = -10.5 offset_right = -1.0
offset_bottom = -8.5 offset_bottom = -245.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
size_flags_horizontal = 4 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="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"] [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://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://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://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"] [node name="Main" type="Node2D"]
script = ExtResource("1_jyhfs") script = ExtResource("1_jyhfs")
@@ -28,4 +29,6 @@ target = NodePath("../Player")
[node name="PickupMagnet" parent="." instance=ExtResource("6_tefeu")] [node name="PickupMagnet" parent="." instance=ExtResource("6_tefeu")]
position = Vector2(1697, 414) 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 class_name PickupBase
extends Node2D extends Node2D
@export var value: float
@export var max_speed: float = 100.0 @export var max_speed: float = 100.0
@export var min_speed: float = 10.0 @export var min_speed: float = 10.0

View File

@@ -6,7 +6,7 @@
size = Vector2(10, 10) size = Vector2(10, 10)
[sub_resource type="CircleShape2D" id="CircleShape2D_oto2a"] [sub_resource type="CircleShape2D" id="CircleShape2D_oto2a"]
radius = 3.16228 radius = 4.0
[node name="PickupBase" type="Node2D" groups=["pickup"]] [node name="PickupBase" type="Node2D" groups=["pickup"]]
script = ExtResource("1_oto2a") 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: if dead or god_mode:
return return
player_stats.current_health -= value 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() var dm = preload("res://scenes/damage_numbers.tscn").instantiate()
dm.damage_taken = value dm.damage_taken = value
dm.player_damage = false dm.player_damage = false