➕ADD: Ataques y hud de energia mejorados
This commit is contained in:
1 parent
5d87de8ca1
commit
9b32d97d1f
6 files changed
+245
-12
No files matched your search
+164
-10
@@ -3,6 +3,7 @@ extends CharacterBody2D
|
||||
|
||||
signal health_changed(current_health: int, max_health: int)
|
||||
signal died
|
||||
signal special_charge_changed(current_charge: int, max_charge: int)
|
||||
|
||||
|
||||
# Collision layers used by this first playable slice.
|
||||
@@ -111,6 +112,33 @@ const ENEMY_HURTBOX_MASK: int = 1 << 4
|
||||
@export var ground_pound_radius: float = 85.0
|
||||
@export var ground_pound_offset: Vector2 = Vector2(0.0, 28.0)
|
||||
|
||||
## Damage per pixel of jump height. Higher jumps deal more damage, up to the max.
|
||||
@export var ground_pound_damage_per_pixel: float = 0.03
|
||||
@export_range(1, 100, 1) var ground_pound_min_damage: int = 1
|
||||
@export_range(1, 100, 1) var ground_pound_max_damage: int = 10
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# SPECIAL ATTACK
|
||||
# ============================================================================
|
||||
|
||||
@export_category("Special Attack")
|
||||
|
||||
## Maximum charge of the special meter (0-100).
|
||||
@export_range(0, 100, 1) var special_max_charge: int = 100
|
||||
|
||||
## Charge gained when an enemy dies.
|
||||
@export_range(0, 100, 1) var special_charge_per_kill: int = 25
|
||||
|
||||
## Minimum damage dealt by the special (scales up with charge).
|
||||
@export_range(0, 100, 1) var special_min_damage: int = 3
|
||||
|
||||
## Maximum damage dealt by the special (at full charge, point-blank).
|
||||
@export_range(0, 100, 1) var special_max_damage: int = 8
|
||||
|
||||
## Radius of the radial special attack in pixels.
|
||||
@export var special_radius: float = 200.0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# DEBUG
|
||||
@@ -156,10 +184,18 @@ var ground_pound_active: bool = false
|
||||
var ground_pound_debug_timer: float = 0.0
|
||||
var is_dead: bool = false
|
||||
|
||||
# Tracks the highest point reached since leaving the ground, used to scale
|
||||
# ground pound damage by jump height instead of fall distance.
|
||||
var _jump_height_tracking: bool = false
|
||||
var _jump_start_position: Vector2
|
||||
var _jump_peak_height: float = 0.0
|
||||
|
||||
## Prevents one target from receiving damage every physics frame during the
|
||||
## same punch. A new punch starts with an empty set again.
|
||||
var punch_hit_targets: Dictionary = {}
|
||||
|
||||
var special_charge: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if character_data == null:
|
||||
@@ -174,6 +210,8 @@ func _ready() -> void:
|
||||
_update_facing()
|
||||
_update_animation()
|
||||
health_changed.emit(current_health, character_data.max_health)
|
||||
special_charge_changed.emit(special_charge, special_max_charge)
|
||||
_connect_to_enemies()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -192,6 +230,18 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
move_and_slide()
|
||||
|
||||
# Track the highest point reached since leaving the ground, so ground pound
|
||||
# damage is based on jump height rather than the current fall distance.
|
||||
if not is_on_floor():
|
||||
if not _jump_height_tracking:
|
||||
_jump_height_tracking = true
|
||||
_jump_start_position = global_position
|
||||
_jump_peak_height = global_position.y
|
||||
else:
|
||||
_jump_peak_height = min(_jump_peak_height, global_position.y)
|
||||
elif _jump_height_tracking:
|
||||
_jump_height_tracking = false
|
||||
|
||||
# Landing is only reliable after move_and_slide() has resolved collisions.
|
||||
if ground_pound_active and not was_on_floor and is_on_floor():
|
||||
_ground_pound_impact()
|
||||
@@ -302,16 +352,20 @@ func _handle_jump() -> void:
|
||||
# ============================================================================
|
||||
|
||||
func _handle_attack_input() -> void:
|
||||
if not Input.is_action_just_pressed("attack"):
|
||||
return
|
||||
|
||||
if attack_cooldown_timer > 0.0:
|
||||
return
|
||||
|
||||
if is_on_floor():
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
_start_punch()
|
||||
else:
|
||||
_start_ground_pound()
|
||||
return
|
||||
|
||||
if Input.is_action_just_pressed("ground_pound"):
|
||||
# The ground pound is an air attack: it only triggers while jumping or
|
||||
# falling, so it never replaces a grounded punch.
|
||||
if not is_on_floor():
|
||||
_start_ground_pound()
|
||||
return
|
||||
|
||||
if Input.is_action_just_pressed("special_attack"):
|
||||
_start_special_attack()
|
||||
return
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -352,10 +406,88 @@ func _ground_pound_impact() -> void:
|
||||
ground_pound_active = false
|
||||
ground_pound_debug_timer = debug_impact_duration
|
||||
|
||||
# Damage scales with jump height: how high the player rose from the takeoff
|
||||
# point, clamped between the min and max damage.
|
||||
var height_reached: float = _jump_start_position.y - _jump_peak_height
|
||||
if height_reached < 0.0:
|
||||
height_reached = 0.0
|
||||
|
||||
var damage: int = clamp(
|
||||
int(height_reached * ground_pound_damage_per_pixel),
|
||||
ground_pound_min_damage,
|
||||
ground_pound_max_damage
|
||||
)
|
||||
|
||||
var hit_targets: Dictionary = {}
|
||||
|
||||
for area in ground_pound_hitbox.get_overlapping_areas():
|
||||
_damage_target(area, character_data.air_attack_damage, hit_targets)
|
||||
_damage_target(area, damage, hit_targets)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# SPECIAL ATTACK
|
||||
# ============================================================================
|
||||
|
||||
func _start_special_attack() -> void:
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
if special_charge < special_max_charge:
|
||||
return
|
||||
|
||||
# Consume the full charge.
|
||||
special_charge = 0
|
||||
special_charge_changed.emit(special_charge, special_max_charge)
|
||||
|
||||
_apply_special_attack()
|
||||
|
||||
|
||||
func _apply_special_attack() -> void:
|
||||
# The special requires full charge, so charge_ratio is always 1.0 here.
|
||||
# Partial-charge support can be added later if desired.
|
||||
var charge_ratio: float = 1.0
|
||||
|
||||
var hit_targets: Dictionary = {}
|
||||
|
||||
for enemy in get_tree().get_nodes_in_group("enemy"):
|
||||
if not is_instance_valid(enemy):
|
||||
continue
|
||||
|
||||
if not enemy.has_method("take_damage"):
|
||||
continue
|
||||
|
||||
var distance: float = global_position.distance_to(enemy.global_position)
|
||||
if distance > special_radius:
|
||||
continue
|
||||
|
||||
# Damage falls off with distance: maximum at the player, zero at the edge.
|
||||
var distance_factor: float = 1.0 - clamp(distance / special_radius, 0.0, 1.0)
|
||||
|
||||
var base_damage: float = lerp(special_min_damage, special_max_damage, charge_ratio)
|
||||
var damage: int = int(base_damage * distance_factor)
|
||||
if damage < 1:
|
||||
damage = 1
|
||||
|
||||
var enemy_id: int = enemy.get_instance_id()
|
||||
if hit_targets.has(enemy_id):
|
||||
continue
|
||||
|
||||
hit_targets[enemy_id] = true
|
||||
enemy.take_damage(damage, global_position)
|
||||
|
||||
|
||||
func _connect_to_enemies() -> void:
|
||||
for enemy in get_tree().get_nodes_in_group("enemy"):
|
||||
if is_instance_valid(enemy) and enemy.has_signal(&"died"):
|
||||
enemy.died.connect(_on_enemy_died.bind(enemy))
|
||||
|
||||
|
||||
func _on_enemy_died(enemy: Node) -> void:
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
special_charge = min(special_charge + special_charge_per_kill, special_max_charge)
|
||||
special_charge_changed.emit(special_charge, special_max_charge)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -502,6 +634,28 @@ func _draw() -> void:
|
||||
2.0
|
||||
)
|
||||
|
||||
# Special: show the radial damage area. Brighter when fully charged.
|
||||
if special_charge >= special_max_charge:
|
||||
var fill_alpha: float = 0.18
|
||||
var outline_alpha: float = 0.85
|
||||
else:
|
||||
var fill_alpha: float = 0.08
|
||||
var outline_alpha: float = 0.35
|
||||
draw_circle(
|
||||
Vector2.ZERO,
|
||||
special_radius,
|
||||
Color(1.0, 0.6, 0.05, fill_alpha)
|
||||
)
|
||||
draw_arc(
|
||||
Vector2.ZERO,
|
||||
special_radius,
|
||||
0.0,
|
||||
TAU,
|
||||
48,
|
||||
Color(1.0, 0.6, 0.05, outline_alpha),
|
||||
2.0
|
||||
)
|
||||
|
||||
|
||||
func _draw_rectangle_collision(
|
||||
collision: CollisionShape2D,
|
||||
|
||||
Reference in new issue
Block a user