Add per-level wind atmosphere property

WIND directive in .lvl files sets a constant horizontal force (px/s^2)
that pushes entities, projectiles, and particles. Positive is rightward.

Wind is applied as acceleration in physics_update() (halved on ground),
directly to projectile and particle velocities, and as a gentle position
drift on flyers. Entities with gravity_scale=0 (drones, spacecraft) are
unaffected. Levels default to no wind when the directive is absent.
This commit is contained in:
Thomas
2026-03-01 17:13:01 +00:00
parent cdba479ced
commit 6c4b076c68
11 changed files with 56 additions and 5 deletions

View File

@@ -4,9 +4,11 @@
#include <math.h>
static float s_gravity = DEFAULT_GRAVITY;
static float s_wind = 0.0f;
void physics_init(void) {
s_gravity = DEFAULT_GRAVITY;
s_wind = 0.0f;
}
void physics_set_gravity(float gravity) {
@@ -17,6 +19,14 @@ float physics_get_gravity(void) {
return s_gravity;
}
void physics_set_wind(float wind) {
s_wind = wind;
}
float physics_get_wind(void) {
return s_wind;
}
static void resolve_tilemap_x(Body *body, const Tilemap *map) {
if (!map) return;
@@ -102,6 +112,12 @@ void physics_update(Body *body, float dt, const Tilemap *map) {
/* Apply gravity */
body->vel.y += s_gravity * body->gravity_scale * dt;
/* Apply wind — halved on ground (friction counteracts) */
if (s_wind != 0.0f && body->gravity_scale > 0.0f) {
float wind_factor = body->on_ground ? 0.5f : 1.0f;
body->vel.x += s_wind * body->gravity_scale * wind_factor * dt;
}
/* Clamp fall speed */
if (body->vel.y > MAX_FALL_SPEED) {
body->vel.y = MAX_FALL_SPEED;