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/physics.h | |
| parent | 077dfb2774e29cc49b9d602bb3a2f5e81e4a9a63 (diff) | |
| download | gamedev-b47571e7f1b4348b526c23a6ab6b88dbcb49ecf1.tar.gz gamedev-b47571e7f1b4348b526c23a6ab6b88dbcb49ecf1.zip | |
Add random platforms into game world for testing
Diffstat (limited to 'platformer/src/physics.h')
| -rw-r--r-- | platformer/src/physics.h | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/platformer/src/physics.h b/platformer/src/physics.h index 580d09b..f626c65 100644 --- a/platformer/src/physics.h +++ b/platformer/src/physics.h @@ -3,31 +3,36 @@ * FILE: physics.h * * PURPOSE: Public interface for generic physical motion: a `Body` that - * falls, moves and lands on the ground. It knows nothing about - * players or controllers, so enemies and objects can reuse it later. + * falls, moves, lands on floors, slides along walls and bumps its + * head on ceilings. It knows nothing about players or controllers, + * so enemies and objects can reuse it later. * * FITS IN: player.c owns a Body, sets its horizontal velocity from input, * then calls physics_step() once per tick. physics.c asks world.h - * about the ground and the bounds. + * about floors, ceilings, overlapping boxes and the bounds. * * INTERFACE: Use these exact names: * * typedef struct Body { - * Vec3 pos; position of the body's FEET (bottom center), meters - * Vec3 vel; velocity, meters/second - * bool on_ground; true if the body ended the last step standing on ground + * Vec3 pos; position of the body's FEET (bottom center), meters + * Vec3 vel; velocity, meters/second + * bool on_ground; true if the body ended the last step standing on + * 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 * } Body; * * void physics_step(Body *b, float dt); * * Include <stdbool.h> and "math3d.h". * - * CONVENTIONS: Include guard: PHYSICS_H. + * 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. * - * DONE WHEN: player.c can move and land using only Body + physics_step. + * DONE WHEN: player.c can move, land, and collide using only Body + physics_step. * ============================================================ */ #ifndef PHYSICS_H @@ -38,9 +43,11 @@ #include "math3d.h" typedef struct Body { - Vec3 pos; /* position of the body's FEET (bottom center), meters */ - Vec3 vel; /* velocity, meters/second */ - bool on_ground; /* true if the body ended the last step standing on ground */ + Vec3 pos; /* position of the body's FEET (bottom center), meters */ + Vec3 vel; /* velocity, meters/second */ + 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 */ } Body; void physics_step(Body *b, float dt); |
