engine-c: denser mid-flight combat tracers in KKND_SHOT

This commit is contained in:
local-model/engine-L2-grok-4.5 2026-09-19 10:40:43 +02:00 committed by Hernâni Marques
parent 75c9294202
commit 97662d4440
No known key found for this signature in database
6 changed files with 85 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Before After
Before After

View file

@ -159,6 +159,61 @@ int main(int argc, char **argv) {
particle_burst(g, cx + 44, cy - 16, 20, 2, 255, 240, 100);
particle_burst(g, cx + 8, cy - 40, 18, 1, 255, 150, 45);
particle_burst(g, cx - 22, cy + 36, 18, 0, 120, 110, 95);
/* Mid-flight shells/missiles/lasers: after ~1s sim most live
* bullets have already impacted. Reseed between nearby opposing
* pairs so the PNG shows KKND2-like tracers across the clash. */
{
int spawned = 0;
const float pair_r2 = 170.0f * 170.0f;
for (int i = 0; i < g->unit_count && spawned < 56; i++) {
Unit *a = &g->units[i];
if (a->dead) continue;
float ax = a->x - clash_x, ay = a->y - clash_y;
if (ax * ax + ay * ay > r2) continue;
int shots = 0;
for (int j = 0; j < g->unit_count && spawned < 56 && shots < 2; j++) {
Unit *b = &g->units[j];
if (b->dead || b->faction == a->faction) continue;
float dx = b->x - a->x, dy = b->y - a->y;
float d2 = dx * dx + dy * dy;
if (d2 > pair_r2 || d2 < 24.0f * 24.0f) continue;
int kind = (spawned % 4 == 0) ? 3
: (spawned % 4 == 1) ? 1
: (spawned % 4 == 2) ? 2 : 0;
float t = 0.22f + 0.55f * ((spawned * 37) % 100) / 100.0f;
float sx = a->x + dx * t;
float sy = a->y + dy * t;
bullet_spawn(g, sx, sy, b->id, -1, 1.0f, a->faction, kind);
spawned++;
shots++;
}
}
/* turret / base guns → nearest enemy in clash */
for (int i = 0; i < g->bld_count && spawned < 64; i++) {
Building *bl = &g->buildings[i];
if (bl->dead || (bl->type != BT_TURRET && bl->type != BT_BASE))
continue;
float bx = (float)(bl->tx * TILE + bl->w * TILE / 2);
float by = (float)(bl->ty * TILE + bl->h * TILE / 2);
float bdx = bx - clash_x, bdy = by - clash_y;
if (bdx * bdx + bdy * bdy > r2) continue;
int best = -1; float bestd = 1e12f;
for (int j = 0; j < g->unit_count; j++) {
Unit *u = &g->units[j];
if (u->dead || u->faction == bl->faction) continue;
float dx = u->x - bx, dy = u->y - by;
float d2 = dx * dx + dy * dy;
if (d2 < bestd && d2 < pair_r2) { bestd = d2; best = j; }
}
if (best < 0) continue;
Unit *tgt = &g->units[best];
float dx = tgt->x - bx, dy = tgt->y - by;
float t = 0.30f + 0.40f * ((spawned * 19) % 100) / 100.0f;
bullet_spawn(g, bx + dx * t, by + dy * t, tgt->id, -1,
2.0f, bl->faction, (spawned & 1) ? 1 : 2);
spawned++;
}
}
}
char path[64]; snprintf(path, sizeof path, "shot_%04d.png", 1);
snapshot_capture(g, path);

View file

@ -469,17 +469,41 @@ void snapshot_capture(Game *g, const char *path) {
draw_unit(u, sx, sy);
}
/* projectiles — bright tracers / shells */
/* projectiles — bright tracers / shells with streak tails (KKND2-like) */
for (int i = 0; i < g->bullet_count; i++) {
Bullet *p = &g->bullets[i];
int sx=(int)(p->x-camx), sy=(int)(p->y-camy);
int sx = (int)(p->x - camx), sy = (int)(p->y - camy);
float dx = p->tx - p->x, dy = p->ty - p->y;
float d = sqrtf(dx * dx + dy * dy);
if (d > 1.0f) {
float ux = dx / d, uy = dy / d;
int len = (p->kind == 2) ? 24 : (p->kind == 3) ? 18
: (p->kind == 1) ? 14 : 10;
for (int t = 1; t <= len; t++) {
int tx = sx - (int)(ux * (float)t * 0.75f);
int ty = sy - (int)(uy * (float)t * 0.75f);
uint8_t fade = (uint8_t)(255 - t * 9);
if (p->kind == 2) {
/* laser beam: cyan→magenta streak */
disc(tx, ty, (t < 3) ? 2 : 1, fade, 80, 255);
px(tx, ty, 220, 180, 255);
} else if (p->kind == 3) {
disc(tx, ty, (t < 4) ? 2 : 1, 255, (uint8_t)(120 - t * 4), 30);
} else {
disc(tx, ty, 1, 255, (uint8_t)(200 - t * 8), 50);
}
}
}
int rad = (p->kind == 1 || p->kind == 3) ? 6 : 4;
disc(sx, sy, rad + 1, 255, 160, 40);
disc(sx, sy, rad, 255, 240, 140);
px(sx+1, sy, 255, 255, 220);
px(sx + 1, sy, 255, 255, 220);
if (p->kind == 3) {
disc(sx - 3, sy + 1, 3, 255, 70, 30);
disc(sx + 2, sy - 2, 2, 255, 200, 80);
} else if (p->kind == 2) {
disc(sx, sy, rad + 1, 120, 200, 255);
disc(sx, sy, rad - 1, 240, 220, 255);
}
}