summaryrefslogtreecommitdiff
path: root/platformer/src/main.c
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2026-09-24 00:06:00 -0400
committerSchark <jordan@schark.online>2026-09-24 00:06:00 -0400
commit5d078ec17b27afd159f8b9a8c1298fcac15d695d (patch)
tree59c2d29d64933e849f17bb50d34ea71b88c13602 /platformer/src/main.c
parent23ef8bc20310bdfad52b07a3f1e4e61c98896841 (diff)
downloadgamedev-5d078ec17b27afd159f8b9a8c1298fcac15d695d.tar.gz
gamedev-5d078ec17b27afd159f8b9a8c1298fcac15d695d.zip
Fix recentering, default button
Diffstat (limited to '')
-rw-r--r--platformer/src/main.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/platformer/src/main.c b/platformer/src/main.c
index 5b11772..8f5e510 100644
--- a/platformer/src/main.c
+++ b/platformer/src/main.c
@@ -32,9 +32,12 @@
* while accumulator >= TICK_DT: // 0, 1 or several ticks
* controls_poll(&input);
* if input.quit_pressed: window_request_close();
- * if input.reset_pressed: player_reset(&player, world_spawn_point());
+ * if input.reset_pressed:
+ * player_reset(&player, world_spawn_point());
+ * camera_init(&camera, player.body.pos); // see WHY below
* player_update(&player, &input, camera_yaw(&camera), TICK_DT);
- * camera_update(&camera, &input, player.body.pos, TICK_DT);
+ * camera_update(&camera, &input, player.body.pos, player.facing_yaw,
+ * window_aspect(), TICK_DT);
* accumulator -= TICK_DT;
*
* render_frame(&camera, &player, window_aspect());
@@ -46,6 +49,9 @@
* ran logic at 30 Hz; we use TICK_HZ (60).
* WHY player before camera: the camera then follows where the player IS,
* not where it was a tick ago. SM64 updates Mario before the camera too.
+ * WHY reset the camera too: the camera frames the player by tracking how
+ * far they moved each tick, so a teleport back to spawn would look like a
+ * 100 m sprint. Re-initializing gives a clean, centered start instead.
*
* - Debug readout for tuning (a few times per second, not every frame):
* window_set_title() with something like
@@ -61,7 +67,8 @@
* NOT IN SCOPE: Menus, pause, command-line args, state interpolation.
*
* DONE WHEN: `make run` opens the window. The player can run, turn and jump
- * with a gamepad, the camera orbits, Back resets, Start quits, and
+ * with a gamepad, the camera orbits and frames them (right stick
+ * click recenters behind them), Back resets, Start quits, and
* the title bar shows live state/speed.
* ============================================================
*/
@@ -138,12 +145,17 @@ int main(void)
controls_poll(&input);
if (input.quit_pressed)
window_request_close();
- if (input.reset_pressed)
+ if (input.reset_pressed) {
+ /* The camera tracks per-tick movement, so a teleport needs a
+ * fresh camera rather than a 100 m "sprint" to follow. */
player_reset(&player, world_spawn_point());
+ camera_init(&camera, player.body.pos);
+ }
/* 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);
- camera_update(&camera, &input, player.body.pos, TICK_DT);
+ camera_update(&camera, &input, player.body.pos, player.facing_yaw,
+ window_aspect(), TICK_DT);
accumulator -= TICK_DT;
}