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

@@ -450,6 +450,8 @@ static bool save_tilemap(const Tilemap *map, const char *path) {
if (map->gravity > 0)
fprintf(f, "GRAVITY %.0f\n", map->gravity);
if (map->wind != 0.0f)
fprintf(f, "WIND %.0f\n", map->wind);
if (map->has_bg_color)
fprintf(f, "BG_COLOR %d %d %d\n", map->bg_color.r, map->bg_color.g, map->bg_color.b);
if (map->music_path[0])

View File

@@ -170,6 +170,13 @@ static void flyer_update(Entity *self, float dt, const Tilemap *map) {
float bob_offset = sinf(fd->bob_timer * FLYER_BOB_SPD) * FLYER_BOB_AMP;
body->pos.y = fd->base_y + bob_offset;
/* Wind drifts flyers (they bypass physics_update).
* Apply as gentle position offset matching first-frame physics. */
float wind = physics_get_wind();
if (wind != 0.0f) {
body->pos.x += wind * dt * dt;
}
/* Chase player if in range */
Entity *player = find_player(s_flyer_em);
if (player && player->active && !(player->flags & ENTITY_DEAD)) {

View File

@@ -57,6 +57,9 @@ static bool level_setup(Level *level) {
physics_set_gravity(DEFAULT_GRAVITY);
}
/* Apply level wind (0 = no wind) */
physics_set_wind(level->map.wind);
/* Apply level background color */
if (level->map.has_bg_color) {
renderer_set_clear_color(level->map.bg_color);

View File

@@ -1631,6 +1631,10 @@ bool levelgen_dump_lvl(const Tilemap *map, const char *path) {
fprintf(f, "GRAVITY %.0f\n", map->gravity);
}
if (map->wind != 0.0f) {
fprintf(f, "WIND %.0f\n", map->wind);
}
if (map->has_bg_color) {
fprintf(f, "BG_COLOR %d %d %d\n",
map->bg_color.r, map->bg_color.g, map->bg_color.b);

View File

@@ -204,6 +204,12 @@ static void projectile_update(Entity *self, float dt, const Tilemap *map) {
if (body->vel.y > MAX_FALL_SPEED) body->vel.y = MAX_FALL_SPEED;
}
/* ── Apply wind ─────────────────────────── */
float wind = physics_get_wind();
if (wind != 0.0f) {
body->vel.x += wind * dt;
}
/* ── Move ────────────────────────────────── */
body->pos.x += body->vel.x * dt;
body->pos.y += body->vel.y * dt;