forked from tas/major_tom
Add Mars surface atmosphere particels
This commit is contained in:
@@ -529,3 +529,65 @@ void particle_emit_wall_slide_dust(Vec2 pos, int wall_dir) {
|
||||
};
|
||||
particle_emit(&dust);
|
||||
}
|
||||
|
||||
/* Spawn a single dust mote with the given visual properties. */
|
||||
static void spawn_dust_mote(Vec2 pos, Vec2 vel,
|
||||
float life_min, float life_max,
|
||||
float size_min, float size_max,
|
||||
float drag, float gscale,
|
||||
uint8_t r, uint8_t g, uint8_t b, int vary) {
|
||||
Particle *p = alloc_particle();
|
||||
p->pos = pos;
|
||||
p->vel = vel;
|
||||
p->life = randf_range(life_min, life_max);
|
||||
p->max_life = p->life;
|
||||
p->size = randf_range(size_min, size_max);
|
||||
p->drag = drag;
|
||||
p->gravity_scale = gscale;
|
||||
p->active = true;
|
||||
p->color.r = clamp_u8(r + (int)randf_range(-vary, vary));
|
||||
p->color.g = clamp_u8(g + (int)randf_range(-vary, vary));
|
||||
p->color.b = clamp_u8(b + (int)randf_range(-vary, vary));
|
||||
p->color.a = 255; /* alpha applied during render from life ratio */
|
||||
}
|
||||
|
||||
void particle_emit_atmosphere_dust(Vec2 cam_pos, Vec2 vp) {
|
||||
/* Ambient Mars dust — subtle motes drifting across the viewport.
|
||||
* Two sub-layers for depth: large slow "far" motes and small quick
|
||||
* "near" specks. Wind carries them; gravity_scale controls how much
|
||||
* environmental forces (wind + gravity) affect each particle.
|
||||
* Particles spawn along the upwind viewport edge and drift inward;
|
||||
* occasional interior spawns prevent a visible edge seam. */
|
||||
float wind = physics_get_wind();
|
||||
float margin = 32.0f;
|
||||
float dir = (wind >= 0.0f) ? 1.0f : -1.0f; /* velocity sign */
|
||||
|
||||
/* Upwind edge X for the two edge-spawned layers */
|
||||
float edge_far = (wind >= 0.0f) ? cam_pos.x - margin
|
||||
: cam_pos.x + vp.x + margin;
|
||||
float edge_near = (wind >= 0.0f) ? cam_pos.x - margin * 0.5f
|
||||
: cam_pos.x + vp.x + margin * 0.5f;
|
||||
|
||||
/* Far dust motes — large, slow, translucent (1/frame) */
|
||||
spawn_dust_mote(
|
||||
vec2(edge_far, cam_pos.y + randf() * vp.y),
|
||||
vec2(dir * randf_range(8.0f, 25.0f), randf_range(-6.0f, 6.0f)),
|
||||
4.0f, 7.0f, 1.5f, 3.0f, 0.3f, 0.08f,
|
||||
180, 140, 100, 25);
|
||||
|
||||
/* Near dust specks — small, quicker, brighter (1/frame) */
|
||||
spawn_dust_mote(
|
||||
vec2(edge_near, cam_pos.y + randf() * vp.y),
|
||||
vec2(dir * randf_range(15.0f, 40.0f), randf_range(-10.0f, 10.0f)),
|
||||
2.5f, 5.0f, 0.8f, 1.5f, 0.2f, 0.12f,
|
||||
200, 160, 120, 20);
|
||||
|
||||
/* Occasional interior spawn — prevents edge seam on calm wind */
|
||||
if (rand() % 3 == 0) {
|
||||
spawn_dust_mote(
|
||||
vec2(cam_pos.x + randf() * vp.x, cam_pos.y + randf() * vp.y),
|
||||
vec2(randf_range(-5.0f, 5.0f), randf_range(-8.0f, 3.0f)),
|
||||
3.0f, 6.0f, 1.0f, 2.5f, 0.4f, 0.06f,
|
||||
160, 130, 95, 25);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user