Change exit ship trigger from proximity distance to exit zone overlap

This commit is contained in:
Thomas
2026-03-01 12:45:07 +00:00
parent ded662b42a
commit 66a97a4beb

View File

@@ -362,10 +362,6 @@ static void handle_collisions(EntityManager *em) {
/* ── Exit zone / exit ship ───────────────────────── */ /* ── Exit zone / exit ship ───────────────────────── */
/* How close the player must be to an exit zone to trigger the exit ship
* fly-in. Roughly 2 screen widths. */
#define EXIT_SHIP_TRIGGER_DIST (SCREEN_WIDTH * 2.0f)
/* Landing offset: where the ship lands relative to the exit zone center. /* Landing offset: where the ship lands relative to the exit zone center.
* The ship lands a bit to the left of the exit zone so the player walks * The ship lands a bit to the left of the exit zone so the player walks
* rightward into it. */ * rightward into it. */
@@ -391,8 +387,8 @@ static Entity *find_exit_ship(EntityManager *em) {
return NULL; return NULL;
} }
/* Spawn the exit ship when the player gets close to an exit zone. */ /* Spawn the exit ship when the player touches an exit zone. */
static void check_exit_ship_proximity(Level *level) { static void check_exit_ship_trigger(Level *level) {
if (level->exit_triggered) return; if (level->exit_triggered) return;
if (level->exit_ship_spawned) return; if (level->exit_ship_spawned) return;
if (level->map.exit_zone_count == 0) return; if (level->map.exit_zone_count == 0) return;
@@ -400,19 +396,11 @@ static void check_exit_ship_proximity(Level *level) {
Entity *player = find_player(&level->entities); Entity *player = find_player(&level->entities);
if (!player) return; if (!player) return;
Vec2 pc = vec2(
player->body.pos.x + player->body.size.x * 0.5f,
player->body.pos.y + player->body.size.y * 0.5f
);
for (int i = 0; i < level->map.exit_zone_count; i++) { for (int i = 0; i < level->map.exit_zone_count; i++) {
const ExitZone *ez = &level->map.exit_zones[i]; const ExitZone *ez = &level->map.exit_zones[i];
Vec2 ez_center = vec2(ez->x + ez->w * 0.5f, ez->y + ez->h * 0.5f); if (physics_aabb_overlap(
float dx = pc.x - ez_center.x; player->body.pos, player->body.size,
float dy = pc.y - ez_center.y; vec2(ez->x, ez->y), vec2(ez->w, ez->h))) {
float dist = sqrtf(dx * dx + dy * dy);
if (dist < EXIT_SHIP_TRIGGER_DIST) {
/* Land the ship so its bottom aligns with the exit zone bottom. /* Land the ship so its bottom aligns with the exit zone bottom.
* land_pos is the top-left of the ship's resting position. */ * land_pos is the top-left of the ship's resting position. */
float land_x = ez->x + ez->w * 0.5f + EXIT_SHIP_LAND_OFFSET_X; float land_x = ez->x + ez->w * 0.5f + EXIT_SHIP_LAND_OFFSET_X;
@@ -423,7 +411,7 @@ static void check_exit_ship_proximity(Level *level) {
if (ship) { if (ship) {
level->exit_ship_spawned = true; level->exit_ship_spawned = true;
level->exit_zone_idx = i; level->exit_zone_idx = i;
printf("Exit ship triggered (zone %d, dist=%.0f)\n", i, dist); printf("Exit ship triggered (zone %d)\n", i);
} }
return; return;
} }
@@ -545,7 +533,7 @@ void level_update(Level *level, float dt) {
handle_collisions(&level->entities); handle_collisions(&level->entities);
/* Exit ship: proximity trigger + boarding/departure */ /* Exit ship: proximity trigger + boarding/departure */
check_exit_ship_proximity(level); check_exit_ship_trigger(level);
update_exit_ship(level); update_exit_ship(level);
/* Fallback direct exit zone check (for levels without ship exit) */ /* Fallback direct exit zone check (for levels without ship exit) */