diff --git a/pickups/pickup.gd b/pickups/pickup.gd index 573de6d..66b5730 100644 --- a/pickups/pickup.gd +++ b/pickups/pickup.gd @@ -48,5 +48,6 @@ func is_on_floor() -> bool: func _on_body_entered(body: Node2D) -> void: if body.is_in_group("player"): - picked_up.emit(self, pickup_data) + if pickup_data != null: + picked_up.emit(self, pickup_data) queue_free() diff --git a/player/player.gd b/player/player.gd index 3a7ef9d..7e38a1b 100644 --- a/player/player.gd +++ b/player/player.gd @@ -199,8 +199,9 @@ var is_dead: bool = false var jumps_remaining: int = 2 var _speed_boost_timer: float = 0.0 -var _speed_boost_multiplier: float = 1.0 -var _original_move_speed: float = 0.0 +var _speed_boost_multiplier: float = 0.0 + +var _floating_texts: Array = [] # Tracks the highest point reached since leaving the ground, used to scale # ground pound damage by jump height instead of fall distance. @@ -252,6 +253,7 @@ func _physics_process(delta: float) -> void: _handle_horizontal_movement(delta) _update_punch_damage() _update_speed_boost(delta) + _update_floating_texts(delta) move_and_slide() @@ -528,15 +530,39 @@ func _on_pickup_picked_up(pickup: Node, data: PickupData) -> void: if is_dead or data == null: return if data.effect_type == "heal": - current_health = min(current_health + int(data.value), character_data.max_health) + var heal_amount: int = int(data.value) + current_health = min(current_health + heal_amount, character_data.max_health) health_changed.emit(current_health, character_data.max_health) + _spawn_floating_text("+" + str(heal_amount), Color(0.2, 1.0, 0.3)) elif data.effect_type == "speed_boost": _speed_boost_multiplier = data.value _speed_boost_timer = data.duration + _spawn_floating_text("SPEED UP", Color(1.0, 0.8, 0.2)) -func _update_speed_boost(_delta: float) -> void: - pass +func _update_speed_boost(delta: float) -> void: + if _speed_boost_timer > 0.0: + _speed_boost_timer = max(_speed_boost_timer - delta, 0.0) + else: + _speed_boost_multiplier = 0.0 + + +func _spawn_floating_text(text: String, color: Color) -> void: + var entry := { + "text": text, + "timer": 1.2, + "pos": Vector2(-12, -60), + "color": color, + "velocity": Vector2(0, -25) + } + _floating_texts.append(entry) + + +func _update_floating_texts(delta: float) -> void: + for entry in _floating_texts: + entry.pos += entry.velocity * delta + entry.timer -= delta + _floating_texts = _floating_texts.filter(func(e): return e.timer > 0.0) func _connect_to_enemies() -> void: @@ -622,6 +648,8 @@ func _update_timers(delta: float) -> void: invulnerability_timer = max(invulnerability_timer - delta, 0.0) if _speed_boost_timer > 0.0: _speed_boost_timer = max(_speed_boost_timer - delta, 0.0) + else: + _speed_boost_multiplier = 0.0 func _update_animation() -> void: @@ -722,6 +750,14 @@ func _draw() -> void: 2.0 ) + var font: Font = ThemeDB.get_default_theme().get_font("font", "Label") + if font != null: + for entry in _floating_texts: + var alpha: float = clamp(entry.timer / 1.2, 0.0, 1.0) + var col = entry.color + col.a = alpha + draw_string(font, entry.pos, entry.text, 0, -1, 14, col) + func _draw_rectangle_collision( collision: CollisionShape2D, diff --git a/ui/hud/player_health_hud.gd b/ui/hud/player_health_hud.gd index 5c488ee..ff4c572 100644 --- a/ui/hud/player_health_hud.gd +++ b/ui/hud/player_health_hud.gd @@ -10,10 +10,14 @@ extends CanvasLayer @onready var health_bar: ProgressBar = $HUD/HealthBar @onready var health_label: Label = $HUD/HealthBar/HealthLabel +@onready var speed_label: Label = $HUD/SpeedLabel + +var player_ref: Node func _ready() -> void: var player: Node = get_parent() + player_ref = player if player == null or not player.has_signal(&"health_changed"): push_error("PlayerHealthHUD must be a child of a Player with health_changed signal.") return @@ -21,6 +25,21 @@ func _ready() -> void: # Child _ready() runs before Player._ready(). We connect here first and the # Player will emit its initial health value a moment later during its _ready(). player.connect(&"health_changed", _on_health_changed) + if speed_label: + speed_label.visible = false + + +func _process(_delta: float) -> void: + if player_ref == null or speed_label == null: + return + if "get" in player_ref and player_ref.has_method("get"): + pass + var t = player_ref.get("_speed_boost_timer") + if t != null and float(t) > 0.0: + speed_label.visible = true + speed_label.text = "SPEED UP: %ds" % int(float(t)) + else: + speed_label.visible = false func _on_health_changed(current_health: int, max_health: int) -> void: diff --git a/ui/hud/player_health_hud.tscn b/ui/hud/player_health_hud.tscn index 9607bbc..2bcb2aa 100644 --- a/ui/hud/player_health_hud.tscn +++ b/ui/hud/player_health_hud.tscn @@ -63,3 +63,17 @@ theme_override_font_sizes/font_size = 18 text = "HP 5 / 5" horizontal_alignment = 1 vertical_alignment = 1 + +[node name="SpeedLabel" type="Label" parent="HUD"] +layout_mode = 0 +offset_left = 18.0 +offset_top = 70.0 +offset_right = 278.0 +offset_bottom = 98.0 +theme_override_colors/font_color = Color(1, 0.8, 0.2, 1) +theme_override_colors/font_shadow_color = Color(0, 0, 0, 0.9) +theme_override_font_sizes/font_size = 16 +text = "SPEED UP: 0s" +horizontal_alignment = 1 +vertical_alignment = 1 +visible = false