forked from tas/major_tom
Change exit ship trigger from proximity distance to exit zone overlap
This commit is contained in:
@@ -362,10 +362,6 @@ static void handle_collisions(EntityManager *em) {
|
||||
|
||||
/* ── 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.
|
||||
* The ship lands a bit to the left of the exit zone so the player walks
|
||||
* rightward into it. */
|
||||
@@ -391,8 +387,8 @@ static Entity *find_exit_ship(EntityManager *em) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Spawn the exit ship when the player gets close to an exit zone. */
|
||||
static void check_exit_ship_proximity(Level *level) {
|
||||
/* Spawn the exit ship when the player touches an exit zone. */
|
||||
static void check_exit_ship_trigger(Level *level) {
|
||||
if (level->exit_triggered) return;
|
||||
if (level->exit_ship_spawned) 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);
|
||||
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++) {
|
||||
const ExitZone *ez = &level->map.exit_zones[i];
|
||||
Vec2 ez_center = vec2(ez->x + ez->w * 0.5f, ez->y + ez->h * 0.5f);
|
||||
float dx = pc.x - ez_center.x;
|
||||
float dy = pc.y - ez_center.y;
|
||||
float dist = sqrtf(dx * dx + dy * dy);
|
||||
|
||||
if (dist < EXIT_SHIP_TRIGGER_DIST) {
|
||||
if (physics_aabb_overlap(
|
||||
player->body.pos, player->body.size,
|
||||
vec2(ez->x, ez->y), vec2(ez->w, ez->h))) {
|
||||
/* Land the ship so its bottom aligns with the exit zone bottom.
|
||||
* 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;
|
||||
@@ -423,7 +411,7 @@ static void check_exit_ship_proximity(Level *level) {
|
||||
if (ship) {
|
||||
level->exit_ship_spawned = true;
|
||||
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;
|
||||
}
|
||||
@@ -545,7 +533,7 @@ void level_update(Level *level, float dt) {
|
||||
handle_collisions(&level->entities);
|
||||
|
||||
/* Exit ship: proximity trigger + boarding/departure */
|
||||
check_exit_ship_proximity(level);
|
||||
check_exit_ship_trigger(level);
|
||||
update_exit_ship(level);
|
||||
|
||||
/* Fallback direct exit zone check (for levels without ship exit) */
|
||||
|
||||
Reference in New Issue
Block a user