From 8a5290c5efb75093868efe1d02ce2c588250e5b1 Mon Sep 17 00:00:00 2001 From: Diego De la Viuda Llorente Date: Tue, 27 Oct 2026 10:58:57 +0100 Subject: [PATCH] Animaciones --- assets/characters/ankarde/player_pixel.svg | 580 ++++++++++++++++++ docs/pixel_combat.md | 78 +++ effects/combat_fx.gd | 123 ++++ enemies/walker/walker.gd | 90 ++- player/camera_2d.gd | 77 ++- .../shared/prototype_sprite_frames.tres | 474 +++++++------- player/player.gd | 244 ++++++-- player/player.tscn | 7 +- tests/test_pixel_combat_resources.py | 62 ++ tests/test_pixel_combat_runtime.gd | 134 ++++ 10 files changed, 1581 insertions(+), 288 deletions(-) create mode 100644 assets/characters/ankarde/player_pixel.svg create mode 100644 docs/pixel_combat.md create mode 100644 effects/combat_fx.gd create mode 100644 tests/test_pixel_combat_resources.py create mode 100644 tests/test_pixel_combat_runtime.gd diff --git a/assets/characters/ankarde/player_pixel.svg b/assets/characters/ankarde/player_pixel.svg new file mode 100644 index 0000000..d6c90e6 --- /dev/null +++ b/assets/characters/ankarde/player_pixel.svg @@ -0,0 +1,580 @@ + +Pixel rocker: idle, walk, jump, fall, punch, ground pound, land, guitar solo and hurt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/pixel_combat.md b/docs/pixel_combat.md new file mode 100644 index 0000000..e726273 --- /dev/null +++ b/docs/pixel_combat.md @@ -0,0 +1,78 @@ +# Pixel combat pass + +Apply this patch after `fix_player.patch` and `fix_level_02.patch`. +It does not reapply or undo either fix. + +## Art and scale + +The four existing CharacterData resources still share the same SpriteFrames. +Their existing references and the SpriteFrames UID are retained. The old PNGs +are not deleted; the new resource uses `assets/characters/ankarde/player_pixel.svg`. +This is a self-contained pixel atlas (integer coordinates, flat palette), matching +the SVG pixel style of the enemies. No external fonts, plugins or image files are +needed to build the atlas. + +There are 37 frames in 11 animations: idle, walk, jump, fall, punch, ground pound, +land, special start, special loop, special end and hurt. Cells are 64 x 64 pixels, +with the standing character approximately 56 pixels tall. Nearest filtering and +1:1 sprite scale avoid smoothing. The body and hurtbox change from 41 x 74 to +26 x 52, comparable to the enemies' 28 x 52 bodies. Jump and movement stats are +unchanged. The punch area and ground-pound origin follow the new proportions. + +## Combat behaviour + +- Punch: 0.28-second animation, 0.055-second windup and 0.11-second active window. + A target takes one hit per punch. The 0.34-second cooldown is enforced. +- Ground pound: dedicated falling pose, squash on landing, ground-space dust, + cracks and an expanding impact ring. Damage remains capped at 7-12. The impact + queries the hurtboxes at the resolved landing position rather than the previous + physics frame's cached Area2D overlaps. +- Special: 2.4 seconds by default, with four pulses at 0.36, 0.88, 1.40 and 1.92 + seconds. The player draws a guitar, plays the solo and lowers it afterwards. + Movement, jump and other attacks are locked during the solo, except for recoil + and incoming knockback. No extra invulnerability is granted. +- All current charge is consumed once, on activation. Kills during the solo can + recharge the next attack; recasting during the current solo is blocked. +- The original damage budget is distributed across the pulses, NOT applied four + times. Cumulative rounding avoids losing points or imposing one point per pulse + on a tiny budget. The per-target budget is fixed on first contact. Enemies must + still be on screen and within special_radius to receive each pulse, so escaping + its range can avoid later damage. The existing per-level radius is preserved. +- Enemies flash on impact and retain knockback. At zero HP, logical death and the + existing rewards happen immediately once. Combat collisions stop, while the + body launches, falls against the world, collapses and fades for 0.9 seconds. + Dead nodes remain available to the levels' KO polling and total-enemy counts. + Respawn still works and restores the sprite transform, opacity and collisions. + +Effects are independent of the debug-hitbox flags. They use lightweight transient +world-space nodes and a non-interactive screen overlay below the HUD. Effects +clean themselves up. No new music or guitar audio is included in this visual pass. + +## Adjustments in the Inspector + +- Player: special_duration, special_pulse_count and existing special_radius. +- Camera2D: feedback_strength from 0 to 1. Zero disables both screen overlays and + camera shake. Shake is capped at three world pixels; there are no white flashes. +- Enemy: death_animation_duration. Respawn delay remains measured from logical death. + +## Checks + +Engine-independent resource checks: + +```sh +python -m unittest discover -s tests -v +``` + +Import the new SVG and register scripts, then run engine integration checks: + +```sh +godot --headless --path . --editor --import +godot --headless --path . --script res://tests/test_level_02_runtime.gd +godot --headless --path . --script res://tests/test_pixel_combat_runtime.gd +``` + +The combat check exercises scene/texture loading, charge consumption, delayed and +bounded pulse damage, recoil, death visibility, one-time rewards, respawn state +and the 12-point ground-pound cap. This headless check is not a visual playtest. +In the editor, run Level02 and check W (jump), J (punch), K (air ground pound) and +L (charged guitar solo), including left-facing attacks and mobile controls. diff --git a/effects/combat_fx.gd b/effects/combat_fx.gd new file mode 100644 index 0000000..159d2df --- /dev/null +++ b/effects/combat_fx.gd @@ -0,0 +1,123 @@ +class_name CombatFX +extends Node2D + +## Short-lived world-space effects shared by the player and enemies. +## Pixel shapes only: no particles plugin, imported effect textures or fonts. + +var kind: StringName = &"hit" +var direction: float = 1.0 +var radius: float = 54.0 +var _age: float = 0.0 +var _lifetime: float = 0.28 + + +static func spawn(parent: Node, origin: Vector2, effect_kind: StringName, + effect_direction: float = 1.0, effect_radius: float = 54.0) -> void: + if not is_instance_valid(parent): + return + var effect: CombatFX = CombatFX.new() + effect.kind = effect_kind + effect.direction = effect_direction + effect.radius = effect_radius + parent.add_child(effect) + effect.global_position = origin + + +func _ready() -> void: + z_index = 12 + texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST + match kind: + &"ground_pound": + _lifetime = 0.60 + &"solo": + _lifetime = 0.62 + &"death": + _lifetime = 0.48 + &"dust": + _lifetime = 0.32 + + +func _process(delta: float) -> void: + _age += delta + if _age >= _lifetime: + queue_free() + return + queue_redraw() + + +func _draw() -> void: + var progress: float = clampf(_age / _lifetime, 0.0, 1.0) + var fade: float = 1.0 - progress + match kind: + &"ground_pound": + _draw_ring(lerpf(8.0, radius, progress), 0.24, Color(1.0, 0.72, 0.34, fade), 3.0) + _draw_ring(lerpf(3.0, radius * 0.72, progress), 0.32, Color(1.0, 0.94, 0.68, fade), 2.0) + _draw_debris(progress, 16, Color(0.84, 0.71, 0.56, fade), radius) + # Ground cracks appear at the landing point, not attached to the player. + for side: float in [-1.0, 1.0]: + var crack := PackedVector2Array([ + Vector2(3.0 * side, 0.0), Vector2(14.0 * side, 3.0), + Vector2(22.0 * side, -1.0), Vector2(35.0 * side, 2.0), + Vector2(44.0 * side, 0.0)]) + draw_polyline(crack, Color(1.0, 0.77, 0.4, fade * 0.8), 2.0) + &"solo": + var wave_radius: float = lerpf(12.0, radius, progress) + _draw_ring(wave_radius, 0.70, Color(0.42, 0.88, 1.0, fade * 0.85), 3.0) + _draw_ring(wave_radius * 0.78, 0.70, Color(0.85, 0.57, 1.0, fade * 0.65), 2.0) + for index: int in range(8): + var angle: float = TAU * float(index) / 8.0 - progress * 0.18 + var point := Vector2(cos(angle), sin(angle) * 0.7) * wave_radius + _draw_note(point.round(), Color(0.95, 0.82, 1.0, fade)) + if progress < 0.35: + _draw_sparks(progress / 0.35, Color(0.75, 0.91, 1.0, fade), 10, 34.0) + &"dust": + _draw_debris(progress, 7, Color(0.78, 0.76, 0.70, fade * 0.65), 22.0) + &"death": + _draw_sparks(progress, Color(1.0, 0.73, 0.34, fade), 14, 42.0) + _draw_ring(lerpf(4.0, 27.0, progress), 0.80, Color(1.0, 0.89, 0.66, fade), 2.0) + &"swing": + var arc := PackedVector2Array() + for index: int in range(7): + var angle: float = lerpf(-1.1, 1.1, float(index) / 6.0) + arc.append(Vector2(cos(angle) * 16.0 * direction, sin(angle) * 17.0).round()) + draw_polyline(arc, Color(1.0, 0.91, 0.69, fade * 0.9), 2.0) + _: + _draw_sparks(progress, Color(1.0, 0.84, 0.49, fade), 8, 27.0) + if progress < 0.45: + draw_rect(Rect2(-3, -8, 6, 16), Color(1.0, 0.98, 0.88, fade)) + draw_rect(Rect2(-8, -3, 16, 6), Color(1.0, 0.98, 0.88, fade)) + + +func _draw_ring(ring_radius: float, height_ratio: float, color: Color, width: float) -> void: + var points := PackedVector2Array() + for index: int in range(33): + var angle: float = TAU * float(index) / 32.0 + points.append(Vector2(cos(angle) * ring_radius, sin(angle) * ring_radius * height_ratio).round()) + draw_polyline(points, color, width) + + +func _draw_sparks(progress: float, color: Color, count: int, spread: float) -> void: + for index: int in range(count): + var angle: float = float(index) * TAU / float(count) + var axis := Vector2(cos(angle), sin(angle)) + var distance: float = spread * progress + var point: Vector2 = (axis * distance + Vector2(direction * 5.0 * progress, 0)).round() + var tail: Vector2 = (point - axis * (6.0 * (1.0 - progress))).round() + draw_line(tail, point, color, 2.0) + + +func _draw_debris(progress: float, count: int, color: Color, spread: float) -> void: + for index: int in range(count): + var side: float = -1.0 if index % 2 == 0 else 1.0 + var speed: float = 0.35 + float(index % 5) * 0.16 + var height: float = 10.0 + float(index % 4) * 7.0 + var point := Vector2(side * spread * progress * speed, + -height * sin(progress * PI) - 2.0) + var size: float = 2.0 + float(index % 3) + draw_rect(Rect2(point.round(), Vector2.ONE * size), color) + + +func _draw_note(point: Vector2, color: Color) -> void: + draw_rect(Rect2(point, Vector2(5, 4)), color) + draw_rect(Rect2(point + Vector2(4, -10), Vector2(2, 13)), color) + draw_rect(Rect2(point + Vector2(6, -10), Vector2(5, 3)), color) diff --git a/enemies/walker/walker.gd b/enemies/walker/walker.gd index b426b78..c19d5c2 100644 --- a/enemies/walker/walker.gd +++ b/enemies/walker/walker.gd @@ -10,6 +10,7 @@ signal died const PLAYER_HURTBOX_MASK: int = 1 << 3 const DROP_MANAGER := preload("res://pickups/drop_manager.gd") +const COMBAT_FX = preload("res://effects/combat_fx.gd") enum AttackState { @@ -108,6 +109,9 @@ var drops_handled_by_level: bool = false ## A value of 0 disables respawn (one enemy = one test item). @export var respawn_delay: float = 5.0 +## Visible launch, collapse and fade before the body disappears. +@export_range(0.3, 2.5, 0.05) var death_animation_duration: float = 0.9 + ## Limits how far the enemy may chase from its spawn point; 0 = unrestricted. ## Small limits keep independent testing encounters from piling up. @export var chase_radius: float = 0.0 @@ -125,7 +129,7 @@ var drops_handled_by_level: bool = false ## Enabled while the enemy has no final sprite/animation. The grey rectangle is ## the temporary body. Red overlays are the hurtbox and active attack hitbox. ## The orange area during windup previews the complete attack sweep. -@export var show_debug_hitboxes: bool = true +@export var show_debug_hitboxes: bool = false ## Shows the enemy health bar above its head and floating damage numbers when ## it is hit. Purely debug: can be disabled once final art and UI exist. @@ -173,9 +177,20 @@ var knockback_timer: float = 0.0 ## Floating damage numbers shown above the enemy when it takes damage. ## Each entry: { text: String, local_pos: Vector2, timer: float } var _damage_texts: Array = [] +var _hit_flash_timer: float = 0.0 +var _death_elapsed: float = 0.0 +var _last_hit_direction: float = 1.0 +var _visual_position: Vector2 +var _visual_scale: Vector2 +var _visual_rotation: float +var _visual_color: Color func _ready() -> void: + _visual_position = visual.position + _visual_scale = visual.scale + _visual_rotation = visual.rotation + _visual_color = visual.self_modulate spawn_position = global_position current_health = max_health target = get_tree().get_first_node_in_group(&"player") as Node2D @@ -198,8 +213,11 @@ func _ready() -> void: func _physics_process(delta: float) -> void: if is_dead: + _update_death_animation(delta) return + _hit_flash_timer = maxf(0.0, _hit_flash_timer - delta) + visual.self_modulate = Color(1.8, 1.8, 1.8) if _hit_flash_timer > 0.0 else _visual_color _update_timers(delta) _update_damage_texts(delta) _apply_gravity(delta) @@ -465,6 +483,15 @@ func take_damage(amount: int, source_position: Vector2) -> void: return current_health = max(current_health - amount, 0) + _hit_flash_timer = 0.09 + is_awake = true + _last_hit_direction = signf(global_position.x - source_position.x) + if _last_hit_direction == 0.0: + _last_hit_direction = -facing_direction + COMBAT_FX.spawn(get_parent(), global_position, &"hit", _last_hit_direction) + var camera: Camera2D = get_viewport().get_camera_2d() + if camera != null and camera.has_method("impact"): + camera.call("impact", 1.0, 0.12) # Floating damage number (debug only). if show_debug_enemy_info: @@ -508,7 +535,14 @@ func take_damage(amount: int, source_position: Vector2) -> void: func _die() -> void: + if is_dead: + return + _interrupt_attack() is_dead = true + _death_elapsed = 0.0 + velocity = Vector2(_last_hit_direction * 150.0, -210.0) + COMBAT_FX.spawn(get_parent(), global_position, &"death", _last_hit_direction) + # Logical death happens now, exactly once. Animation must not delay rewards. died.emit() # Test encounters always drop their assigned item, including the two items @@ -525,21 +559,51 @@ func _die() -> void: parent = get_tree().root DROP_MANAGER.spawn_drops(drops, parent, global_position) - velocity = Vector2.ZERO - visible = false - - # take_damage() can run while Godot is flushing physics queries, therefore - # collision shapes are disabled deferred instead of changing them directly. - body_collision.set_deferred("disabled", true) + # Disable combat immediately; keep the body colliding with the WORLD while it + # falls. Disabling the body now would let the death pose fall through streets. hurtbox_collision.set_deferred("disabled", true) attack_collision.set_deferred("disabled", true) + queue_redraw() - if respawn_delay > 0.0: - await get_tree().create_timer(respawn_delay).timeout + +func _update_death_animation(delta: float) -> void: + _death_elapsed += delta + _update_damage_texts(delta) + var duration: float = maxf(death_animation_duration, 0.3) + if _death_elapsed < duration: + _apply_gravity(delta) + velocity.x = move_toward(velocity.x, 0.0, 180.0 * delta) + move_and_slide() + var collapse: float = smoothstep(0.06, duration * 0.55, _death_elapsed) + visual.rotation = _visual_rotation + _last_hit_direction * PI * 0.5 * collapse + visual.position = _visual_position + Vector2(0, 10.0 * collapse) + visual.scale = _visual_scale * Vector2(1.0, lerpf(1.0, 0.85, collapse)) + var fade: float = 1.0 - smoothstep(duration * 0.65, duration, _death_elapsed) + var color: Color = Color(1.8, 1.8, 1.8) if _death_elapsed < 0.09 else _visual_color + color.a = _visual_color.a * fade + visual.self_modulate = color + queue_redraw() + return + + visible = false + velocity = Vector2.ZERO + body_collision.set_deferred("disabled", true) + if respawn_delay <= 0.0: + # Keep the dead node for the lab's KO polling and Level02's total count. + set_physics_process(false) + elif _death_elapsed >= maxf(respawn_delay, duration): _respawn() func _respawn() -> void: + set_physics_process(true) + _death_elapsed = 0.0 + _hit_flash_timer = 0.0 + visual.position = _visual_position + visual.scale = _visual_scale + visual.rotation = _visual_rotation + visual.self_modulate = _visual_color + _damage_texts.clear() global_position = spawn_position velocity = Vector2.ZERO current_health = max_health @@ -571,6 +635,10 @@ func _respawn() -> void: # ============================================================================ func _draw() -> void: + if is_dead: + if show_debug_enemy_info: + _draw_damage_texts() + return # Retain a fallback body if an imported sprite is missing. if visual.texture == null: _draw_rectangle_collision( @@ -650,7 +718,7 @@ func _draw_enemy_health_bar() -> void: # Background. draw_rect(Rect2(bar_pos, Vector2(bar_width, bar_height)), Color(0.2, 0.2, 0.2, 0.8), true) # Fill. - var fill_ratio: float = current_health / max_health if max_health > 0 else 0.0 + var fill_ratio: float = float(current_health) / float(max_health) if max_health > 0 else 0.0 draw_rect( Rect2(bar_pos, Vector2(bar_width * fill_ratio, bar_height)), Color(0.85, 0.2, 0.2, 0.95), @@ -667,4 +735,4 @@ func _draw_damage_texts() -> void: for entry in _damage_texts: var alpha: float = clamp(entry.timer, 0.0, 1.0) - draw_string(font, entry.local_pos, entry.text, 0, -1, 16, Color(1, 1, 1, alpha)) + draw_string(font, entry.local_pos, entry.text, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, Color(1, 1, 1, alpha)) diff --git a/player/camera_2d.gd b/player/camera_2d.gd index f79efda..606a8d4 100644 --- a/player/camera_2d.gd +++ b/player/camera_2d.gd @@ -1,10 +1,83 @@ extends Camera2D +## Set to zero to disable camera shake and screen overlays. +@export_range(0.0, 1.0, 0.05) var feedback_strength: float = 1.0 + +var _base_offset: Vector2 +var _shake_remaining: float = 0.0 +var _shake_duration: float = 0.16 +var _shake_amplitude: float = 0.0 +var _clock: float = 0.0 +var _solo_remaining: float = 0.0 +var _flash_color := Color(1.0, 0.82, 0.50) +var _overlay: Control + -## Límites provisionales de cámara para la sala de pruebas actual. -## Cuando existan niveles reales, estos límites podrán configurarse por nivel. func _ready() -> void: limit_left = 0 limit_top = 0 limit_right = 4000 limit_bottom = 2500 + _base_offset = offset + + # Below the existing HUDs. This Control never intercepts touch controls. + var layer := CanvasLayer.new() + layer.name = "CombatFeedback" + layer.layer = 80 + add_child(layer) + _overlay = Control.new() + _overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE + layer.add_child(_overlay) + _overlay.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + _overlay.draw.connect(_draw_feedback) + + +func impact(strength: float = 1.5, duration: float = 0.16, + color: Color = Color(1.0, 0.82, 0.50)) -> void: + _shake_amplitude = maxf(_shake_amplitude, strength) + _shake_remaining = maxf(_shake_remaining, duration) + _shake_duration = maxf(_shake_remaining, 0.01) + _flash_color = color + + +func start_solo(duration: float) -> void: + _solo_remaining = duration + + +func _process(delta: float) -> void: + _clock += delta + _shake_remaining = maxf(0.0, _shake_remaining - delta) + _solo_remaining = maxf(0.0, _solo_remaining - delta) + var envelope: float = _shake_remaining / _shake_duration + var amplitude: float = minf(_shake_amplitude, 3.0) * envelope * envelope * feedback_strength + offset = _base_offset + Vector2(sin(_clock * 83.0), cos(_clock * 67.0)) * amplitude + if _shake_remaining == 0.0: + _shake_amplitude = 0.0 + _overlay.queue_redraw() + + +func _draw_feedback() -> void: + if feedback_strength <= 0.0: + return + var size: Vector2 = get_viewport_rect().size + var pulse: float = (_shake_remaining / _shake_duration) * feedback_strength + # Subtle edge flashes, not full-white flashes or a strobing screen. + if pulse > 0.0: + var color: Color = _flash_color + color.a = pulse * 0.14 + _overlay.draw_rect(Rect2(0, 0, size.x, 8), color) + _overlay.draw_rect(Rect2(0, size.y - 8, size.x, 8), color) + _overlay.draw_rect(Rect2(0, 0, 8, size.y), color) + _overlay.draw_rect(Rect2(size.x - 8, 0, 8, size.y), color) + if _solo_remaining <= 0.0: + return + var solo_alpha: float = minf(_solo_remaining / 0.25, 1.0) * feedback_strength + _overlay.draw_rect(Rect2(Vector2.ZERO, size), Color(0.18, 0.08, 0.32, 0.07 * solo_alpha)) + for side: float in [-1.0, 1.0]: + var edge_x: float = 0.0 if side > 0.0 else size.x + for index: int in range(7): + var y: float = (float(index) + 0.5) * size.y / 7.0 + var length: float = (32.0 + float(index % 3) * 19.0) * (0.7 + pulse) + var start := Vector2(edge_x, y) + var end := Vector2(edge_x + side * length, lerpf(y, size.y * 0.5, 0.1)) + _overlay.draw_line(start, end, Color(0.66, 0.85, 1.0, 0.24 * solo_alpha), 3.0) diff --git a/player/characters/shared/prototype_sprite_frames.tres b/player/characters/shared/prototype_sprite_frames.tres index 8c22eda..221e437 100644 --- a/player/characters/shared/prototype_sprite_frames.tres +++ b/player/characters/shared/prototype_sprite_frames.tres @@ -1,248 +1,306 @@ [gd_resource type="SpriteFrames" format=3 uid="uid://s2xmt6mpri5c"] -[ext_resource type="Texture2D" uid="uid://cjxrw1p7eh82i" path="res://assets/characters/ankarde/Diego-idle-trimmed.png" id="1_idle"] -[ext_resource type="Texture2D" uid="uid://dg1x17ci14p4f" path="res://assets/characters/ankarde/Diego-walk-trimmed.png" id="2_walk"] +[ext_resource type="Texture2D" path="res://assets/characters/ankarde/player_pixel.svg" id="1_pixel"] -[sub_resource type="AtlasTexture" id="AtlasTexture_lquwl"] -atlas = ExtResource("1_idle") -region = Rect2(0, 0, 256, 256) +[sub_resource type="AtlasTexture" id="idle_0"] +atlas = ExtResource("1_pixel") +region = Rect2(0, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_7mycd"] -atlas = ExtResource("1_idle") -region = Rect2(256, 0, 256, 256) +[sub_resource type="AtlasTexture" id="idle_1"] +atlas = ExtResource("1_pixel") +region = Rect2(64, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_272bh"] -atlas = ExtResource("1_idle") -region = Rect2(512, 0, 256, 256) +[sub_resource type="AtlasTexture" id="idle_2"] +atlas = ExtResource("1_pixel") +region = Rect2(128, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_5vw27"] -atlas = ExtResource("1_idle") -region = Rect2(768, 0, 256, 256) +[sub_resource type="AtlasTexture" id="idle_3"] +atlas = ExtResource("1_pixel") +region = Rect2(192, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_kek77"] -atlas = ExtResource("1_idle") -region = Rect2(1024, 0, 256, 256) +[sub_resource type="AtlasTexture" id="walk_0"] +atlas = ExtResource("1_pixel") +region = Rect2(256, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_4c57u"] -atlas = ExtResource("1_idle") -region = Rect2(0, 256, 256, 256) +[sub_resource type="AtlasTexture" id="walk_1"] +atlas = ExtResource("1_pixel") +region = Rect2(320, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_efxa6"] -atlas = ExtResource("1_idle") -region = Rect2(256, 256, 256, 256) +[sub_resource type="AtlasTexture" id="walk_2"] +atlas = ExtResource("1_pixel") +region = Rect2(384, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_dg77c"] -atlas = ExtResource("1_idle") -region = Rect2(512, 256, 256, 256) +[sub_resource type="AtlasTexture" id="walk_3"] +atlas = ExtResource("1_pixel") +region = Rect2(448, 0, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_ycdy4"] -atlas = ExtResource("1_idle") -region = Rect2(768, 256, 256, 256) +[sub_resource type="AtlasTexture" id="walk_4"] +atlas = ExtResource("1_pixel") +region = Rect2(0, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_w48qg"] -atlas = ExtResource("1_idle") -region = Rect2(1024, 256, 256, 256) +[sub_resource type="AtlasTexture" id="walk_5"] +atlas = ExtResource("1_pixel") +region = Rect2(64, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_vivmo"] -atlas = ExtResource("1_idle") -region = Rect2(0, 512, 256, 256) +[sub_resource type="AtlasTexture" id="jump_0"] +atlas = ExtResource("1_pixel") +region = Rect2(128, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_2cqfq"] -atlas = ExtResource("1_idle") -region = Rect2(256, 512, 256, 256) +[sub_resource type="AtlasTexture" id="jump_1"] +atlas = ExtResource("1_pixel") +region = Rect2(192, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_yaehf"] -atlas = ExtResource("2_walk") -region = Rect2(0, 0, 256, 256) +[sub_resource type="AtlasTexture" id="fall_0"] +atlas = ExtResource("1_pixel") +region = Rect2(256, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_074og"] -atlas = ExtResource("2_walk") -region = Rect2(256, 0, 256, 256) +[sub_resource type="AtlasTexture" id="fall_1"] +atlas = ExtResource("1_pixel") +region = Rect2(320, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_cegan"] -atlas = ExtResource("2_walk") -region = Rect2(512, 0, 256, 256) +[sub_resource type="AtlasTexture" id="punch_0"] +atlas = ExtResource("1_pixel") +region = Rect2(384, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_82xsv"] -atlas = ExtResource("2_walk") -region = Rect2(768, 0, 256, 256) +[sub_resource type="AtlasTexture" id="punch_1"] +atlas = ExtResource("1_pixel") +region = Rect2(448, 64, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_getpj"] -atlas = ExtResource("2_walk") -region = Rect2(1024, 0, 256, 256) +[sub_resource type="AtlasTexture" id="punch_2"] +atlas = ExtResource("1_pixel") +region = Rect2(0, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_ryguw"] -atlas = ExtResource("2_walk") -region = Rect2(0, 256, 256, 256) +[sub_resource type="AtlasTexture" id="punch_3"] +atlas = ExtResource("1_pixel") +region = Rect2(64, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_d13ii"] -atlas = ExtResource("2_walk") -region = Rect2(256, 256, 256, 256) +[sub_resource type="AtlasTexture" id="punch_4"] +atlas = ExtResource("1_pixel") +region = Rect2(128, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_1u8w0"] -atlas = ExtResource("2_walk") -region = Rect2(512, 256, 256, 256) +[sub_resource type="AtlasTexture" id="ground_pound_0"] +atlas = ExtResource("1_pixel") +region = Rect2(192, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_0odxb"] -atlas = ExtResource("2_walk") -region = Rect2(768, 256, 256, 256) +[sub_resource type="AtlasTexture" id="ground_pound_1"] +atlas = ExtResource("1_pixel") +region = Rect2(256, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_lswn8"] -atlas = ExtResource("2_walk") -region = Rect2(1024, 256, 256, 256) +[sub_resource type="AtlasTexture" id="land_0"] +atlas = ExtResource("1_pixel") +region = Rect2(320, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_a6jrf"] -atlas = ExtResource("2_walk") -region = Rect2(0, 512, 256, 256) +[sub_resource type="AtlasTexture" id="land_1"] +atlas = ExtResource("1_pixel") +region = Rect2(384, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_xuqvo"] -atlas = ExtResource("2_walk") -region = Rect2(256, 512, 256, 256) +[sub_resource type="AtlasTexture" id="land_2"] +atlas = ExtResource("1_pixel") +region = Rect2(448, 128, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_qsp4k"] -atlas = ExtResource("2_walk") -region = Rect2(512, 512, 256, 256) +[sub_resource type="AtlasTexture" id="special_start_0"] +atlas = ExtResource("1_pixel") +region = Rect2(0, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_kq58d"] -atlas = ExtResource("2_walk") -region = Rect2(768, 512, 256, 256) +[sub_resource type="AtlasTexture" id="special_start_1"] +atlas = ExtResource("1_pixel") +region = Rect2(64, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_seu75"] -atlas = ExtResource("2_walk") -region = Rect2(1024, 512, 256, 256) +[sub_resource type="AtlasTexture" id="special_start_2"] +atlas = ExtResource("1_pixel") +region = Rect2(128, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_htxhm"] -atlas = ExtResource("2_walk") -region = Rect2(0, 768, 256, 256) +[sub_resource type="AtlasTexture" id="special_0"] +atlas = ExtResource("1_pixel") +region = Rect2(192, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_jq2sk"] -atlas = ExtResource("2_walk") -region = Rect2(256, 768, 256, 256) +[sub_resource type="AtlasTexture" id="special_1"] +atlas = ExtResource("1_pixel") +region = Rect2(256, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_4k2k6"] -atlas = ExtResource("2_walk") -region = Rect2(512, 768, 256, 256) +[sub_resource type="AtlasTexture" id="special_2"] +atlas = ExtResource("1_pixel") +region = Rect2(320, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_0rl1p"] -atlas = ExtResource("2_walk") -region = Rect2(768, 768, 256, 256) +[sub_resource type="AtlasTexture" id="special_3"] +atlas = ExtResource("1_pixel") +region = Rect2(384, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_ok6jj"] -atlas = ExtResource("2_walk") -region = Rect2(1024, 768, 256, 256) +[sub_resource type="AtlasTexture" id="special_4"] +atlas = ExtResource("1_pixel") +region = Rect2(448, 192, 64, 64) +filter_clip = true -[sub_resource type="AtlasTexture" id="AtlasTexture_facbu"] -atlas = ExtResource("2_walk") -region = Rect2(0, 1024, 256, 256) +[sub_resource type="AtlasTexture" id="special_5"] +atlas = ExtResource("1_pixel") +region = Rect2(0, 256, 64, 64) +filter_clip = true + +[sub_resource type="AtlasTexture" id="special_end_0"] +atlas = ExtResource("1_pixel") +region = Rect2(64, 256, 64, 64) +filter_clip = true + +[sub_resource type="AtlasTexture" id="special_end_1"] +atlas = ExtResource("1_pixel") +region = Rect2(128, 256, 64, 64) +filter_clip = true + +[sub_resource type="AtlasTexture" id="hurt_0"] +atlas = ExtResource("1_pixel") +region = Rect2(192, 256, 64, 64) +filter_clip = true + +[sub_resource type="AtlasTexture" id="hurt_1"] +atlas = ExtResource("1_pixel") +region = Rect2(256, 256, 64, 64) +filter_clip = true [resource] -animations = [{ -"frames": [{ -"duration": 1.0, -"texture": SubResource("AtlasTexture_lquwl") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_7mycd") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_272bh") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_5vw27") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_kek77") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_4c57u") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_efxa6") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_dg77c") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_ycdy4") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_w48qg") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_vivmo") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_2cqfq") -}], -"loop": 1, +animations = [ +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("idle_0")}, +{"duration": 1.0, "texture": SubResource("idle_1")}, +{"duration": 1.0, "texture": SubResource("idle_2")}, +{"duration": 1.0, "texture": SubResource("idle_3")} +], +"loop": true, "name": &"idle", "speed": 5.0 -}, { -"frames": [{ -"duration": 1.0, -"texture": SubResource("AtlasTexture_yaehf") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_074og") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_cegan") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_82xsv") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_getpj") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_ryguw") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_d13ii") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_1u8w0") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_0odxb") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_lswn8") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_a6jrf") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_xuqvo") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_qsp4k") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_kq58d") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_seu75") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_htxhm") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_jq2sk") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_4k2k6") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_0rl1p") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_ok6jj") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_facbu") -}], -"loop": 1, +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("walk_0")}, +{"duration": 1.0, "texture": SubResource("walk_1")}, +{"duration": 1.0, "texture": SubResource("walk_2")}, +{"duration": 1.0, "texture": SubResource("walk_3")}, +{"duration": 1.0, "texture": SubResource("walk_4")}, +{"duration": 1.0, "texture": SubResource("walk_5")} +], +"loop": true, "name": &"walk", -"speed": 5.0 -}] +"speed": 10.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("jump_0")}, +{"duration": 1.0, "texture": SubResource("jump_1")} +], +"loop": false, +"name": &"jump", +"speed": 9.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("fall_0")}, +{"duration": 1.0, "texture": SubResource("fall_1")} +], +"loop": true, +"name": &"fall", +"speed": 7.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("punch_0")}, +{"duration": 0.75, "texture": SubResource("punch_1")}, +{"duration": 1.15, "texture": SubResource("punch_2")}, +{"duration": 0.8, "texture": SubResource("punch_3")}, +{"duration": 1.3, "texture": SubResource("punch_4")} +], +"loop": false, +"name": &"punch", +"speed": 18.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("ground_pound_0")}, +{"duration": 1.0, "texture": SubResource("ground_pound_1")} +], +"loop": true, +"name": &"ground_pound", +"speed": 12.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("land_0")}, +{"duration": 1.0, "texture": SubResource("land_1")}, +{"duration": 1.0, "texture": SubResource("land_2")} +], +"loop": false, +"name": &"land", +"speed": 16.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("special_start_0")}, +{"duration": 1.0, "texture": SubResource("special_start_1")}, +{"duration": 1.0, "texture": SubResource("special_start_2")} +], +"loop": false, +"name": &"special_start", +"speed": 9.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("special_0")}, +{"duration": 1.0, "texture": SubResource("special_1")}, +{"duration": 1.0, "texture": SubResource("special_2")}, +{"duration": 1.0, "texture": SubResource("special_3")}, +{"duration": 1.0, "texture": SubResource("special_4")}, +{"duration": 1.0, "texture": SubResource("special_5")} +], +"loop": true, +"name": &"special", +"speed": 12.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("special_end_0")}, +{"duration": 1.0, "texture": SubResource("special_end_1")} +], +"loop": false, +"name": &"special_end", +"speed": 7.0 +}, +{ +"frames": [ +{"duration": 1.0, "texture": SubResource("hurt_0")}, +{"duration": 1.0, "texture": SubResource("hurt_1")} +], +"loop": false, +"name": &"hurt", +"speed": 12.0 +} +] diff --git a/player/player.gd b/player/player.gd index d756b2d..b39e7a2 100644 --- a/player/player.gd +++ b/player/player.gd @@ -17,6 +17,7 @@ signal pickup_collected(data: PickupData) # 4 -> player hurtbox # 5 -> enemy hurtbox const ENEMY_HURTBOX_MASK: int = 1 << 4 +const COMBAT_FX = preload("res://effects/combat_fx.gd") # ============================================================================ @@ -103,10 +104,12 @@ const ENEMY_HURTBOX_MASK: int = 1 << 4 @export_category("Punch") -@export var punch_duration: float = 0.13 -@export var punch_cooldown: float = 0.28 -@export var punch_hitbox_size: Vector2 = Vector2(34.0, 24.0) -@export var punch_offset: Vector2 = Vector2(30.0, 0.0) +@export var punch_duration: float = 0.28 +@export var punch_windup: float = 0.055 +@export var punch_active_duration: float = 0.11 +@export var punch_cooldown: float = 0.34 +@export var punch_hitbox_size: Vector2 = Vector2(28.0, 22.0) +@export var punch_offset: Vector2 = Vector2(28.0, -4.0) # ============================================================================ @@ -125,7 +128,7 @@ const ENEMY_HURTBOX_MASK: int = 1 << 4 @export_range(0.0, 1.0) var ground_pound_horizontal_control: float = 0.25 @export var ground_pound_radius: float = 54.0 -@export var ground_pound_offset: Vector2 = Vector2(0.0, 18.0) +@export var ground_pound_offset: Vector2 = Vector2(0.0, 24.0) ## From 7 damage on a small jump to 12 on a high one; always stronger ## than a standard 5-point punch, even without any pickup. @@ -156,6 +159,10 @@ const ENEMY_HURTBOX_MASK: int = 1 << 4 ## The Level 01 test sets a smaller radius to keep encounters independent. @export var special_radius: float = 100000.0 +## Guitar draw, sustained solo, then recovery. Damage is shared by all pulses. +@export_range(0.6, 6.0, 0.1) var special_duration: float = 2.4 +@export_range(1, 8, 1) var special_pulse_count: int = 4 + # ============================================================================ # DEBUG @@ -164,8 +171,8 @@ const ENEMY_HURTBOX_MASK: int = 1 << 4 @export_category("Debug") ## Draws the actual hurtbox and attack areas used by gameplay. -## It is deliberately enabled while the final animations do not exist. -@export var show_debug_hitboxes: bool = true +## Combat effects do not depend on this debug overlay. +@export var show_debug_hitboxes: bool = false ## Keeps the ground-pound area visible briefly after impact. @export var debug_impact_duration: float = 0.18 @@ -176,6 +183,7 @@ const ENEMY_HURTBOX_MASK: int = 1 << 4 # ============================================================================ @onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D +@onready var feedback_camera: Camera2D = $Camera2D @onready var hurtbox_collision: CollisionShape2D = $Hurtbox/CollisionShape2D @onready var punch_hitbox: Area2D = $PunchHitbox @onready var punch_collision: CollisionShape2D = $PunchHitbox/CollisionShape2D @@ -230,6 +238,16 @@ var punch_hit_targets: Dictionary = {} var special_charge: int = 0 +var _special_active: bool = false +var _special_elapsed: float = 0.0 +var _special_charge_used: int = 0 +var _special_pulses_sent: int = 0 +var _special_damage_budgets: Dictionary = {} +var _special_damage_dealt: Dictionary = {} +var _hurt_animation_timer: float = 0.0 +var _landing_animation_timer: float = 0.0 +var _punch_swing_shown: bool = false + func _ready() -> void: if character_data == null: @@ -286,8 +304,13 @@ func _physics_process(delta: float) -> void: jumps_remaining = max_jumps if ground_pound_active: _ground_pound_impact() + else: + _landing_animation_timer = 0.18 + COMBAT_FX.spawn(get_parent(), global_position + Vector2(0, 26), &"dust") + _update_special_attack(delta) _update_animation() + _update_visual_feedback() queue_redraw() @@ -296,9 +319,14 @@ func _physics_process(delta: float) -> void: # ============================================================================ func _handle_horizontal_movement(delta: float) -> void: + # Let impulses decay instead of immediately overwriting them with input. + if _special_active or _hurt_animation_timer > 0.0: + var braking: float = 110.0 if _special_active else 550.0 + velocity.x = move_toward(velocity.x, 0.0, braking * delta) + return var direction: float = Input.get_axis("move_left", "move_right") - if direction != 0.0: + if direction != 0.0 and punch_timer <= 0.0: facing_direction = signf(direction) _update_facing() @@ -385,6 +413,8 @@ func _update_jump_windows(delta: float) -> void: func _handle_jump() -> void: + if _special_active or _hurt_animation_timer > 0.0: + return if ( jump_buffer_timer > 0.0 and not ground_pound_active @@ -408,6 +438,8 @@ func _handle_jump() -> void: # ============================================================================ func _handle_attack_input() -> void: + if _special_active or _hurt_animation_timer > 0.0: + return if Input.is_action_just_pressed("attack"): _start_punch() return @@ -429,14 +461,23 @@ func _handle_attack_input() -> void: # ============================================================================ func _start_punch() -> void: + if is_dead or _special_active or ground_pound_active or attack_cooldown_timer > 0.0: + return punch_timer = punch_duration - attack_cooldown_timer = punch_cooldown + attack_cooldown_timer = maxf(punch_cooldown, punch_duration) + _punch_swing_shown = false punch_hit_targets.clear() func _update_punch_damage() -> void: if punch_timer <= 0.0: return + var elapsed: float = punch_duration - punch_timer + if elapsed < punch_windup or elapsed > punch_windup + punch_active_duration: + return + if not _punch_swing_shown: + _punch_swing_shown = true + COMBAT_FX.spawn(get_parent(), punch_hitbox.global_position, &"swing", facing_direction) for area in punch_hitbox.get_overlapping_areas(): _damage_target(area, roundi(character_data.basic_attack_damage * (1.0 + _damage_boost_multiplier)), punch_hit_targets) @@ -447,9 +488,10 @@ func _update_punch_damage() -> void: # ============================================================================ func _start_ground_pound() -> void: - if ground_pound_active: + if is_dead or _special_active or ground_pound_active: return + punch_timer = 0.0 ground_pound_active = true attack_cooldown_timer = punch_cooldown @@ -461,6 +503,10 @@ func _start_ground_pound() -> void: func _ground_pound_impact() -> void: ground_pound_active = false ground_pound_debug_timer = debug_impact_duration + _landing_animation_timer = 0.20 + COMBAT_FX.spawn(get_parent(), global_position + Vector2(0, 26), + &"ground_pound", facing_direction, ground_pound_radius) + feedback_camera.call("impact", 2.8, 0.24) # Damage scales with jump height: how high the player rose from the takeoff # point, clamped between the min and max damage. @@ -482,8 +528,15 @@ func _ground_pound_impact() -> void: roundi(damage * (1.0 + _damage_boost_multiplier + _air_damage_boost_multiplier)), ground_pound_max_damage ) - for area in ground_pound_hitbox.get_overlapping_areas(): - _damage_target(area, final_damage, hit_targets) + # Query at the resolved landing position, not last frame's cached overlaps. + var query := PhysicsShapeQueryParameters2D.new() + query.shape = ground_pound_collision.shape + query.transform = ground_pound_collision.global_transform + query.collision_mask = ENEMY_HURTBOX_MASK + query.collide_with_areas = true + query.collide_with_bodies = false + for hit: Dictionary in get_world_2d().direct_space_state.intersect_shape(query, 64): + _damage_target(hit["collider"], final_damage, hit_targets) # ============================================================================ @@ -491,59 +544,77 @@ func _ground_pound_impact() -> void: # ============================================================================ func _start_special_attack() -> void: - if is_dead: + if is_dead or _special_active or ground_pound_active or special_max_charge <= 0: + return + if special_charge <= 0 or special_charge < special_min_use_charge: return - if special_charge < special_min_use_charge: - return - - var charge_used: int = special_charge - # Consume all current charge + _special_charge_used = special_charge special_charge = 0 special_charge_changed.emit(special_charge, special_max_charge) - - _apply_special_attack(charge_used) + _special_active = true + _special_elapsed = 0.0 + _special_pulses_sent = 0 + _special_damage_budgets.clear() + _special_damage_dealt.clear() + punch_timer = 0.0 + velocity.x = 0.0 + feedback_camera.call("start_solo", special_duration) + _spawn_floating_text("GUITAR SOLO!", Color(0.76, 0.85, 1.0)) -func _apply_special_attack(charge_used: int = special_max_charge) -> void: - var charge_ratio: float = clamp(float(charge_used) / float(special_max_charge), 0.0, 1.0) +func _update_special_attack(delta: float) -> void: + if not _special_active: + return + _special_elapsed += delta + var pulse_count: int = maxi(special_pulse_count, 1) + var windup: float = special_duration * 0.15 + var interval: float = special_duration * 0.65 / float(maxi(pulse_count - 1, 1)) + # Catch up when a long frame spans a pulse, without replaying previous pulses. + while _special_pulses_sent < pulse_count: + if _special_elapsed < windup + interval * float(_special_pulses_sent): + break + _apply_special_attack(_special_charge_used, _special_pulses_sent) + _special_pulses_sent += 1 + var effect_radius: float = minf(special_radius, 300.0) if special_radius > 0.0 else 300.0 + COMBAT_FX.spawn(get_parent(), global_position, &"solo", facing_direction, effect_radius) + feedback_camera.call("impact", 2.0, 0.18, Color(0.61, 0.82, 1.0)) + velocity.x = -facing_direction * 35.0 + if _special_elapsed >= special_duration: + _special_active = false + _special_damage_budgets.clear() + _special_damage_dealt.clear() - var hit_targets: Dictionary = {} - # Get viewport size to scale falloff across the whole screen - var viewport: Viewport = get_viewport() - var viewport_rect: Rect2 = viewport.get_visible_rect() - var max_distance: float = max(viewport_rect.size.x, viewport_rect.size.y) * 0.8 - if max_distance < 1.0: - max_distance = special_radius +func _apply_special_attack(charge_used: int, pulse_index: int = 0) -> void: + var charge_ratio: float = clampf(float(charge_used) / float(maxi(special_max_charge, 1)), 0.0, 1.0) + var viewport_rect: Rect2 = get_viewport().get_visible_rect() + var max_distance: float = maxf(maxf(viewport_rect.size.x, viewport_rect.size.y) * 0.8, 1.0) + var pulse_count: int = maxi(special_pulse_count, 1) - for enemy in get_tree().get_nodes_in_group("enemy"): - if not is_instance_valid(enemy): + for node: Node in get_tree().get_nodes_in_group("enemy"): + var enemy := node as Node2D + if enemy == null or not enemy.has_method("take_damage") or bool(enemy.get("is_dead")): continue - - if not enemy.has_method("take_damage"): - continue - var distance: float = global_position.distance_to(enemy.global_position) if special_radius > 0.0 and distance > special_radius: continue - # Damage falls off with distance: maximum at the player, lower farther away - # affects the whole screen (no hard circle cutoff) - var distance_factor: float = 1.0 - clamp(distance / max_distance, 0.0, 1.0) - # Ensure it still affects even if very far, just minimal - if distance_factor < 0.1: - distance_factor = 0.1 - - var damage: int = int(special_max_damage * charge_ratio * distance_factor) - if damage < 1: - damage = 1 - - var enemy_id: int = enemy.get_instance_id() - if hit_targets.has(enemy_id): + # A screen attack should not silently damage enemies at the far end of the map. + if not viewport_rect.grow(28.0).has_point(enemy.get_global_transform_with_canvas().origin): continue - hit_targets[enemy_id] = true - enemy.take_damage(damage, global_position) + var enemy_id: int = enemy.get_instance_id() + if not _special_damage_budgets.has(enemy_id): + var distance_factor: float = maxf(0.1, 1.0 - clampf(distance / max_distance, 0.0, 1.0)) + _special_damage_budgets[enemy_id] = maxi(1, int(special_max_damage * charge_ratio * distance_factor)) + # Freeze the budget on first contact: knockback must not change total damage. + var total_damage: int = int(_special_damage_budgets[enemy_id]) + var cumulative_damage: int = ceili(float(total_damage) * float(pulse_index + 1) / float(pulse_count)) + var damage: int = cumulative_damage - int(_special_damage_dealt.get(enemy_id, 0)) + if damage <= 0: + continue + _special_damage_dealt[enemy_id] = cumulative_damage + enemy.call("take_damage", damage, global_position) func collect_pickup(data: PickupData) -> bool: @@ -627,7 +698,7 @@ func _connect_to_enemies() -> void: enemy.connect(&"died", _on_enemy_died.bind(enemy)) -func _on_enemy_died(enemy: Node) -> void: +func _on_enemy_died(_enemy: Node) -> void: if is_dead: return @@ -682,6 +753,11 @@ func take_damage(amount: int, source_position: Vector2) -> void: velocity.x = knockback_direction * damage_knockback.x velocity.y = -damage_knockback.y + _hurt_animation_timer = 0.18 + punch_timer = 0.0 + ground_pound_active = false + COMBAT_FX.spawn(get_parent(), global_position, &"hit", knockback_direction) + feedback_camera.call("impact", 1.5, 0.18) health_changed.emit(current_health, character_data.max_health) @@ -691,6 +767,8 @@ func take_damage(amount: int, source_position: Vector2) -> void: func _die() -> void: is_dead = true + _special_active = false + feedback_camera.call("start_solo", 0.0) died.emit() # Reloading from a deferred call avoids changing the scene tree while a @@ -707,6 +785,8 @@ func _reload_level() -> void: # ============================================================================ func _update_timers(delta: float) -> void: + _hurt_animation_timer = maxf(0.0, _hurt_animation_timer - delta) + _landing_animation_timer = maxf(0.0, _landing_animation_timer - delta) punch_timer = max(punch_timer - delta, 0.0) attack_cooldown_timer = max(attack_cooldown_timer - delta, 0.0) ground_pound_debug_timer = max(ground_pound_debug_timer - delta, 0.0) @@ -731,13 +811,44 @@ func _update_timers(delta: float) -> void: func _update_animation() -> void: - # There are only idle and walk animations at the moment. Until proper jump - # and attack animations arrive, walk is used only for horizontal walking and - # idle is the safe fallback for every other state. - if is_on_floor() and abs(velocity.x) > 10.0: - animated_sprite.play("walk") + var animation_name: StringName = &"idle" + if _special_active: + if _special_elapsed < special_duration * 0.15: + animation_name = &"special_start" + elif _special_elapsed > special_duration * 0.85: + animation_name = &"special_end" + else: + animation_name = &"special" + elif _hurt_animation_timer > 0.0: + animation_name = &"hurt" + elif ground_pound_active: + animation_name = &"ground_pound" + elif punch_timer > 0.0: + animation_name = &"punch" + elif not is_on_floor(): + animation_name = &"jump" if velocity.y < 0.0 else &"fall" + elif _landing_animation_timer > 0.0: + animation_name = &"land" + elif absf(velocity.x) > 10.0: + animation_name = &"walk" + + # Custom CharacterData can still provide a smaller animation set. + if not animated_sprite.sprite_frames.has_animation(animation_name): + animation_name = &"idle" + if animated_sprite.animation != animation_name or not animated_sprite.is_playing(): + # Finished one-shot animations hold their last frame until the state changes. + if animated_sprite.animation == animation_name and animated_sprite.frame > 0: + return + animated_sprite.play(animation_name) + + +func _update_visual_feedback() -> void: + if _hurt_animation_timer > 0.10: + animated_sprite.self_modulate = Color(1.8, 1.8, 1.8) + elif invulnerability_timer > 0.0 and int(invulnerability_timer * 12.0) % 2 == 0: + animated_sprite.self_modulate = Color(1.0, 1.0, 1.0, 0.55) else: - animated_sprite.play("idle") + animated_sprite.self_modulate = Color.WHITE # ============================================================================ @@ -766,6 +877,18 @@ func _setup_attack_hitboxes() -> void: # ============================================================================ func _draw() -> void: + if is_on_floor(): + draw_rect(Rect2(-14, 24, 28, 3), Color(0.05, 0.06, 0.10, 0.25)) + if ground_pound_active: + for side: float in [-1.0, 1.0]: + draw_line(Vector2(17 * side, -30), Vector2(17 * side, -9), Color(1.0, 0.8, 0.45, 0.75), 2.0) + # Pickup messages remain visible when collision debugging is disabled. + var font: Font = ThemeDB.get_default_theme().get_font("font", "Label") + if font != null: + for entry: Dictionary in _floating_texts: + var text_color: Color = entry.color + text_color.a = clampf(float(entry.timer) / 1.2, 0.0, 1.0) + draw_string(font, entry.pos, entry.text, HORIZONTAL_ALIGNMENT_LEFT, -1, 14, text_color) if not show_debug_hitboxes: return @@ -828,13 +951,6 @@ 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( diff --git a/player/player.tscn b/player/player.tscn index 6370739..8f60cf1 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -8,7 +8,7 @@ [ext_resource type="PackedScene" path="res://ui/hud/special_charge_hud.tscn" id="6_special_charge_hud"] [sub_resource type="RectangleShape2D" id="PlayerShape"] -size = Vector2(41, 74) +size = Vector2(26, 52) [node name="Player" type="CharacterBody2D" unique_id=730885194 groups=["player"]] z_index = 1 @@ -43,10 +43,11 @@ monitorable = false [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1502470275] z_index = -1 -scale = Vector2(0.56, 0.56) +texture_filter = 1 +position = Vector2(0, -2) sprite_frames = ExtResource("2_frames") animation = &"idle" -speed_scale = 2.0 +speed_scale = 1.0 [node name="Camera2D" type="Camera2D" parent="." unique_id=902833396] zoom = Vector2(2, 2) diff --git a/tests/test_pixel_combat_resources.py b/tests/test_pixel_combat_resources.py new file mode 100644 index 0000000..5f078aa --- /dev/null +++ b/tests/test_pixel_combat_resources.py @@ -0,0 +1,62 @@ +"""Engine-independent checks. Run: python -m unittest discover -s tests -v.""" +from pathlib import Path +import math +import re +import unittest +import xml.etree.ElementTree as ET + +ROOT = Path(__file__).resolve().parents[1] +FRAMES = ROOT / "player/characters/shared/prototype_sprite_frames.tres" + + +class PixelCombatResourceTests(unittest.TestCase): + def test_all_animation_cells_exist_and_fit_atlas(self): + text = FRAMES.read_text(encoding="utf-8") + atlas = ET.parse(ROOT / "assets/characters/ankarde/player_pixel.svg").getroot() + width, height = int(atlas.attrib["width"]), int(atlas.attrib["height"]) + declared = re.findall(r'\[sub_resource type="AtlasTexture" id="([^"]+)"\]', text) + used = re.findall(r'SubResource\("([^"]+)"\)', text) + self.assertEqual(len(declared), 37) + self.assertEqual(set(declared), set(used)) + self.assertEqual(len(declared), len(set(declared))) + for x, y, w, h in re.findall(r'region = Rect2\((\d+), (\d+), (\d+), (\d+)\)', text): + x, y, w, h = map(int, (x, y, w, h)) + self.assertEqual((w, h), (64, 64)) + self.assertLessEqual(x + w, width) + self.assertLessEqual(y + h, height) + + def test_player_poses_and_pixel_scale(self): + names = set(re.findall(r'"name": &"([^"]+)"', FRAMES.read_text())) + self.assertEqual(names, {"idle", "walk", "jump", "fall", "punch", "ground_pound", + "land", "special_start", "special", "special_end", "hurt"}) + scene = (ROOT / "player/player.tscn").read_text() + self.assertIn("size = Vector2(26, 52)", scene) + self.assertIn("texture_filter = 1", scene) + self.assertNotIn("scale = Vector2(0.56, 0.56)", scene) + self.assertIn("speed_scale = 1.0", scene) + + def test_new_asset_has_no_external_dependencies(self): + atlas = ET.parse(ROOT / "assets/characters/ankarde/player_pixel.svg").getroot() + self.assertEqual(atlas.attrib["shape-rendering"], "crispEdges") + self.assertFalse(list(atlas.iter("{http://www.w3.org/2000/svg}image"))) + self.assertFalse(list(atlas.iter("{http://www.w3.org/2000/svg}text"))) + for rel in ("player/player.gd", "enemies/walker/walker.gd", str(FRAMES.relative_to(ROOT))): + for path in re.findall(r'res://([^"\s]+)', (ROOT / rel).read_text()): + self.assertTrue((ROOT / path).is_file(), path) + + def test_pulse_rounding_preserves_the_damage_budget(self): + # Mathematical invariant used by the GDScript cumulative damage formula. + # Runtime behaviour is covered separately by test_pixel_combat_runtime.gd. + for total in range(1, 101): + for count in range(1, 9): + dealt = 0 + for index in range(count): + cumulative = math.ceil(total * (index + 1) / count) + damage = cumulative - dealt + self.assertGreaterEqual(damage, 0) + dealt = cumulative + self.assertEqual(dealt, total) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_pixel_combat_runtime.gd b/tests/test_pixel_combat_runtime.gd new file mode 100644 index 0000000..52476dc --- /dev/null +++ b/tests/test_pixel_combat_runtime.gd @@ -0,0 +1,134 @@ +extends SceneTree + +## Run after importing assets: +## godot --headless --path . --script res://tests/test_pixel_combat_runtime.gd +## Tests actual scene instantiation, pulse damage, death lifecycle and respawn. + +var _failures: int = 0 +var _death_signals: int = 0 + + +func _initialize() -> void: + call_deferred("_run") + + +func _run() -> void: + var packed: PackedScene = load("res://levels/level_02.tscn") as PackedScene + if packed == null: + push_error("Cannot load Level02") + quit(1) + return + var level: Node2D = packed.instantiate() as Node2D + if level == null: + push_error("Cannot instantiate Level02") + quit(1) + return + root.add_child(level) + current_scene = level + await process_frame + await physics_frame + + var player: CharacterBody2D = level.get_node("Player") as CharacterBody2D + var sprite: AnimatedSprite2D = player.get_node("AnimatedSprite2D") as AnimatedSprite2D + for animation: StringName in [&"idle", &"walk", &"jump", &"fall", &"punch", &"ground_pound", + &"land", &"special_start", &"special", &"special_end", &"hurt"]: + _check(sprite.sprite_frames.has_animation(animation), "Missing animation: " + str(animation)) + if sprite.sprite_frames.has_animation(animation): + for index: int in range(sprite.sprite_frames.get_frame_count(animation)): + _check(sprite.sprite_frames.get_frame_texture(animation, index) != null, + "Missing texture in " + str(animation)) + + # Keep positions fixed, so pulse falloff and screen clipping are deterministic. + player.set_physics_process(false) + for node: Node in get_nodes_in_group("enemy"): + node.set_physics_process(false) + node.set("is_dead", true) + var enemy: CharacterBody2D = level.get_node("Enemies").get_child(0) as CharacterBody2D + enemy.set("is_dead", false) + enemy.set("max_health", 200) + enemy.set("current_health", 200) + enemy.set("respawn_delay", 0.0) + enemy.set("drops_handled_by_level", true) + enemy.global_position = player.global_position + Vector2(50, 0) + var camera: Camera2D = player.get_node("Camera2D") as Camera2D + camera.force_update_scroll() + await process_frame + + player.set("special_charge", 100) + player.call("_start_special_attack") + player.call("_update_animation") + _check(sprite.animation == &"special_start", "Solo must draw the guitar first") + _check(int(player.get("special_charge")) == 0, "Charge must be consumed once") + _check(int(enemy.get("current_health")) == 200, "No instant special damage") + player.set("special_charge", 50) + player.call("_start_special_attack") + _check(int(player.get("special_charge")) == 50, "Cannot recast during the solo") + player.call("_start_punch") + _check(float(player.get("punch_timer")) == 0.0, "Cannot punch during the solo") + + player.call("_update_special_attack", 0.35) + _check(int(enemy.get("current_health")) == 200, "Damage must wait for the windup") + player.call("_update_special_attack", 0.02) + _check(int(enemy.get("current_health")) < 200, "First solo pulse must hit") + var budgets: Dictionary = player.get("_special_damage_budgets") + var budget: int = int(budgets.get(enemy.get_instance_id(), 0)) + _check(budget > 0 and budget <= 30, "Invalid per-enemy special budget") + player.call("_update_special_attack", 2.1) + _check(not bool(player.get("_special_active")), "Solo must finish") + _check(int(player.get("_special_pulses_sent")) == 4, "Exactly four pulses") + _check(200 - int(enemy.get("current_health")) == budget, "Pulses must not multiply damage") + _check(enemy.velocity.x > 0.0 and player.velocity.x < 0.0, "Missing hit/recoil impulses") + var health_after_solo: int = int(enemy.get("current_health")) + player.call("_update_special_attack", 1.0) + _check(int(enemy.get("current_health")) == health_after_solo, "No damage after the solo") + + enemy.connect(&"died", _on_test_enemy_died) + var charge_before_death: int = int(player.get("special_charge")) + enemy.call("take_damage", 1000, player.global_position) + _check(bool(enemy.get("is_dead")), "Logical death must be immediate") + _check(enemy.visible, "Enemy must not disappear at zero HP") + _check(_death_signals == 1, "Death signal must fire once") + enemy.call("take_damage", 1000, player.global_position) + _check(_death_signals == 1, "Repeated hits must not produce another death") + _check(int(player.get("special_charge")) == mini(100, charge_before_death + 25), + "Death must grant special charge exactly once") + enemy.call("_update_death_animation", 0.20) + var enemy_visual: Sprite2D = enemy.get_node("Visual") as Sprite2D + _check(enemy.visible and not is_zero_approx(enemy_visual.rotation), "Missing collapse animation") + enemy.call("_update_death_animation", 1.0) + _check(not enemy.visible, "Enemy must hide after the death animation") + _check(is_instance_valid(enemy), "Keep the dead node for level KO/total tracking") + enemy.call("_respawn") + enemy.set_physics_process(false) + _check(enemy.visible and not bool(enemy.get("is_dead")), "Respawn state was not restored") + _check(is_zero_approx(enemy_visual.rotation) and is_equal_approx(enemy_visual.self_modulate.a, 1.0), + "Respawn must restore the sprite transform and opacity") + + # Shape query uses the new landing position, with combat shapes restored. + enemy.global_position = player.global_position + Vector2(30, 0) + enemy.set("max_health", 50) + enemy.set("current_health", 50) + await physics_frame + await physics_frame + player.set("_jump_start_position", player.global_position) + player.set("_jump_peak_height", player.global_position.y - 300.0) + player.call("_ground_pound_impact") + _check(int(enemy.get("current_health")) == 38, "High ground pound must deal exactly 12 damage") + + # Exercise effect processing/cleanup, not just resource loading. + await create_timer(0.8).timeout + if _failures == 0: + print("OK PIXEL COMBAT: animations, solo pulses, recoil, death, rewards, respawn and ground pound") + else: + push_error("PIXEL COMBAT: %d failed checks" % _failures) + quit(0 if _failures == 0 else 1) + + +func _on_test_enemy_died() -> void: + _death_signals += 1 + + +func _check(condition: bool, message: String) -> void: + if not condition: + _failures += 1 + push_error(message)