Expand and stage boss encounter

This commit is contained in:
Loïc Wisniewski 2026-09-03 22:00:26 +02:00
commit 66b314f51a
17 changed files with 485 additions and 64 deletions

View file

@ -9,9 +9,16 @@ const COMBAT_TARGET = preload("res://core/CombatTarget.gd")
@export var max_hp: int = 5
@export var speed: float = 245.0
@export var acceleration: float = 520.0
@export var expulsion_speed: float = 520.0
@export var dash_speed: float = 760.0
var boss: Node2D
const REDRAW_INTERVAL: float = 1.0 / 12.0
const EXPULSION_SECONDS: float = 0.85
const BRAKE_SECONDS: float = 0.42
const DASH_SECONDS: float = 0.48
enum Motion { EXPELLED, CHASING, BRAKING, DASHING }
var hp: int = 5
var velocity: Vector2 = Vector2.ZERO
@ -19,6 +26,11 @@ var phase: float = 0.0
var dead: bool = false
var redraw_left: float = 0.0
var fleet: Node2D = null
var motion: int = Motion.CHASING
var motion_left: float = 0.0
var dash_cooldown: float = 0.0
var dash_direction: Vector2 = Vector2.ZERO
var uses_dash_pattern: bool = false
func _ready() -> void:
@ -31,25 +43,71 @@ func _ready() -> void:
queue_redraw()
# The boss throws hatchlings clear of its now much larger silhouette before
# they acquire the fleet. Every third hatchling also gets the stop-and-lunge
# rhythm requested in #189; the others remain steady pursuers so a wave is
# varied rather than uniformly twitchy.
func expel(direction: Vector2, dashes: bool) -> void:
var outward: Vector2 = direction.normalized()
uses_dash_pattern = dashes
motion = Motion.EXPELLED
motion_left = EXPULSION_SECONDS * randf_range(0.8, 1.2)
velocity = outward * expulsion_speed * randf_range(0.85, 1.15)
dash_cooldown = randf_range(1.2, 2.8)
func _physics_process(delta: float) -> void:
phase += delta
if not is_instance_valid(fleet):
fleet = get_tree().get_first_node_in_group("player_fleet")
if fleet != null and not fleet.ships.is_empty():
var to_fleet: Vector2 = fleet.get_centroid() - global_position
if to_fleet.length() > 1.0:
velocity = velocity.move_toward(to_fleet.normalized() * speed,
acceleration * delta)
global_position += velocity * delta
if velocity.length() > 4.0:
rotation = lerp_angle(rotation, velocity.angle() + PI / 2.0,
7.0 * delta)
_update_motion(delta)
global_position += velocity * delta
if velocity.length() > 4.0:
rotation = lerp_angle(rotation, velocity.angle() + PI / 2.0,
7.0 * delta)
redraw_left -= delta
if redraw_left <= 0.0:
redraw_left = REDRAW_INTERVAL
queue_redraw()
func _update_motion(delta: float) -> void:
if motion == Motion.EXPELLED:
motion_left -= delta
if motion_left <= 0.0:
motion = Motion.CHASING
return
if fleet == null or fleet.ships.is_empty():
velocity = velocity.move_toward(Vector2.ZERO, acceleration * delta)
return
var to_fleet: Vector2 = fleet.get_centroid() - global_position
if motion == Motion.BRAKING:
motion_left -= delta
velocity = velocity.move_toward(Vector2.ZERO, acceleration * 2.2 * delta)
if motion_left <= 0.0:
motion = Motion.DASHING
motion_left = DASH_SECONDS
dash_direction = to_fleet.normalized().rotated(randf_range(-0.42, 0.42))
return
if motion == Motion.DASHING:
motion_left -= delta
velocity = velocity.move_toward(dash_direction * dash_speed,
acceleration * 4.0 * delta)
if motion_left <= 0.0:
motion = Motion.CHASING
dash_cooldown = randf_range(1.8, 3.8)
return
if uses_dash_pattern:
dash_cooldown -= delta
if dash_cooldown <= 0.0:
motion = Motion.BRAKING
motion_left = BRAKE_SECONDS
return
if to_fleet.length() > 1.0:
velocity = velocity.move_toward(to_fleet.normalized() * speed,
acceleration * delta)
func take_damage(amount: int) -> bool:
if dead:
return false