diff options
| author | Schark <jordan@schark.online> | 2026-09-24 14:43:21 -0400 |
|---|---|---|
| committer | Schark <jordan@schark.online> | 2026-09-24 14:43:21 -0400 |
| commit | b47571e7f1b4348b526c23a6ab6b88dbcb49ecf1 (patch) | |
| tree | 3c0b52b313b02f270e77844c67278e8a51822b80 /platformer/src/player.c | |
| parent | 077dfb2774e29cc49b9d602bb3a2f5e81e4a9a63 (diff) | |
| download | gamedev-b47571e7f1b4348b526c23a6ab6b88dbcb49ecf1.tar.gz gamedev-b47571e7f1b4348b526c23a6ab6b88dbcb49ecf1.zip | |
Add random platforms into game world for testing
Diffstat (limited to 'platformer/src/player.c')
| -rw-r--r-- | platformer/src/player.c | 19 |
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) |
