summaryrefslogtreecommitdiff
path: root/platformer/src/main.c
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2026-09-29 22:28:37 -0400
committerSchark <jordan@schark.online>2026-09-29 22:28:37 -0400
commitfdc8c951fc72d9dc4c8faa58a21b2b9de0599698 (patch)
treeedd9934a43429508acb9ec37da71eb172dc788e9 /platformer/src/main.c
parentadb6a882870464490a8026aed1f66b21b0e72477 (diff)
downloadgamedev-fdc8c951fc72d9dc4c8faa58a21b2b9de0599698.tar.gz
gamedev-fdc8c951fc72d9dc4c8faa58a21b2b9de0599698.zip
Implemented no-panning zones
Diffstat (limited to 'platformer/src/main.c')
-rw-r--r--platformer/src/main.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/platformer/src/main.c b/platformer/src/main.c
index 23f06d2..8e1d139 100644
--- a/platformer/src/main.c
+++ b/platformer/src/main.c
@@ -38,8 +38,9 @@
* player_reset(&player, world_spawn_point());
* camera_init(&camera, player.body.pos); // see WHY below
* player_update(&player, &input, camera_yaw(&camera), TICK_DT);
+ * pan_locked = world_in_zone(player's body center, ZONE_LOCKED_PAN);
* camera_update(&camera, &input, player.body.pos, player.facing_yaw,
- * window_aspect(), TICK_DT);
+ * pan_locked, window_aspect(), TICK_DT);
* accumulator -= TICK_DT;
*
* render_frame(&camera, &player, window_aspect(), fps);
@@ -98,17 +99,18 @@
/* Our "HUD" until text rendering exists: live state in the title bar.
* Updating a few times per second keeps it readable (and cheap). */
-static void update_debug_title(const Player *player, const Input *input)
+static void update_debug_title(const Player *player, const Input *input, bool pan_locked)
{
- char title[128];
- snprintf(title, sizeof title, "%s | %s | speed %.2f m/s | y %.2f | %s%s%s",
+ char title[160];
+ snprintf(title, sizeof title, "%s | %s | speed %.2f m/s | y %.2f | %s%s%s%s",
WINDOW_TITLE,
player_state_name(player->state),
player->forward_speed,
player->body.pos.y,
input->using_gamepad ? "pad" : "keyboard",
player->heightened_movement ? " | heightened" : "",
- player->retreating_movement ? " | retreating" : "");
+ player->retreating_movement ? " | retreating" : "",
+ pan_locked ? " | pan locked" : "");
window_set_title(title);
}
@@ -138,6 +140,7 @@ int main(void)
* frame, which is exactly what you need when tuning movement. SM64 ran its
* logic at 30 Hz; we use TICK_HZ. */
Input input = { 0 };
+ bool pan_locked = false; /* the player is in a locked-pan zone (for the camera and the title) */
double previous = window_time();
double accumulator = 0.0;
double last_title_time = 0.0;
@@ -172,8 +175,11 @@ int main(void)
/* Player before camera, so the camera follows where the player IS,
* not where it was a tick ago. SM64 updates Mario before the camera too. */
player_update(&player, &input, camera_yaw(&camera), TICK_DT);
+ /* In a locked-pan zone the camera doesn't swing behind the player. */
+ Vec3 body_center = vec3_add(player.body.pos, vec3_make(0.0f, 0.5f * PLAYER_HEIGHT, 0.0f));
+ pan_locked = world_in_zone(body_center, ZONE_LOCKED_PAN);
camera_update(&camera, &input, player.body.pos, player.facing_yaw,
- window_aspect(), TICK_DT);
+ pan_locked, window_aspect(), TICK_DT);
accumulator -= TICK_DT;
}
@@ -190,7 +196,7 @@ int main(void)
}
if (now - last_title_time >= TITLE_UPDATE_INTERVAL) {
- update_debug_title(&player, &input);
+ update_debug_title(&player, &input, pan_locked);
last_title_time = now;
}
}