From 5f04f3ae87fb307e055d39e81f7c0c841e8a9af8 Mon Sep 17 00:00:00 2001 From: Schark Date: Tue, 29 Sep 2026 19:20:15 -0400 Subject: Slightly alter first jump top speed --- platformer/src/config.h | 9 +++++++++ platformer/src/player.c | 50 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 10 deletions(-) (limited to 'platformer/src') diff --git a/platformer/src/config.h b/platformer/src/config.h index f496ee1..23d85ec 100644 --- a/platformer/src/config.h +++ b/platformer/src/config.h @@ -49,6 +49,12 @@ * PLAYER_AIR_ACCEL 9.0f m/s^2 speeding up toward target speed in air * PLAYER_JUMP_VELOCITY 14.0f m/s upward at jump start (~2.4 m apex) * PLAYER_JUMP_CUT 0.50f vel.y multiplier when A released while rising + * PLAYER_JUMP_MAX_SPEED 7.0f m/s top horizontal speed during a normal + * jump (a little past the run speed) + * PLAYER_JUMP_BOOST_ACCEL 1.5f m/s^2 how slowly speed builds past the run + * speed in a normal jump (~7 m/s by landing) + * PLAYER_OVERSPEED_DECEL 2.0f m/s^2 how slowly speed above the run speed + * eases back down on the ground * PLAYER_SECOND_JUMP_VELOCITY 18.41f m/s upward at second-jump start (1.75x * the first jump's height, ~4.1 m apex) * PLAYER_SECOND_JUMP_WINDOW 0.2f s after landing a jump that the second @@ -169,6 +175,9 @@ #define PLAYER_AIR_ACCEL 9.0f /* m/s^2 toward target speed in air; higher = more steerable jumps */ #define PLAYER_JUMP_VELOCITY 14.0f /* m/s upward at jump start; higher = taller jumps (~2.4 m apex at 14) */ #define PLAYER_JUMP_CUT 0.50f /* vel.y multiplier on early A release; lower = shorter taps */ +#define PLAYER_JUMP_MAX_SPEED 7.0f /* m/s top horizontal speed in a normal jump; higher = bigger reward for jumping at full run */ +#define PLAYER_JUMP_BOOST_ACCEL 1.5f /* m/s^2 build past run speed in a normal jump; higher = reaches PLAYER_JUMP_MAX_SPEED sooner */ +#define PLAYER_OVERSPEED_DECEL 2.0f /* m/s^2 ease back down to run speed after landing (stick held); lower = keeps the extra speed longer */ #define PLAYER_SECOND_JUMP_VELOCITY 18.41f /* m/s upward for the second jump; tuned to 1.75x the first jump's height (4.08 m at 60 Hz) */ #define PLAYER_SECOND_JUMP_WINDOW 0.2f /* s after landing a normal or retreat jump that A gives the second jump; higher = more forgiving timing */ #define PLAYER_SECOND_JUMP_MAX_SPEED 5.0f /* m/s top horizontal speed until the second jump lands; lower = more vertical, less distance */ diff --git a/platformer/src/player.c b/platformer/src/player.c index b4341de..7fe0d76 100644 --- a/platformer/src/player.c +++ b/platformer/src/player.c @@ -39,6 +39,11 @@ * - If mag > 0: facing_yaw = approach_angle(facing_yaw, wish_yaw, * PLAYER_TURN_RATE * dt); forward_speed = approachf(forward_speed, * PLAYER_MAX_SPEED * mag, PLAYER_GROUND_ACCEL * dt) + * - Faster than PLAYER_MAX_SPEED with the stick pushed (landing from a + * normal jump at up to PLAYER_JUMP_MAX_SPEED): ease back down to + * PLAYER_MAX_SPEED at PLAYER_OVERSPEED_DECEL instead, so the extra + * speed fades over ~0.5 s rather than vanishing on landing. + * (Releasing the stick still uses the normal friction.) * - Else: forward_speed = approachf(forward_speed, 0, * PLAYER_GROUND_FRICTION * dt). Accel and friction are low on * purpose: starts build up and stops skid briefly, so the player @@ -96,9 +101,15 @@ * no instant turn from a standstill, and there's NO friction when the * stick is released (you keep your momentum, like SM64). * - Top speed: steering aims for top_speed() * mag, where top_speed() - * is PLAYER_SECOND_JUMP_MAX_SPEED in the second jump, + * is PLAYER_JUMP_MAX_SPEED in a normal jump, + * PLAYER_SECOND_JUMP_MAX_SPEED in the second jump, * PLAYER_RETREAT_JUMP_SPEED in the retreat jump, and - * PLAYER_MAX_SPEED otherwise. While forward_speed is ABOVE it (a + * PLAYER_MAX_SPEED otherwise. + * - Building past run speed: up to PLAYER_MAX_SPEED * mag the air + * accelerates at PLAYER_AIR_ACCEL as usual; beyond it (only a + * normal jump allows that) only at PLAYER_JUMP_BOOST_ACCEL. So a full + * jump taken at a full run gains ~1 m/s by landing: a small, + * gradual reward for jumping, not a burst. While forward_speed is ABOVE it (a * full run into the second jump), the stick only turns: the extra * speed bleeds off at PLAYER_SECOND_JUMP_SLOWDOWN, whatever the * stick does. So a 6 m/s run into the second jump eases down to @@ -143,7 +154,9 @@ * lands. Pulling the stick back at full run turns the player to * face the stick and slides them backward to a stop over 0.5 s, * and A during that slide launches a 2x-height jump toward the - * stick at 4 m/s; landing it opens the second-jump window too. The player lands cleanly back in IDLE/RUN. + * stick at 4 m/s; landing it opens the second-jump window too. A + * full jump at full run builds gently to ~7 m/s, and that extra + * speed eases back to 6 m/s after landing. The player lands cleanly back in IDLE/RUN. * ============================================================ */ @@ -180,6 +193,7 @@ static Wish compute_wish(const Input *in, float camera_yaw) static float top_speed(const Player *p) { switch (p->jump_kind) { + case JUMP_NORMAL: return PLAYER_JUMP_MAX_SPEED; case JUMP_SECOND: return PLAYER_SECOND_JUMP_MAX_SPEED; case JUMP_RETREAT: return PLAYER_RETREAT_JUMP_SPEED; default: return PLAYER_MAX_SPEED; @@ -204,12 +218,12 @@ static void turn(Player *p, Wish wish, float turn_rate, float dt) p->facing_yaw = approach_angle(p->facing_yaw, wish.yaw, turn_rate * dt); } -/* Turns toward the stick and speeds up toward a speed set by how far it's - * pushed. Shared by ground and air movement; the air passes smaller rates. */ -static void steer(Player *p, Wish wish, float turn_rate, float accel, float dt) +/* Turns toward the stick and changes speed toward target_speed by at most + * `rate`. Shared by ground and air movement; the air passes smaller rates. */ +static void steer(Player *p, Wish wish, float turn_rate, float target_speed, float rate, float dt) { turn(p, wish, turn_rate, dt); - p->forward_speed = approachf(p->forward_speed, top_speed(p) * wish.mag, accel * dt); + p->forward_speed = approachf(p->forward_speed, target_speed, rate * dt); } /* Standing still vs walking vs running is only a matter of speed. */ @@ -312,7 +326,13 @@ static void update_ground(Player *p, const Input *in, Wish wish, float dt) * nudging the stick to adjust your aim still looks smooth. */ if (p->forward_speed == 0.0f && angle_off_facing(p, wish) > deg_to_rad(PLAYER_SNAP_TURN_DEG)) p->facing_yaw = wish.yaw; - steer(p, wish, PLAYER_TURN_RATE, PLAYER_GROUND_ACCEL, dt); + + /* Landed from a normal jump carrying more than run speed: let the + * extra fade slowly instead of vanishing the moment we touch down. */ + if (p->forward_speed > top_speed(p)) + steer(p, wish, PLAYER_TURN_RATE, top_speed(p), PLAYER_OVERSPEED_DECEL, dt); + else + steer(p, wish, PLAYER_TURN_RATE, top_speed(p) * wish.mag, PLAYER_GROUND_ACCEL, dt); } else { p->forward_speed = approachf(p->forward_speed, 0.0f, PLAYER_GROUND_FRICTION * dt); } @@ -379,8 +399,18 @@ static void air_steer(Player *p, Wish wish, float dt) return; } - if (wish.mag > 0.0f) - steer(p, wish, air_turn_rate, PLAYER_AIR_ACCEL, dt); + if (wish.mag <= 0.0f) + return; + + /* Up to what running would give, the air accelerates as usual. Past it + * (only a normal jump's top speed allows that) speed builds slowly: a + * small reward for jumping at full run, not a burst. */ + float target = top_speed(p) * wish.mag; + float run_target = fminf(target, PLAYER_MAX_SPEED * wish.mag); + if (target > run_target && p->forward_speed >= run_target) + steer(p, wish, air_turn_rate, target, PLAYER_JUMP_BOOST_ACCEL, dt); + else + steer(p, wish, air_turn_rate, run_target, PLAYER_AIR_ACCEL, dt); } /* FALL: in the air, going down. Landing hands straight over to the ground -- cgit v1.2.3-18-g5258