Frontline Run
của MusicBar, thanh tiến trình
Một màn bắn súng pixel: anh lính đột kích lao tới chỗ đang phát, bắn theo nhịp trống, hạ lính, xe tăng, trực thăng dọc đường, hết bài thì gặp trùm robot khổng lồ.
Cách cài, mã SHA-256 và mã nguồn
Bấm Áp dụng: MusicBar tự tải về, kiểm tra mã SHA-256 rồi mặc lên taskbar; có rồi thì mặc luôn. Cần MusicBar 1.8 trở lên.
SHA-256 559179392989b48c93ec06b933de3d9a332d707a33a8d28e246336a62705ab54
//! name: Frontline Run
//! author: MusicBar
//! kind: progress
//! description: The song is a run-and-gun level in chunky pixel art: a commando charges to the playhead firing on the beat, through riflemen, tanks and gunships that blow up as he passes, and the song ends on a giant walker boss.
// Everything is drawn on a grid of whole pixels (doubled on tall taskbars), counted from the screen edge.
// A color as 0xRRGGBB: one shader constant instead of three.
float3 hx(float h) { return floor(fmod(float3(h / 65536.0, h / 256.0, h), 256.0)) / 255.0; }
float hash1(float n) { return frac(sin(n * 91.345) * 47453.5453); }
float hash2(float2 p) { return frac(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }
float noise2(float2 p)
{
float2 i = floor(p);
float2 f = frac(p);
f = f * f * (3.0 - 2.0 * f);
float a = hash2(i), b = hash2(i + float2(1, 0)), c = hash2(i + float2(0, 1)), d = hash2(i + float2(1, 1));
return lerp(lerp(a, b, f.x), lerp(c, d, f.x), f.y);
}
// 1 inside the rectangle of whole pixels from (x0, y0) to (x1, y1), both ends included.
float B(float2 p, float x0, float y0, float x1, float y1)
{
return step(x0, p.x) * step(p.x, x1) * step(y0, p.y) * step(p.y, y1);
}
float4 over(float4 under, float3 rgb, float m) { return lerp(under, float4(rgb, 1.0), saturate(m)); }
// Ordered 2x2 dither, for gradients in a few steps the way old games did them.
float bayer(float2 p) { return frac((fmod(p.x, 2.0) * 2.0 + fmod(p.y, 2.0) * 3.0) / 4.0); }
// ------------------------------------------------------------------ a soldier, ours or theirs
// p: pixels from the feet, facing right. run: stride phase. fire: muzzle flash on. hero: our commando's
// headband and colors, else a helmeted rifleman.
float4 trooper(float2 p, float run, float fire, float hero, float t)
{
// Painted as an old console would: each rectangle sets which palette entry the pixel takes (the last one
// wins), and the color is looked up once at the end. One number to carry instead of a color per layer,
// which kept ps_3_0 inside its 32 temporary registers.
float swing = round(sin(run) * 2.0);
float bob = abs(round(sin(run)));
p.y -= bob;
float kick = -step(0.5, fire);
float id = 0.0;
id = B(p, -1 - swing, 2, 0 - swing, 7) > 0.5 ? 1.0 : id; // back leg
id = B(p, -2 - swing, 0, 0 - swing, 1 + bob) > 0.5 ? 2.0 : id; // back boot
id = B(p, -1 + swing, 2, 0 + swing, 7) > 0.5 ? 3.0 : id; // front leg
id = B(p, -1 + swing, 0, 1 + swing, 1 + bob) > 0.5 ? 4.0 : id; // front boot
id = B(p, -2, 8, 2, 8) > 0.5 ? 5.0 : id; // belt
id = B(p, -2, 9, 2, 14) > 0.5 ? 6.0 : id; // vest
id = B(p, -1, 13, 1, 14) > 0.5 ? 7.0 : id; // its lit top
id = B(p, 2, 9, 2, 14) + B(p, -2, 9, 2, 9) > 0.5 ? 8.0 : id; // its shadow
id = B(p, -4, 9, -3, 14) > 0.5 ? 9.0 : id; // pack
id = B(p, -1, 15, 2, 18) > 0.5 ? 10.0 : id; // face
id = B(p, -1, 15, -1, 18) > 0.5 ? 11.0 : id; // jaw shadow
id = B(p, 2, 17, 2, 17) > 0.5 ? 12.0 : id; // eye
float wave = round(sin(t * 14.0 + p.x * 0.9) * 0.7);
float tails = B(p, -6, 17 + wave, -3, 18 + wave) * step(p.x + 6.0 - 4.0 * step(17.5 + wave, p.y), 4.5);
id = hero > 0.5 && B(p, -2, 19, 2, 20) + B(p, -2, 16, -2, 18) > 0.5 ? 13.0 : id; // hair
id = hero > 0.5 && B(p, -2, 18, 2, 18) + tails > 0.5 ? 14.0 : id; // red headband
id = hero < 0.5 && B(p, -2, 18, 3, 20) + B(p, -3, 18, 4, 18) > 0.5 ? 15.0 : id; // helmet
id = hero < 0.5 && B(p, -1, 20, 1, 20) > 0.5 ? 16.0 : id; // its shine
id = B(p, -2 + kick, 11, 0 + kick, 12) > 0.5 ? 17.0 : id; // stock
id = B(p, 0 + kick, 12, 9 + kick, 13) + B(p, 10 + kick, 13, 12 + kick, 13) > 0.5 ? 18.0 : id; // rifle
id = B(p, 1 + kick, 13, 8 + kick, 13) > 0.5 ? 19.0 : id; // its shine
id = B(p, 4 + kick, 10, 5 + kick, 11) > 0.5 ? 20.0 : id; // magazine
id = B(p, 1 + kick, 12, 2 + kick, 12) + B(p, 6 + kick, 12, 6 + kick, 12) > 0.5 ? 10.0 : id; // hands
float flash = fire * B(p, 13, 12, 16, 14) * step(abs(p.y - 13.0) + abs(p.x - 14.5) * 0.6, 2.2);
id = flash > 0.5 ? (abs(p.y - 13.0) < 0.5 ? 22.0 : 21.0) : id;
float3 pants = hero > 0.5 ? hx(0x857347) : hx(0x5c6675);
float3 vest = hero > 0.5 ? hx(0x4c7330) : hx(0x6b788c);
float3 c = id < 1.5 ? pants * 0.72
: id < 2.5 ? hx(0x291a12)
: id < 3.5 ? pants
: id < 4.5 ? hx(0x332117)
: id < 5.5 ? hx(0x52361f)
: id < 6.5 ? vest
: id < 7.5 ? min(vest * 1.3, 1.0)
: id < 8.5 ? vest * 0.7
: id < 9.5 ? (hero > 0.5 ? hx(0x3d4c24) : hx(0x4c5461))
: id < 10.5 ? hx(0xf5ba8c)
: id < 11.5 ? hx(0xc99873)
: id < 12.5 ? hx(0x1a0d0d)
: id < 13.5 ? hx(0x3d2414)
: id < 14.5 ? hx(0xe0241c)
: id < 15.5 ? hx(0x4c5c47)
: id < 16.5 ? hx(0x677c60)
: id < 17.5 ? hx(0x664224)
: id < 18.5 ? hx(0x3d404a)
: id < 19.5 ? hx(0x6e7385)
: id < 20.5 ? hx(0x31333b)
: id < 21.5 ? hx(0xffd94c)
: hx(0xffffe6);
return float4(c, step(0.5, id));
}
// The same soldier with a dark pixel edge on his lower right, as if lit from the upper left: two extra
// lookups instead of four, which kept the shader under the instruction count WPF and the GPU accept.
float4 outlined(float2 p, float run, float fire, float hero, float t)
{
float4 s = trooper(p, run, fire, hero, t);
if (s.a > 0.5) return s;
// The one-pixel steps come from the bar's size (always 1 when it runs) so the compiler cannot fold them
// into every rectangle of the sprite, which ran it out of constant registers.
float2 ox = float2(step(0.0, size.x), 0.0);
float2 oy = ox.yx;
float n = trooper(p - ox, run, fire, hero, t).a + trooper(p + oy, run, fire, hero, t).a;
return float4(0.06, 0.05, 0.07, step(0.5, n));
}
// ------------------------------------------------------------------ explosions, fire and smoke
// d: pixels from the blast's center. k: 0 to 1 through its life. r: its size in pixels.
float4 boom(float2 d, float k, float r, float seed)
{
float frame = floor(k * 14.0);
float rr = r * (0.35 + 0.75 * sqrt(k));
float n = noise2(d * 0.28 + seed + frame * 3.1);
float inten = saturate(1.0 - length(d * float2(1.0, 1.15)) / (rr * (0.7 + 0.6 * n)));
float heat = inten * (1.2 - k * 1.1);
float3 c = heat > 0.85 ? hx(0xffffd9)
: heat > 0.6 ? hx(0xffdb4c)
: heat > 0.38 ? hx(0xff851f)
: heat > 0.18 ? hx(0xd13314)
: hx(0x3b3333) * (0.8 + 0.4 * n);
float a = step(0.02, inten) * step(k, 0.98) * (heat > 0.18 ? 1.0 : step(bayer(d + seed), 1.0 - k * 0.8));
// Debris flying out and falling: one fragment per sixth of the circle, so no loop is needed.
float sector = floor((atan2(d.y + 30.0 * k * k, d.x) / 6.2832 + 0.5) * 6.0);
float ang = (sector + 0.2 + 0.6 * hash1(seed + sector * 7.3)) / 6.0 * 6.2832 - 3.1416;
float sp = r * (0.9 + hash1(seed + sector * 3.7));
float2 q = float2(cos(ang), sin(ang)) * sp * k - float2(0.0, 30.0 * k * k);
float deb = B(round(d - q), 0, 0, 1, 1) * step(0.0, sin(ang) + 0.6);
c = deb > 0.5 && a < 0.5 ? hx(0x59402e) : c;
a = max(a, step(0.5, deb) * step(k, 0.85));
return float4(c, a);
}
float4 flames(float2 d, float w, float hgt, float t, float seed)
{
// A fire burning on a wreck: tongues of flame flickering, taller when the music is loud.
float h = hgt * (0.5 + 0.5 * noise2(float2(d.x * 0.5 + seed, t * 9.0))) * (0.7 + 0.6 * spectrum(frac(seed * 0.13)));
float inside = step(abs(d.x), w) * step(0.0, d.y) * step(d.y, h * (1.0 - pow(abs(d.x) / (w + 1.0), 2.0)));
float v = d.y / max(h, 1.0);
float3 c = v < 0.35 ? hx(0xffe666) : (v < 0.7 ? hx(0xff8c1f) : hx(0xd93814));
return float4(c, inside);
}
float4 smoke(float2 d, float w, float t, float seed)
{
// A column of smoke rising and leaning with the wind.
float2 q = float2(d.x - d.y * 0.35, d.y);
float n = noise2(float2(q.x * 0.22 + seed, q.y * 0.14 - t * 1.4));
float body = step(abs(q.x), w + d.y * 0.25) * step(0.0, d.y);
float a = body * step(0.45 + d.y * 0.012, n);
a *= step(bayer(d), 1.2 - d.y * 0.03);
return float4(hx(0x333036) * (0.8 + 0.5 * n), a);
}
// ------------------------------------------------------------------ the enemy's machines
float4 tank(float2 p, float alive, float fire, float t)
{
// Facing left; p in pixels from its middle at the ground. Palette entries, as for the soldiers.
float roll = alive * floor(t * 8.0);
float id = 0.0;
id = B(p, -12, 0, 12, 4) > 0.5 ? 1.0 : id; // tracks
id = B(p, -12, 4, 12, 4) * step(0.5, frac((p.x + roll) * 0.5)) > 0.5 ? 2.0 : id; // their links, rolling
float2 wq = float2(frac((p.x + 9.0) / 4.5) * 4.5 - 2.25, p.y - 2.0);
float wheelRow = step(-11.5, p.x) * step(p.x, 11.5);
id = wheelRow * step(length(wq), 1.6) > 0.5 ? 3.0 : id; // road wheels
id = wheelRow * step(length(wq), 0.6) > 0.5 ? 4.0 : id; // their hubs
id = B(p, -13, 5, 12, 9) > 0.5 ? 5.0 : id; // hull
id = B(p, -12, 9, 11, 9) > 0.5 ? 6.0 : id; // its lit edge
id = B(p, -13, 5, 12, 5) > 0.5 ? 7.0 : id; // its shadow
id = B(p, 3, 7, 8, 7) > 0.5 ? 8.0 : id; // white stripe
id = B(p, -4, 10, 6, 13) - B(p, -4, 13, -4, 13) - B(p, 6, 13, 6, 13) > 0.5 ? 5.0 : id; // turret
id = B(p, -3, 13, 5, 13) > 0.5 ? 6.0 : id;
id = B(p, 0, 14, 3, 14) > 0.5 ? 1.0 : id; // hatch
float recoil = step(0.5, fire);
float droop = (1.0 - alive) * step(p.x, -10.0);
id = B(p, -17 + recoil, 11 - droop, -5, 12) > 0.5 ? 9.0 : id; // barrel
id = fire * alive * step(length((p - float2(-19, 11.5)) * float2(0.7, 1.0)), 2.2) > 0.5 ? 10.0 : id;
float3 c = id < 1.5 ? hx(0x262624) : id < 2.5 ? hx(0x444440) : id < 3.5 ? hx(0x54544a) : id < 4.5 ? hx(0x8c8c7a)
: id < 5.5 ? hx(0x616b40) : id < 6.5 ? hx(0x7a8650) : id < 7.5 ? hx(0x444b2d) : id < 8.5 ? hx(0xd9d1b2)
: id < 9.5 ? hx(0x474c33) : hx(0xffe666);
c = alive < 0.5 ? c * 0.3 + hx(0x0a0500) : c;
return float4(c, step(0.5, id));
}
float4 gunship(float2 p, float alive, float t)
{
// A helicopter facing left; p in pixels from its middle.
float spin = alive * step(0.5, frac(t * 18.0));
float id = 0.0;
id = step(length(p * float2(0.13, 0.32)), 1.0) > 0.5 ? 1.0 : id; // body
id = step(length((p - float2(1, 1.5)) * float2(0.16, 0.6)), 1.0) > 0.5 ? 2.0 : id; // its lit back
id = step(length((p - float2(-5, 0.5)) * float2(0.4, 0.45)), 1.0) > 0.5 ? 3.0 : id; // canopy
id = B(p, -6, 1, -5, 1) > 0.5 ? 4.0 : id; // glint
id = B(p, 6, 0, 17, 1) + B(p, 16, 0, 17, 4) > 0.5 ? 5.0 : id; // tail
id = B(p, -5, -5, 5, -5) + B(p, -3, -4, -3, -3) + B(p, 3, -4, 3, -3) > 0.5 ? 6.0 : id; // skids
// Rotors: a blur that flickers between frames.
id = B(p, -13, 5, 13, 5) * step(0.5, frac(p.x * 0.5 + spin * 0.5)) * alive + B(p, -1, 4, 1, 4) > 0.5 ? 7.0 : id;
id = step(length(p - float2(17, 4)), 2.5 * alive) * step(0.5, frac((p.x + p.y) * 0.5 + spin * 0.5)) > 0.5 ? 7.0 : id;
float3 c = id < 1.5 ? hx(0x4c5c4c) : id < 2.5 ? hx(0x677c67) : id < 3.5 ? hx(0x73cce6) : id < 4.5 ? hx(0xd9f2ff)
: id < 5.5 ? hx(0x414e41) : id < 6.5 ? hx(0x1f1f1f) : hx(0x333338);
c = alive < 0.5 ? c * 0.35 : c;
return float4(c, step(0.5, id));
}
float4 walker(float2 p, float t, float hp, float ph)
{
// The boss: a scrap-iron crab on four legs, two cannons forward, hazard stripes, a red core that pulses.
float stride = round(sin(t * 2.5 + ph) * 1.5);
float leg = floor((p.x + 19.0) / 12.0);
float lx = -18.0 + leg * 12.0;
float lift = fmod(leg, 2.0) < 0.5 ? stride : -stride;
float onLeg = step(0.0, leg) * step(leg, 3.0);
float id = 0.0;
id = onLeg * B(p, lx, max(lift, 0.0), lx + 2, 10) > 0.5 ? 1.0 : id; // legs
id = onLeg * B(p, lx - 1, 9, lx + 4, 12 + lift * 0.5) > 0.5 ? 2.0 : id; // knees
id = onLeg * B(p, lx - 2, max(lift, 0.0), lx + 3, 1 + max(lift, 0.0)) > 0.5 ? 1.0 : id; // feet
float shell = length((p - float2(0, 18)) * float2(0.042, 0.13));
id = step(shell, 1.0) > 0.5 ? 2.0 : id; // body
id = step(length((p - float2(-2, 21)) * float2(0.05, 0.3)), 1.0) > 0.5 ? 3.0 : id; // its lit top
id = step(length((p - float2(0, 14.5)) * float2(0.045, 0.5)), 1.0) > 0.5 ? 1.0 : id; // belly
// Hazard stripes along the belly.
id = step(length((p - float2(0, 14.5)) * float2(0.045, 0.5)), 1.0) * step(abs(p.y - 14.5), 0.6) * step(0.5, frac((p.x + p.y) / 6.0)) > 0.5 ? 6.0 : id;
id = step(length(frac(p * float2(0.2, 0.25)) - 0.5), 0.12) * step(shell, 0.85) > 0.5 ? 4.0 : id; // rivets
id = B(p, -34, 15, -20, 17) + B(p, -32, 20, -20, 21) > 0.5 ? 1.0 : id; // cannons
id = B(p, -34, 17, -20, 17) + B(p, -32, 21, -20, 21) > 0.5 ? 5.0 : id;
id = B(p, -38, 12, -34, 19) - B(p, -38, 15, -36, 16) > 0.5 ? 2.0 : id; // claw
// The core, brighter as it takes damage and on every beat.
float coreD = length((p - float2(-6, 17)) * float2(0.4, 0.5));
float pulse = 0.6 + 0.4 * sin(t * 6.0) + 0.6 * beat + (1.0 - hp);
id = step(coreD, 1.6) > 0.5 ? 7.0 : id;
id = step(coreD, 0.6) * step(0.8, pulse) > 0.5 ? 8.0 : id;
float3 c = id < 1.5 ? hx(0x242129) : id < 2.5 ? hx(0x4c4c57) : id < 3.5 ? hx(0x666675) : id < 4.5 ? hx(0x89899c)
: id < 5.5 ? hx(0x5b5b68) : id < 6.5 ? hx(0xe6b422)
: id < 7.5 ? lerp(hx(0x990d0d), hx(0xff9966), saturate(pulse - 0.6)) : hx(0xfff2cc);
return float4(c, step(0.5, id));
}
// ------------------------------------------------------------------ the level
float4 main(float2 uv : TEXCOORD) : COLOR
{
float s = max(1.0, floor(size.y / 34.0)); // pixel size: 1, or 2 on very tall taskbars
float W = floor(size.x / s), H = floor(size.y / s);
float2 P = floor(float2(uv.x * size.x, rise(uv) * size.y) / s);
float t = time;
float ground = 5.0; // the dirt is 0 to 4, they stand on 5
// 1 and 0 the compiler cannot see through: sprites drawn with fixed arguments would otherwise be folded
// into separate copies of every constant, more than ps_3_0 has registers for.
float one = step(0.0, size.x), zero = 1.0 - one;
float bossX = W - 70.0;
float heroX = floor(clamp(progress * W, 10.0, bossX - 46.0));
float bossHp = saturate((0.985 - progress) / 0.08);
float bossDead = step(0.997, progress); // the flag goes up once the blasts are over
float dx = P.x - heroX;
// ---------------------------------------------------------------- sky, a dusk in dithered bands
float hgt = P.y / max(H, 1.0);
float sky = saturate(1.25 - hgt * 1.5);
float band = floor(sky * 7.0 + bayer(P)) / 7.0;
float3 col = lerp(hx(0x1a1c45), hx(0xdb7845), band);
col = lerp(col, colorA.rgb * 0.6, 0.12);
// A low sun.
float sun = length((P - float2(W * 0.55, H * 0.38)) * float2(1.0, 1.0));
col = lerp(col, hx(0xffd180), step(sun, 6.0));
// Clouds drifting.
float cl = noise2(float2(P.x * 0.03 + t * 0.15, P.y * 0.12)) * smoothstep(H * 0.45, H * 0.9, P.y);
// Lit from below by the sunset at their rims, cooler in their cores.
col = lerp(col, cl > 0.7 ? hx(0xb98293) : hx(0xf7b48a), step(0.64, cl) * step(bayer(P), 0.8));
col = lerp(col, hx(0x8c5a78), step(0.58, cl) * step(cl, 0.64) * step(bayer(P), 0.5));
// Far ridges, then the ruined town and the jungle.
float ridge = ground + H * 0.16 + H * 0.12 * noise2(float2(P.x * 0.018, 3.0)) + 2.0 * noise2(float2(P.x * 0.15, 7.0));
col = lerp(col, hx(0x2e2442), step(P.y, floor(ridge)));
float lot = floor(P.x / 22.0);
float bh = ground + H * (0.22 + 0.25 * hash1(lot * 3.7));
float bx = frac(P.x / 22.0) * 22.0;
float building = step(P.y, bh) * step(2.0, bx) * step(bx, 18.0) * step(0.35, hash1(lot * 1.3));
// Ruins: broken tops, window holes; behind our man they burn.
building *= step(P.y, bh - floor(3.0 * noise2(float2(P.x * 0.4, lot))));
float hole = step(0.5, frac(bx / 4.0)) * step(0.5, frac(P.y / 4.0)) * step(P.y, bh - 3.0) * step(ground + 3.0, P.y);
float burning = step(P.x, heroX - 8.0) * step(0.5, hash2(float2(floor(bx / 4.0), floor(P.y / 4.0)) + lot));
float3 wallCol = hx(0x332b38);
float3 holeCol = lerp(hx(0x140f17), hx(0xff8c26) * (0.7 + 0.3 * sin(t * 9.0 + lot)), burning);
col = lerp(col, lerp(wallCol, holeCol, hole), building);
// Palms.
float palm = floor((P.x + 11.0) / 37.0);
float px0 = palm * 37.0 + 8.0 + floor(hash1(palm * 5.1) * 14.0);
float trunkH = ground + H * 0.4;
float trunkX = px0 + floor((P.y - ground) * 0.12);
float isTrunk = step(abs(P.x - trunkX), 0.5) * step(P.y, trunkH) * step(0.3, hash1(palm * 2.9));
float2 crown = P - float2(px0 + floor((trunkH - ground) * 0.12), trunkH);
float fr = 0.0;
[loop] for (int f = 0; f < 5; f++)
{
float a = -0.3 + f * 0.85 + 0.08 * sin(t * 1.5 + palm);
float2 dir = float2(cos(a), sin(a) * 0.55);
float along = dot(crown, dir);
float droopY = crown.y - (dir.y * along - 0.04 * along * along);
fr += step(0.0, along) * step(along, 9.0) * step(abs(droopY - 0.0) * step(0.0, 1.0), 0.8 + along * 0.05);
}
fr *= step(0.3, hash1(palm * 2.9));
col = lerp(col, hx(0x2b1f17), isTrunk);
col = lerp(col, hx(0x1a3d24), step(0.5, fr));
// ---------------------------------------------------------------- ground
float crater = 0.0;
float cratC = floor(P.x / 31.0);
float cratX = cratC * 31.0 + 15.0;
crater = step(P.x, heroX - 4.0) * step(0.55, hash1(cratC * 4.4)) * step(abs(P.x - cratX), 4.0);
float top = ground - crater * (abs(P.x - cratX) < 3.0 ? 2.0 : 1.0);
float3 dirt = hx(0x6b4a2b) * (0.85 + 0.25 * step(0.7, hash2(P)));
dirt = lerp(dirt, dirt * 0.7, step(P.y, 1.0));
col = lerp(col, dirt, step(P.y, top - 1.0));
float3 grassCol = P.x < heroX ? hx(0x4c5229) : hx(0x548533);
col = lerp(col, grassCol, step(abs(P.y - top), 0.5) * step(0.25, hash2(P * 1.7)));
// Spent casings behind him.
col = lerp(col, hx(0xf2bf40), step(abs(P.y - top), 0.5) * step(P.x, heroX - 2.0) * step(0.93, hash2(P + 9.0)));
float4 o;
// ---------------------------------------------------------------- the enemy, cell by cell
float cw = 64.0;
float cell = floor(P.x / cw);
float kind = floor(hash1(cell * 7.13) * 4.0); // 0 riflemen behind sandbags, 1 tank, 2 gunship, 3 two riflemen
kind = cell < 1.0 || (cell + 1.0) * cw > bossX - 20.0 ? -1.0 : kind;
float ex = cell * cw + 24.0 + floor(hash1(cell * 3.3) * 18.0);
float passed = heroX - ex; // how far our man has gone past it
float aware = step(-110.0, passed) * step(passed, -24.0); // within range ahead: shooting at him
float shot = saturate((passed + 24.0) / 18.0); // 0 alive ... 1 blast over: he shoots them from 24 px off
float alive = step(passed, -24.0);
float enemyFire = aware * step(0.6, frac(t * 2.2 + hash1(cell)));
if (kind == 0.0 || kind == 3.0)
{
if (kind == 0.0)
{
// Sandbags.
float2 sb = P - float2(ex - 6.0, ground);
float bag = step(length((frac(float2(sb.x / 5.0 + 0.5 * floor(sb.y / 3.0), sb.y / 3.0)) - 0.5) * float2(1.0, 1.4)), 0.55);
float wall = B(sb, -1, 0, 6, 8) * bag;
col = lerp(col, hx(0x9e8759) * (0.8 + 0.25 * step(0.6, frac(sb.y / 3.0))), wall);
}
// Two riflemen stand 13 pixels apart in a pair: each pixel draws the one whose feet are nearer.
float m = kind == 3.0 && P.x > ex + 6.5 ? 1.0 : 0.0;
float mx = ex + m * 13.0;
float mp = heroX - mx;
float k = saturate((mp + 24.0) / 16.0);
float2 lp = P - float2(mx, ground);
lp.x = -lp.x; // they face left, toward him
// Alive he aims and fires; hit, he flashes white, is thrown back and gone in a puff.
float hit = step(-24.0, mp);
float2 fly = lp - hit * float2(-k * 10.0, k * 9.0 - k * k * 12.0);
float shoots = (1.0 - hit) * step(-110.0, mp) * step(0.6, frac(t * 2.4 + m * 0.37 + hash1(cell)));
[branch] if (k < 1.0)
{
float4 tr = trooper(fly, zero, shoots, zero, t);
tr.rgb = hit > 0.5 && k < 0.15 ? hx(0xffffff) : tr.rgb;
col = lerp(col, tr.rgb, tr.a * (hit > 0.5 ? step(k, 0.55) : 1.0));
}
[branch] if (hit > 0.5 && k < 1.0)
{
float4 pf = boom(P - float2(mx + 2.0, ground + 9.0), k, 7.0 * one, mx);
col = lerp(col, pf.rgb, pf.a * step(0.3, k));
}
}
else if (kind == 1.0)
{
float2 tp = P - float2(ex, ground);
o = tank(tp, alive, enemyFire, t);
col = lerp(col, o.rgb, o.a);
if (alive < 0.5)
{
o = smoke(P - float2(ex + 2.0, ground + 13.0), 2.0 * one, t, ex);
col = lerp(col, o.rgb, o.a * step(shot, 2.0));
o = flames(P - float2(ex + 1.0, ground + 13.0), 5.0 * one, 7.0 * one, t, ex);
col = lerp(col, o.rgb, o.a);
o = boom(P - float2(ex, ground + 9.0), shot, 16.0 * one, ex);
// The blast lights up everything around it.
col += hx(0xff8c33) * exp(-length(P - float2(ex, ground + 9.0)) * 0.05) * (1.0 - shot) * step(0.001, shot) * 0.7;
col = lerp(col, o.rgb, o.a);
}
}
else if (kind == 2.0)
{
float alt = min(H - 9.0, ground + 24.0);
float hover = round(sin(t * 2.0 + cell) * 1.5);
float fall = alive > 0.5 ? 0.0 : min(shot * 2.0, 1.0);
float2 hp = P - float2(ex, alt + hover - fall * (alt - ground - 4.0));
if (alive > 0.5)
{
// Its searchlight sweeping the ground ahead of him.
float2 beamD = P - float2(ex - 6.0, alt + hover - 2.0);
float ang = -2.2 + 0.35 * sin(t * 1.3 + cell);
float2 bdir = float2(cos(ang), sin(ang));
float along = dot(beamD, bdir);
float across = abs(beamD.x * bdir.y - beamD.y * bdir.x);
float beam = step(0.0, along) * step(across, 1.0 + along * 0.28) * step(ground, P.y);
col += hx(0xfff2bf) * beam * 0.13 * step(bayer(P), 0.6);
}
o = gunship(hp, alive, t);
col = lerp(col, o.rgb, o.a);
if (alive < 0.5)
{
o = boom(P - float2(ex, alt - fall * (alt - ground - 4.0)), shot, 13.0 * one, ex);
col += hx(0xff8c33) * exp(-length(P - float2(ex, alt - fall * (alt - ground - 4.0))) * 0.05) * (1.0 - shot) * step(0.001, shot) * 0.6;
col = lerp(col, o.rgb, o.a);
o = flames(P - float2(ex, ground), 6.0 * one, 6.0 * step(1.0, shot * 2.0), t, ex + 1.0);
col = lerp(col, o.rgb, o.a);
o = smoke(P - float2(ex + 1.0, ground + 4.0), 2.0 * one, t, ex + 5.0);
col = lerp(col, o.rgb, o.a * step(1.0, shot * 2.0));
}
}
// Their bullets: red pellets flying back at him from whatever is shooting.
float nearCell = floor((heroX + 40.0) / cw);
float nKind = floor(hash1(nearCell * 7.13) * 4.0);
nKind = nearCell < 1.0 || (nearCell + 1.0) * cw > bossX - 20.0 ? -1.0 : nKind;
float nex = nearCell * cw + 24.0 + floor(hash1(nearCell * 3.3) * 18.0);
float nAlive = step(heroX - nex, -24.0);
float gunY = nKind == 1.0 ? ground + 11.0 : (nKind == 2.0 ? min(H - 9.0, ground + 24.0) - 2.0 : ground + 13.0);
float pelletY = lerp(gunY, ground + 13.0, saturate((nex - P.x) / max(nex - heroX, 1.0)));
float pel = step(abs(P.y - round(pelletY)), 0.5) * step(heroX + 4.0, P.x) * step(P.x, nex - 14.0) * nAlive * step(nex - heroX, 96.0) * (nKind >= 0.0 ? 1.0 : 0.0);
pel *= step(frac((P.x + t * 70.0) / 23.0), 0.09);
col = lerp(col, hx(0xff4033), pel);
col = lerp(col, hx(0xffccb2), pel * step(frac((P.x + t * 70.0) / 23.0), 0.045));
// ---------------------------------------------------------------- the boss
float2 bp = P - float2(bossX + 30.0, ground);
if (abs(bp.x) < 46.0)
{
float bossK = saturate((progress - 0.985) / 0.012);
if (bossK < 1.0)
{
o = walker(bp, t, bossHp, zero);
o.rgb = bossHp < 0.3 && frac(t * 8.0) < 0.5 ? lerp(o.rgb, hx(0xff664c), 0.35) : o.rgb;
col = lerp(col, o.rgb, o.a * step(bossK, 0.6));
// Its health bar above it.
float2 hb = P - float2(bossX + 8.0, min(H - 3.0, ground + 33.0));
col = lerp(col, hx(0x140f14), B(hb, -1, -1, 44, 1));
col = lerp(col, lerp(hx(0xff3326), hx(0xffd94c), bossHp), B(hb, 0, 0, floor(43.0 * bossHp), 0));
// Cannon shells lobbed at him while he closes in.
float shell = step(length(P - float2(bossX - 6.0 - frac(t * 0.9) * 40.0, ground + 16.0 + sin(frac(t * 0.9) * 3.14) * 6.0)), 1.6) * (1.0 - bossDead);
col = lerp(col, hx(0xff9933), shell);
}
if (bossK > 0.0)
{
// Chain explosions all over it, then the wreck.
[loop] for (int e = 0; e < 5; e++)
{
float ek = saturate(bossK * 1.6 - e * 0.15);
float2 ec = float2(bossX + 30.0 + (hash1(e * 3.1) - 0.5) * 44.0, ground + 8.0 + hash1(e * 5.7) * 16.0);
o = boom(P - ec, ek, 11.0 + e * 2.0, e * 13.0);
col = lerp(col, o.rgb, o.a * step(0.001, ek));
}
o = walker(bp, zero, zero, zero);
col = lerp(col, o.rgb * 0.25, o.a * step(0.6, bossK) * step(P.y, ground + 9.0));
o = flames(P - float2(bossX + 26.0, ground + 6.0), 10.0 * one, 10.0 * one, t, 3.0 * one);
col = lerp(col, o.rgb, o.a * step(0.6, bossK));
}
// The flag, planted when it's over.
float2 fp = P - float2(bossX - 8.0, ground);
float wave = round(sin(t * 6.0 + fp.x * 0.8) * 0.8);
col = lerp(col, hx(0xbfb8a6), bossDead * B(fp, 0, 0, 0, 20));
col = lerp(col, hx(0x338c4c), bossDead * B(fp, 1, 13 + wave, 10, 19 + wave));
col = lerp(col, hx(0xfff2bf), bossDead * step(length(fp - float2(5.5, 16.0 + wave)), 1.5));
}
// ---------------------------------------------------------------- our man
if (dx > -12.0 && dx < 110.0)
{
float running = playing > 0.5 ? 1.0 : 0.0;
float run = t * 13.0 * running;
float bursts = (step(0.35, frac(t * (2.0 + 4.0 * level))) + beat) * (1.0 - step(0.985, progress)); // nothing left to shoot at the end
float fire = step(0.5, bursts) * step(0.5, frac(t * 22.0)) * running;
// Tracers streaking forward to whatever is ahead.
float target = nAlive > 0.5 && nKind >= 0.0 ? nex : heroX + 100.0;
target = min(target, bossX + 10.0);
float tr = step(abs(P.y - (ground + 13.0)), 0.5) * step(heroX + 17.0, P.x) * step(P.x, target);
float dash = frac((P.x - t * 260.0) / 13.0);
col = lerp(col, hx(0xfff299), tr * step(dash, 0.3) * step(0.5, bursts) * running);
col = lerp(col, hx(0xffffff), tr * step(dash, 0.1) * step(0.5, bursts) * running);
// Sparks where they hit.
float2 hit = P - float2(target - 2.0, ground + 13.0);
float spark = step(length(hit), 2.5) * step(0.5, frac(t * 15.0 + hash2(P))) * step(0.5, bursts) * running;
col = lerp(col, hx(0xffe680), spark);
// His muzzle flash lights the ground and the air in front of him.
col += hx(0xffc966) * fire * exp(-length(P - float2(heroX + 15.0, ground + 13.0)) * 0.12) * 0.5;
o = outlined(float2(dx, P.y - ground), run, fire, one, t);
col = lerp(col, o.rgb, o.a);
}
// On every beat the screen near him shakes a pixel and flashes, like a shot landing.
col += hx(0xffd999) * beat * 0.06 * exp(-abs(dx) * 0.02);
return paint(col, 0.95);
}