summaryrefslogtreecommitdiff
path: root/platformer/src/player.h
diff options
context:
space:
mode:
Diffstat (limited to 'platformer/src/player.h')
-rw-r--r--platformer/src/player.h50
1 files changed, 40 insertions, 10 deletions
diff --git a/platformer/src/player.h b/platformer/src/player.h
index 5f8d963..4d8fdc6 100644
--- a/platformer/src/player.h
+++ b/platformer/src/player.h
@@ -15,9 +15,18 @@
* PLAYER_IDLE, on ground, not moving
* PLAYER_RUN, on ground, moving (walk vs run is just speed)
* PLAYER_JUMP, in air, going up after a jump
- * PLAYER_FALL in air, going down (or walked off something)
+ * PLAYER_FALL, in air, going down (or walked off something)
+ * PLAYER_SKID on ground, braking after pulling the stick back at
+ * full run; retreating_movement is on
* } PlayerState;
*
+ * typedef enum JumpKind { which jump the player is in the air from
+ * JUMP_NONE, on the ground, or airborne without jumping
+ * JUMP_NORMAL, a normal jump
+ * JUMP_SECOND, the higher jump from heightened_movement
+ * JUMP_RETREAT the jump out of a skid, from retreating_movement
+ * } JumpKind;
+ *
* typedef struct Player {
* Body body; position / velocity / on_ground (physics.h)
* float facing_yaw; direction the player faces, radians.
@@ -26,14 +35,20 @@
* float forward_speed; ground speed along facing_yaw, m/s (>= 0)
* PlayerState state;
* bool heightened_movement; on for PLAYER_SECOND_JUMP_WINDOW s after
- * landing a normal jump, and for the whole
+ * landing a normal or retreat jump, and for the whole
* second jump. While on, A gives the second
* jump. Later moves will read it too.
* float heightened_timer; s left before heightened_movement ends
* (not counted down during the second jump)
- * int jump_number; which jump the player is in the air from:
- * 0 = none (walked off an edge, or grounded),
- * 1 = a normal jump, 2 = the second jump
+ * bool retreating_movement; on for the whole skid (PLAYER_SKID) and
+ * the retreat jump out of it. While skidding, A
+ * gives the retreat jump. Later moves will read
+ * it too.
+ * JumpKind jump_kind; which jump the player is in the air from
+ * float skid_time; s since the current skid began
+ * float skid_speed; forward_speed when the skid began
+ * float skid_yaw; direction the skid slides (the old run
+ * direction; the player already faces the stick)
* } Player;
*
* void player_init(Player *p, Vec3 spawn);
@@ -46,8 +61,8 @@
*
* CONVENTIONS: Include guard: PLAYER_H.
*
- * NOT IN SCOPE: Health, animation, extra moves beyond the second jump (see the
- * README roadmap).
+ * NOT IN SCOPE: Health, animation, extra moves beyond the second jump and the
+ * skid's retreat jump (see the README roadmap).
*
* DONE WHEN: main.c and render.c compile against this header alone.
* ============================================================
@@ -61,14 +76,25 @@
/* SM64-style "actions". Add states here only when a new move needs one;
* see the README roadmap (triple jump, long jump, wall kick, ...). The second
- * jump didn't need one: it's a JUMP with a higher launch (see jump_number). */
+ * and retreat jumps didn't need one: they're a JUMP with a different launch
+ * (see JumpKind). The skid did, because it follows its own ground rules. */
typedef enum PlayerState {
PLAYER_IDLE, /* on ground, not moving */
PLAYER_RUN, /* on ground, moving (walk vs run is just speed) */
PLAYER_JUMP, /* in air, going up after a jump */
- PLAYER_FALL /* in air, going down (or walked off something) */
+ PLAYER_FALL, /* in air, going down (or walked off something) */
+ PLAYER_SKID /* on ground, braking after pulling back at full run */
} PlayerState;
+/* Which jump the player is in the air from. It decides the top speed in the
+ * air and what landing turns on or off. */
+typedef enum JumpKind {
+ JUMP_NONE, /* on the ground, or airborne without jumping (walked off an edge) */
+ JUMP_NORMAL, /* a normal jump */
+ JUMP_SECOND, /* the higher jump from heightened_movement */
+ JUMP_RETREAT /* the jump out of a skid, from retreating_movement */
+} JumpKind;
+
typedef struct Player {
Body body; /* position / velocity / on_ground */
float facing_yaw; /* radians; facing vector = (sin(yaw), 0, cos(yaw)) */
@@ -76,7 +102,11 @@ typedef struct Player {
PlayerState state;
bool heightened_movement; /* second jump available (or in progress); later moves read it too */
float heightened_timer; /* s left before heightened_movement ends; paused during the second jump */
- int jump_number; /* airborne from: 0 = no jump (walked off an edge), 1 = normal, 2 = second */
+ bool retreating_movement; /* skidding (or in the jump out of a skid); later moves read it too */
+ JumpKind jump_kind; /* which jump the player is in the air from */
+ float skid_time; /* s since the current skid began */
+ float skid_speed; /* forward_speed when the skid began */
+ float skid_yaw; /* direction the skid slides; facing_yaw already points at the stick */
} Player;
void player_init(Player *p, Vec3 spawn);