summaryrefslogtreecommitdiff
path: root/platformer/src/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'platformer/src/player.c')
-rw-r--r--platformer/src/player.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/platformer/src/player.c b/platformer/src/player.c
index ed8da51..16924ec 100644
--- a/platformer/src/player.c
+++ b/platformer/src/player.c
@@ -13,6 +13,7 @@
*
* IMPLEMENT:
* - player_init / player_reset: body.pos = spawn, vel = 0, on_ground = true,
+ * body.half_width = PLAYER_HALF_WIDTH, body.height = PLAYER_HEIGHT,
* facing_yaw = 0, forward_speed = 0, state = PLAYER_IDLE.
*
* - player_update(p, in, camera_yaw, dt). Use one static helper per state
@@ -47,7 +48,7 @@
* - JUMP -> FALL when vel.y <= 0.
* - FALL -> IDLE/RUN when body.on_ground (landing).
* - If the player is on the ground state-wise but body.on_ground is false
- * (walked off an edge, once edges exist) -> FALL.
+ * (walked off a platform edge) -> FALL.
*
* E. Apply: body.vel.x = sin(facing_yaw) * forward_speed
* body.vel.z = cos(facing_yaw) * forward_speed
@@ -117,7 +118,7 @@ static PlayerState grounded_state(const Player *p)
* and the only place a jump can start. */
static void update_ground(Player *p, const Input *in, Wish wish, float dt)
{
- /* Walked off an edge (once edges exist): start falling. */
+ /* Walked off a platform edge: start falling. */
if (!p->body.on_ground) {
p->state = PLAYER_FALL;
update_fall(p, in, wish, dt);
@@ -182,12 +183,14 @@ static void update_jump(Player *p, const Input *in, Wish wish, float dt)
void player_init(Player *p, Vec3 spawn)
{
- p->body.pos = spawn;
- p->body.vel = vec3_make(0.0f, 0.0f, 0.0f);
- p->body.on_ground = true;
- p->facing_yaw = 0.0f;
- p->forward_speed = 0.0f;
- p->state = PLAYER_IDLE;
+ p->body.pos = spawn;
+ p->body.vel = vec3_make(0.0f, 0.0f, 0.0f);
+ p->body.on_ground = true;
+ p->body.half_width = PLAYER_HALF_WIDTH; /* the collision box matches the drawn box */
+ p->body.height = PLAYER_HEIGHT;
+ p->facing_yaw = 0.0f;
+ p->forward_speed = 0.0f;
+ p->state = PLAYER_IDLE;
}
void player_reset(Player *p, Vec3 spawn)