summaryrefslogtreecommitdiff
path: root/platformer/src/player.c
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2026-09-29 23:36:45 -0400
committerSchark <jordan@schark.online>2026-09-29 23:36:45 -0400
commit8af1210d45c3fa3f41a174d2906ab597dcc22f1c (patch)
tree43f1a9814faae852af943f71de53d4ca38dc6cd2 /platformer/src/player.c
parentfdc8c951fc72d9dc4c8faa58a21b2b9de0599698 (diff)
downloadgamedev-8af1210d45c3fa3f41a174d2906ab597dcc22f1c.tar.gz
gamedev-8af1210d45c3fa3f41a174d2906ab597dcc22f1c.zip
Final state of the game day 3HEADmaster
Diffstat (limited to 'platformer/src/player.c')
-rw-r--r--platformer/src/player.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/platformer/src/player.c b/platformer/src/player.c
index 9f0e822..429baa8 100644
--- a/platformer/src/player.c
+++ b/platformer/src/player.c
@@ -98,11 +98,12 @@
* jump_kind = JUMP_NORMAL. heightened_movement stays OFF, so a
* first jump can't grab walls (tried; it made wall hangs too easy).
*
- * C2. Landing: landing from a normal jump (JUMP_NORMAL, short hop or
- * full) or a retreat jump (JUMP_RETREAT) turns heightened_movement on
- * with heightened_timer = PLAYER_SECOND_JUMP_WINDOW, so either one
- * can lead into the second jump. Landing any other way (from the
- * second jump, or after walking off an edge) turns it off. Every
+ * C2. Landing: every landing turns heightened_movement on with
+ * heightened_timer = PLAYER_SECOND_JUMP_WINDOW (after a normal jump,
+ * a retreat jump, or a plain fall: walking off a platform, letting go
+ * of a wall), so any of them can lead into the second jump. The one
+ * exception is landing the second jump itself: that turns it off, so
+ * second jumps can't chain. Every
* landing turns retreating_movement off and resets jump_kind to
* JUMP_NONE, and clears has_last_wall. The heightened timer counts
* down (turning it off at 0) only while jump_kind == JUMP_NONE and
@@ -187,6 +188,13 @@
* body.gravity_scale = 0 in WALL_HANG, else 1.
* Then physics_step(&p->body, dt).
*
+ * G. Stairs look smooth: after physics_step, visual_offset -= body.step_dy
+ * (so the drawn height stays put when physics steps a stair), clamped to
+ * +-2 * STEP_HEIGHT, then decays toward 0 by exp(-STEP_SMOOTH_RATE * dt).
+ * player_visual_pos() = body.pos + (0, visual_offset, 0): render.c draws
+ * the player there and main.c points the camera at it. Gameplay, the
+ * shadow and zones all use the real body.pos.
+ *
* - player_state_name: a switch that returns string literals.
*
* CONVENTIONS: Facing vector = (sin(yaw), 0, cos(yaw)). Speeds are in m/s,
@@ -336,13 +344,14 @@ static void start_retreat_jump(Player *p)
leave_ground(p, PLAYER_RETREAT_JUMP_VELOCITY, JUMP_RETREAT);
}
-/* C2. Touching down. Landing a normal jump (a hop or a full one) or a
- * retreat jump opens the short window for the second jump; landing any
- * other way closes it, so the second jump can't chain into another one.
- * Any landing ends a retreat jump's retreating_movement. */
+/* C2. Touching down. Every landing opens the short window for the second
+ * jump (after a normal or retreat jump, and after a plain fall such as
+ * walking off a platform or letting go of a wall), EXCEPT landing the
+ * second jump itself, so second jumps can't chain. Any landing ends a
+ * retreat jump's retreating_movement. */
static void land(Player *p)
{
- if (p->jump_kind == JUMP_NORMAL || p->jump_kind == JUMP_RETREAT) {
+ if (p->jump_kind != JUMP_SECOND) {
p->heightened_movement = true;
p->heightened_timer = PLAYER_SECOND_JUMP_WINDOW;
} else {
@@ -682,6 +691,8 @@ void player_init(Player *p, Vec3 spawn)
p->skid_speed = 0.0f;
p->skid_yaw = 0.0f;
p->jump_buffer = 0.0f;
+ p->visual_offset = 0.0f;
+ p->body.step_dy = 0.0f;
p->wall_time = 0.0f;
p->wall_jump_yaw = 0.0f;
p->has_last_wall = false;
@@ -735,6 +746,19 @@ void player_update(Player *p, const Input *in, float camera_yaw, float dt)
p->body.vel.z = cosf(move_yaw) * move_speed;
p->body.gravity_scale = hanging ? 0.0f : 1.0f;
physics_step(&p->body, dt);
+
+ /* G. Stairs: physics lifts or drops the body a whole stair in one tick,
+ * which would pop on screen (and jolt the camera). Keep the DRAWN height
+ * where it was and let it glide onto the body, so stairs look smooth
+ * while collision and timing stay exact. Real jumps and landings aren't
+ * steps, so they're never smoothed. */
+ p->visual_offset = clampf(p->visual_offset - p->body.step_dy, -2.0f * STEP_HEIGHT, 2.0f * STEP_HEIGHT);
+ p->visual_offset *= expf(-STEP_SMOOTH_RATE * dt);
+}
+
+Vec3 player_visual_pos(const Player *p)
+{
+ return vec3_add(p->body.pos, vec3_make(0.0f, p->visual_offset, 0.0f));
}
const char *player_state_name(PlayerState s)