diff options
| author | Schark <jordan@schark.online> | 2026-09-29 21:02:22 -0400 |
|---|---|---|
| committer | Schark <jordan@schark.online> | 2026-09-29 21:02:22 -0400 |
| commit | 21404c26d3907cefa524878fb031e7a2022fb3d7 (patch) | |
| tree | 38b2bb26d6d0c05447213edca4911ccc3887f474 /platformer/src/physics.h | |
| parent | 5f04f3ae87fb307e055d39e81f7c0c841e8a9af8 (diff) | |
| download | gamedev-21404c26d3907cefa524878fb031e7a2022fb3d7.tar.gz gamedev-21404c26d3907cefa524878fb031e7a2022fb3d7.zip | |
Game world test with updated movement
Diffstat (limited to 'platformer/src/physics.h')
| -rw-r--r-- | platformer/src/physics.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/platformer/src/physics.h b/platformer/src/physics.h index f626c65..9da41ac 100644 --- a/platformer/src/physics.h +++ b/platformer/src/physics.h @@ -20,17 +20,27 @@ * something (the ground or a platform top) * float half_width; collision box half-size in x and z, meters * float height; collision box height above the feet, meters + * float gravity_scale; multiplier on GRAVITY (1 = normal). The owner can + * set 0 to take over vertical motion itself (the + * player does while clinging to a wall). + * bool hit_wall; true if the last step pushed the body out of a box's + * SIDE (not a top or bottom) + * Vec3 wall_normal; that side's outward normal (+-x or +-z, y = 0); + * only meaningful if hit_wall + * Box wall; the box that side belongs to; only meaningful if hit_wall + * int ground_box; index (world_box) of the box the body stands on, or -1 + * for the ground / in the air. Used to ride moving boxes. * } Body; * * void physics_step(Body *b, float dt); * - * Include <stdbool.h> and "math3d.h". + * Include <stdbool.h>, "math3d.h" and "world.h" (for Box). * * CONVENTIONS: Include guard: PHYSICS_H. The collision shape is an axis-aligned * box that does not rotate (a spinning box would snag on walls). * * NOT IN SCOPE: Rigid bodies, rotation, mass, forces/impulses API, collision - * between bodies. + * between bodies, keeping a moving box's momentum after leaving it. * * DONE WHEN: player.c can move, land, and collide using only Body + physics_step. * ============================================================ @@ -41,6 +51,7 @@ #include <stdbool.h> #include "math3d.h" +#include "world.h" typedef struct Body { Vec3 pos; /* position of the body's FEET (bottom center), meters */ @@ -48,6 +59,11 @@ typedef struct Body { bool on_ground; /* true if the body ended the last step standing on something */ float half_width; /* collision box half-size in x and z, meters */ float height; /* collision box height above the feet, meters */ + float gravity_scale; /* multiplier on GRAVITY; 1 = normal, 0 = the owner drives vel.y itself */ + bool hit_wall; /* the last step pushed the body out of a box's side */ + Vec3 wall_normal; /* that side's outward normal (+-x or +-z); only if hit_wall */ + Box wall; /* the box that side belongs to; only if hit_wall */ + int ground_box; /* world_box index stood on (-1 = ground or airborne); for riding moving boxes */ } Body; void physics_step(Body *b, float dt); |
