summaryrefslogtreecommitdiff
path: root/platformer/src/player.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--platformer/src/player.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/platformer/src/player.h b/platformer/src/player.h
new file mode 100644
index 0000000..35e5b6a
--- /dev/null
+++ b/platformer/src/player.h
@@ -0,0 +1,73 @@
+/*
+ * ============================================================
+ * FILE: player.h
+ *
+ * PURPOSE: Public interface for the player character: its state and the
+ * one function that advances it each tick.
+ *
+ * FITS IN: main.c owns one Player, calls player_update() each tick, and
+ * calls player_reset() on Input.reset_pressed. render.c reads it
+ * to draw it.
+ *
+ * INTERFACE: Use these exact names:
+ *
+ * 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)
+ * } PlayerState;
+ *
+ * typedef struct Player {
+ * Body body; position / velocity / on_ground (physics.h)
+ * float facing_yaw; direction the player faces, radians.
+ * Facing vector = (sin(yaw), 0, cos(yaw)),
+ * which matches mat4_rotate_y in math3d.h.
+ * float forward_speed; ground speed along facing_yaw, m/s (>= 0)
+ * PlayerState state;
+ * } Player;
+ *
+ * void player_init(Player *p, Vec3 spawn);
+ * void player_reset(Player *p, Vec3 spawn);
+ * void player_update(Player *p, const Input *in, float camera_yaw, float dt);
+ * camera_yaw is a plain float so player.c doesn't depend on camera.h.
+ * const char *player_state_name(PlayerState s); "IDLE", "RUN", ... for debug
+ *
+ * Include "math3d.h", "physics.h", "controls.h".
+ *
+ * CONVENTIONS: Include guard: PLAYER_H.
+ *
+ * NOT IN SCOPE: Health, animation, extra moves (see README roadmap).
+ *
+ * DONE WHEN: main.c and render.c compile against this header alone.
+ * ============================================================
+ */
+#ifndef PLAYER_H
+#define PLAYER_H
+
+#include "controls.h"
+#include "math3d.h"
+#include "physics.h"
+
+/* SM64-style "actions". Add states here only when a new move needs one;
+ * see the README roadmap (double jump, long jump, wall kick, ...). */
+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) */
+} PlayerState;
+
+typedef struct Player {
+ Body body; /* position / velocity / on_ground */
+ float facing_yaw; /* radians; facing vector = (sin(yaw), 0, cos(yaw)) */
+ float forward_speed; /* ground speed along facing_yaw, m/s (>= 0) */
+ PlayerState state;
+} Player;
+
+void player_init(Player *p, Vec3 spawn);
+void player_reset(Player *p, Vec3 spawn);
+void player_update(Player *p, const Input *in, float camera_yaw, float dt);
+const char *player_state_name(PlayerState s);
+
+#endif /* PLAYER_H */