engine-c: SDL ground shadows + type-scale + richer bld silhouettes
This commit is contained in:
parent
86c0d6c0b0
commit
7d880ed2fd
3 changed files with 90 additions and 40 deletions
Binary file not shown.
|
|
@ -158,6 +158,34 @@ void render_wrecks(Game *g) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Per-type live silhouette size (parity with snapshot SHOT_UNIT_SCALE kinds). */
|
||||
static int unit_screen_sz(UnitType t) {
|
||||
switch (t) {
|
||||
case UT_INFANTRY: return 36;
|
||||
case UT_MUTANT: return 38;
|
||||
case UT_JEEP:
|
||||
case UT_BUGGY: return 40;
|
||||
case UT_FLAME:
|
||||
case UT_MISSILE:
|
||||
case UT_MEDIC: return 42;
|
||||
case UT_ARTILLERY:
|
||||
case UT_HARVESTER: return 46;
|
||||
case UT_TANK: return 48;
|
||||
case UT_BEAST: return 50;
|
||||
case UT_RAVAGER: return 52;
|
||||
default: return 41;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unrotated ground shadow disc (must sit under rotated unit tex). */
|
||||
static void draw_unit_shadow(SDL_Renderer *ren, int cx, int cy, int rad) {
|
||||
SDL_SetRenderDrawColor(ren, 55, 48, 28, 200);
|
||||
for (int j = -rad; j <= rad; j++) {
|
||||
int half = (int)sqrtf((float)(rad * rad - j * j));
|
||||
SDL_RenderDrawLine(ren, cx - half + 2, cy + j + 3, cx + half + 2, cy + j + 3);
|
||||
}
|
||||
}
|
||||
|
||||
void render_units(Game *g) {
|
||||
for (int i = 0; i < g->unit_count; i++) {
|
||||
Unit *u = &g->units[i];
|
||||
|
|
@ -166,36 +194,40 @@ void render_units(Game *g) {
|
|||
int tx = (int)(u->x / TILE), ty = (int)(u->y / TILE);
|
||||
if (!map_in_bounds(&g->map, tx, ty) || g->map.fog[ty*g->map.w + tx] != 2) continue;
|
||||
}
|
||||
/* Match snapshot SHOT_UNIT_SCALE 1.45 → live silhouette ~41px */
|
||||
int sz = 41;
|
||||
int sz = unit_screen_sz(u->type);
|
||||
int cx = (int)(u->x - g->cam.x), cy = (int)(u->y - g->cam.y);
|
||||
/* Ground shadow before rotated body so units lift off sand. */
|
||||
draw_unit_shadow(g->ren, cx, cy, sz / 4 + 4);
|
||||
SDL_Texture *tex = g->spr.unit[u->type][u->faction];
|
||||
draw_tex_world(g, tex, u->x, u->y, sz, sz, u->heading, 255);
|
||||
/* selection ring */
|
||||
/* selection ring — larger for heavy chassis */
|
||||
if (u->selected) {
|
||||
int cx = (int)(u->x - g->cam.x), cy = (int)(u->y - g->cam.y);
|
||||
int rad = (u->type == UT_TANK || u->type == UT_BEAST || u->type == UT_RAVAGER)
|
||||
? sz / 2 + 4 : sz / 2 + 2;
|
||||
SDL_SetRenderDrawColor(g->ren, 120, 255, 120, 220);
|
||||
for (int a = 0; a < 360; a += 12) {
|
||||
int px = cx + (int)(cosf(a*3.14159f/180)*22);
|
||||
int py = cy + (int)(sinf(a*3.14159f/180)*22);
|
||||
int px = cx + (int)(cosf(a * 3.14159f / 180) * rad);
|
||||
int py = cy + (int)(sinf(a * 3.14159f / 180) * rad);
|
||||
SDL_RenderDrawPoint(g->ren, px, py);
|
||||
}
|
||||
}
|
||||
/* health bar */
|
||||
if (u->hp < u->max_hp || u->selected) {
|
||||
int cx = (int)(u->x - g->cam.x), by = (int)(u->y - g->cam.y) - 26;
|
||||
int bw = 32;
|
||||
SDL_Rect bg = { cx - bw/2, by, bw, 4 };
|
||||
int by = cy - sz / 2 - 6;
|
||||
int bw = sz - 8;
|
||||
if (bw < 24) bw = 24;
|
||||
SDL_Rect bg = { cx - bw / 2, by, bw, 4 };
|
||||
SDL_SetRenderDrawColor(g->ren, 50, 50, 50, 255);
|
||||
SDL_RenderFillRect(g->ren, &bg);
|
||||
float f = u->hp / u->max_hp;
|
||||
SDL_Color c = (u->faction == FACTION_SURVIVOR) ? (SDL_Color){55,235,55,255}
|
||||
: (SDL_Color){255,40,255,255};
|
||||
SDL_Rect fg = { cx - bw/2, by, (int)(bw * f), 4 };
|
||||
SDL_Rect fg = { cx - bw / 2, by, (int)(bw * f), 4 };
|
||||
SDL_SetRenderDrawColor(g->ren, c.r, c.g, c.b, 255);
|
||||
SDL_RenderFillRect(g->ren, &fg);
|
||||
/* cargo indicator for harvesters */
|
||||
if (u->type == UT_HARVESTER && u->cargo > 0) {
|
||||
SDL_Rect cg = { cx - bw/2, by - 4, (int)(bw * u->cargo / 1000), 2 };
|
||||
SDL_Rect cg = { cx - bw / 2, by - 4, (int)(bw * u->cargo / 1000), 2 };
|
||||
SDL_SetRenderDrawColor(g->ren, 230, 190, 70, 255);
|
||||
SDL_RenderFillRect(g->ren, &cg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,65 +182,83 @@ SDL_Texture *sprites_make_unit(SDL_Renderer *r, UnitType t, Faction f) {
|
|||
}
|
||||
|
||||
/* ---------------- building sprites ---------------- */
|
||||
/* Bright concrete pad + BT_* interiors (parity with snapshot draw_bld). */
|
||||
SDL_Texture *sprites_make_bld(SDL_Renderer *r, BuildingType t, Faction f) {
|
||||
int w = bld_def(t)->w, h = bld_def(t)->h;
|
||||
int W = w * TILE, H = h * TILE;
|
||||
SDL_Surface *s = new_surf(W, H);
|
||||
SDL_Color base = faction_color(f);
|
||||
SDL_Color dark = darken(base, 0.5f);
|
||||
SDL_Color lite = lighten(base, 0.4f);
|
||||
/* Bright sand pad + dark ridge outline (arid wasteland plate). */
|
||||
SDL_Color wall = { 198, 168, 108, 255 };
|
||||
SDL_Color wall2 = { 155, 128, 78, 255 };
|
||||
const Uint8 ok = 28, og = 24, ob = 18;
|
||||
SDL_Color lite = lighten(base, 0.35f);
|
||||
const Uint8 ok = 22, og = 20, ob = 16;
|
||||
const Uint8 wall = 205, wall2 = 175;
|
||||
|
||||
fill_rect(s, 0, 0, W, H, wall2.r, wall2.g, wall2.b, 255);
|
||||
fill_rect(s, 2, 2, W - 4, H - 4, ok, og, ob, 255);
|
||||
fill_rect(s, 4, 4, W - 8, H - 8, wall.r, wall.g, wall.b, 255);
|
||||
ring(s, W/2, H/2, (W<H?W:H)/2 - 3, 2, dark.r, dark.g, dark.b, 255);
|
||||
/* Bright concrete pad on arid sand */
|
||||
fill_rect(s, 0, 0, W, H, ok, og, ob, 255);
|
||||
fill_rect(s, 2, 2, W - 4, H - 4, 210, 185, 130, 255);
|
||||
fill_rect(s, 4, 4, W - 8, H - 8, wall2, (Uint8)(wall2 - 18), (Uint8)(wall2 - 45), 255);
|
||||
fill_rect(s, 5, 5, W - 10, H - 10, wall, (Uint8)(wall - 22), (Uint8)(wall - 55), 255);
|
||||
fill_rect(s, 5, 5, W - 10, 6, (Uint8)(wall + 30), (Uint8)(wall + 10), (Uint8)(wall - 20), 255);
|
||||
|
||||
switch (t) {
|
||||
case BT_BASE:
|
||||
disc(s, W/2, H/2, W/4, base.r, base.g, base.b, 255);
|
||||
disc(s, W/2, H/2, W/6, lite.r, lite.g, lite.b, 255);
|
||||
line(s, W/2, H/2, W/2, 4, 200, 200, 60, 255);
|
||||
fill_rect(s, 5, 5, W - 10, H - 10, ok, og, ob, 255);
|
||||
fill_rect(s, 7, 7, W - 14, H - 14, base.r, base.g, base.b, 255);
|
||||
disc(s, W/2, H/2, W/4, lite.r, lite.g, lite.b, 255);
|
||||
disc(s, W/2, H/2, W/6, 255, 250, 180, 255);
|
||||
line(s, W/2, H/2, W/2, 4, 220, 210, 80, 255);
|
||||
fill_rect(s, W/2 - 2, 4, 4, H/3, 200, 180, 60, 255); /* antenna mast */
|
||||
break;
|
||||
case BT_WARFACTORY:
|
||||
fill_rect(s, 8, 8, W-16, H-16, dark.r, dark.g, dark.b, 255);
|
||||
fill_rect(s, 12, 12, W-24, 10, base.r, base.g, base.b, 255);
|
||||
fill_rect(s, 12, H-24, W-24, 10, base.r, base.g, base.b, 255);
|
||||
fill_rect(s, 5, 5, W - 10, H - 10, ok, og, ob, 255);
|
||||
fill_rect(s, 7, 7, W - 14, H - 14, base.r, base.g, base.b, 255);
|
||||
fill_rect(s, 10, 10, W - 20, 12, lite.r, lite.g, lite.b, 255);
|
||||
fill_rect(s, 10, H - 24, W - 20, 12, lite.r, lite.g, lite.b, 255);
|
||||
fill_rect(s, W/2 - 4, 8, 8, H - 16, 35, 35, 40, 255); /* bay door */
|
||||
break;
|
||||
case BT_REFINERY:
|
||||
disc(s, W/2, H/2, W/4, 120, 100, 60, 255);
|
||||
ring(s, W/2, H/2, W/4 - 3, 3, 60, 50, 40, 255);
|
||||
disc(s, W/2, H/2, W/4 + 2, ok, og, ob, 255);
|
||||
disc(s, W/2, H/2, W/4, 200, 165, 85, 255);
|
||||
ring(s, W/2, H/2, W/4 - 3, 3, 90, 70, 45, 255);
|
||||
fill_rect(s, 8, H - 14, W - 16, 8, 140, 110, 55, 255); /* base slab */
|
||||
break;
|
||||
case BT_POWER:
|
||||
disc(s, W/2, H/2, W/3, 80, 120, 160, 255);
|
||||
line(s, W/2, 4, W/2, H-4, 220, 240, 255, 255);
|
||||
line(s, 4, H/2, W-4, H/2, 220, 240, 255, 255);
|
||||
disc(s, W/2, H/2, W/3 + 1, ok, og, ob, 255);
|
||||
disc(s, W/2, H/2, W/3, 100, 160, 210, 255);
|
||||
line(s, W/2, 4, W/2, H - 4, 230, 245, 255, 255);
|
||||
line(s, 4, H/2, W - 4, H/2, 230, 245, 255, 255);
|
||||
disc(s, W/2, H/2, 4, 250, 252, 255, 255);
|
||||
break;
|
||||
case BT_TURRET:
|
||||
disc(s, W/2, H/2, W/3, dark.r, dark.g, dark.b, 255);
|
||||
fill_rect(s, 4, H - 10, W - 8, 8, 55, 50, 42, 255);
|
||||
disc(s, W/2, H/2, W/3 + 1, ok, og, ob, 255);
|
||||
disc(s, W/2, H/2, W/3, base.r, base.g, base.b, 255);
|
||||
disc(s, W/2, H/2, W/5, lite.r, lite.g, lite.b, 255);
|
||||
line(s, W/2, H/2, W/2 + 12, H/2 - 12, 40, 40, 45, 255);
|
||||
line(s, W/2, H/2, W/2 + 14, H/2 - 14, 30, 28, 24, 255);
|
||||
disc(s, W/2 + 12, H/2 - 12, 2, 255, 200, 80, 255); /* barrel tip */
|
||||
break;
|
||||
case BT_WALL:
|
||||
fill_rect(s, 2, 2, W-4, H-4, 70, 66, 60, 255);
|
||||
line(s, 2, 2, W-2, H-2, 40, 38, 34, 255);
|
||||
fill_rect(s, 1, 1, W - 2, H - 2, ok, og, ob, 255);
|
||||
fill_rect(s, 2, 2, W - 4, H - 4, 175, 155, 120, 255);
|
||||
fill_rect(s, 3, 3, W - 6, 5, 210, 190, 150, 255);
|
||||
line(s, 2, 2, W - 2, H - 2, 60, 52, 42, 255);
|
||||
break;
|
||||
case BT_REPAIR:
|
||||
fill_rect(s, 8, 8, W-16, H-16, dark.r, dark.g, dark.b, 255);
|
||||
fill_rect(s, 7, 7, W - 14, H - 14, ok, og, ob, 255);
|
||||
fill_rect(s, 9, 9, W - 18, H - 18, base.r, base.g, base.b, 255);
|
||||
ring(s, W/2, H/2, W/4, 3, 120, 220, 120, 255);
|
||||
line(s, W/2 - 12, H/2, W/2 + 12, H/2, 120, 220, 120, 255);
|
||||
line(s, W/2, H/2 - 12, W/2, H/2 + 12, 120, 220, 120, 255);
|
||||
break;
|
||||
case BT_RESEARCH:
|
||||
fill_rect(s, 8, 8, W-16, H-16, dark.r, dark.g, dark.b, 255);
|
||||
disc(s, W/2, H/2, W/5, 180, 150, 60, 255);
|
||||
line(s, W/2, 6, W/2, H-6, 220, 220, 150, 255);
|
||||
line(s, 6, H/2, W-6, H/2, 220, 220, 150, 255);
|
||||
fill_rect(s, 7, 7, W - 14, H - 14, ok, og, ob, 255);
|
||||
fill_rect(s, 9, 9, W - 18, H - 18, base.r, base.g, base.b, 255);
|
||||
disc(s, W/2, H/2, W/5, 210, 180, 80, 255);
|
||||
line(s, W/2, 6, W/2, H - 6, 230, 230, 160, 255);
|
||||
line(s, 6, H/2, W - 6, H/2, 230, 230, 160, 255);
|
||||
break;
|
||||
default:
|
||||
(void)dark;
|
||||
break;
|
||||
}
|
||||
SDL_Texture *tex = SDL_CreateTextureFromSurface(r, s);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue