summaryrefslogtreecommitdiff
path: root/platformer/src/player.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--platformer/src/player.c50
1 files changed, 40 insertions, 10 deletions
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