Animaciones
This commit is contained in:
1 parent
b365c79251
commit
8a5290c5ef
10 files changed
+1581
-288
No files matched your search
+180
-64
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user