102 lines
5.4 KiB
JavaScript
102 lines
5.4 KiB
JavaScript
|
|
/* Robot Clash - opponent looks: makes the 3D league robots resemble their ComfyGen portraits
|
||
|
|
(assets/Sprites/opp_<id>.png). A look = a painted skin layer (same 512x256 layout as the player's
|
||
|
|
own drawing: left half top view, right half side view, front to the right) + a few extra model
|
||
|
|
parts that render3d.js adds (eyes, cab, bumps, track covers).
|
||
|
|
|
||
|
|
RC.LOOKS[id] = { pattern, accent2, eyes, cab, bumps, tracksLook, wheelScale }
|
||
|
|
RC.lookLayer(look, paint) -> canvas (cached per id), used as paint.layer with paint.drawn = true */
|
||
|
|
(function (root) {
|
||
|
|
'use strict';
|
||
|
|
const RC = root.RC;
|
||
|
|
const LW = 512, LH = 256;
|
||
|
|
const css = n => '#' + (n >>> 0).toString(16).padStart(6, '0');
|
||
|
|
|
||
|
|
RC.LOOKS = {
|
||
|
|
rustbucket: { pattern: 'rust', cab: true, wheelScale: 1.35, eyes: 0xffb040 },
|
||
|
|
tintoad: { pattern: 'rivets', bumps: true, eyes: 0xd8ff60 },
|
||
|
|
buzzkill: { pattern: 'hazard', tracksLook: true, eyes: 0xff3a20 },
|
||
|
|
flapjack: { pattern: 'twotone', accent2: 0xf2f2f2, eyes: 0x9fd8ff },
|
||
|
|
pincer: { pattern: 'twotone', accent2: 0xe0b030, eyes: 0xffd040 },
|
||
|
|
thunderclap: { pattern: 'scratches', eyes: 0xffa020 },
|
||
|
|
gravedigger: { pattern: 'dark', eyes: 0x50ff80 },
|
||
|
|
overlord: { pattern: 'redstripe', accent2: 0xd02020, eyes: 0xff2020 },
|
||
|
|
};
|
||
|
|
|
||
|
|
const cache = {};
|
||
|
|
RC.lookLayer = (id, paint) => {
|
||
|
|
if (cache[id]) return cache[id];
|
||
|
|
const look = RC.LOOKS[id];
|
||
|
|
if (!look || typeof document === 'undefined') return null;
|
||
|
|
const cv = document.createElement('canvas'); cv.width = LW; cv.height = LH;
|
||
|
|
const c = cv.getContext('2d');
|
||
|
|
let seed = 1; for (const ch of id) seed = (seed * 31 + ch.charCodeAt(0)) >>> 0;
|
||
|
|
const r = () => { seed = (seed * 1664525 + 1013904223) >>> 0; return seed / 4294967296; };
|
||
|
|
const halves = fn => { for (const h of [0, 1]) { c.save(); c.beginPath(); c.rect(h * 256, 0, 256, 256); c.clip(); c.translate(h * 256, 0); fn(h); c.restore(); } };
|
||
|
|
const scratches = (n, a) => {
|
||
|
|
for (let i = 0; i < n; i++) {
|
||
|
|
c.strokeStyle = `rgba(${r() < 0.6 ? '255,255,255' : '0,0,0'},${a * (0.5 + r())})`; c.lineWidth = 0.6 + r() * 1.6;
|
||
|
|
const x = r() * LW, y = r() * LH, ang = r() * 6.3, l = 6 + r() * 34;
|
||
|
|
c.beginPath(); c.moveTo(x, y); c.lineTo(x + Math.cos(ang) * l, y + Math.sin(ang) * l); c.stroke();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
const rivets = (step, col) => halves(() => {
|
||
|
|
c.fillStyle = col;
|
||
|
|
for (let x = 12; x < 256; x += step) for (const y of [12, 244]) { c.beginPath(); c.arc(x, y, 3.2, 0, 7); c.fill(); }
|
||
|
|
for (let y = 12; y < 256; y += step) for (const x of [12, 244]) { c.beginPath(); c.arc(x, y, 3.2, 0, 7); c.fill(); }
|
||
|
|
});
|
||
|
|
|
||
|
|
switch (look.pattern) {
|
||
|
|
case 'rust': // brown base with orange rust blotches and dark holes
|
||
|
|
for (let i = 0; i < 90; i++) {
|
||
|
|
c.fillStyle = `rgba(${150 + r() * 70 | 0},${60 + r() * 40 | 0},${20 + r() * 20 | 0},${0.25 + r() * 0.4})`;
|
||
|
|
c.beginPath(); c.ellipse(r() * LW, r() * LH, 6 + r() * 28, 4 + r() * 18, r() * 3, 0, 7); c.fill();
|
||
|
|
}
|
||
|
|
for (let i = 0; i < 40; i++) { c.fillStyle = `rgba(30,18,10,${0.3 + r() * 0.4})`; c.beginPath(); c.arc(r() * LW, r() * LH, 1 + r() * 4, 0, 7); c.fill(); }
|
||
|
|
rivets(40, 'rgba(40,25,15,.8)'); scratches(120, 0.12);
|
||
|
|
break;
|
||
|
|
case 'rivets': // panel lines + rivet rows
|
||
|
|
halves(() => {
|
||
|
|
c.strokeStyle = 'rgba(0,0,0,.35)'; c.lineWidth = 3;
|
||
|
|
for (const x of [86, 170]) { c.beginPath(); c.moveTo(x, 0); c.lineTo(x, 256); c.stroke(); }
|
||
|
|
c.beginPath(); c.moveTo(0, 128); c.lineTo(256, 128); c.stroke();
|
||
|
|
});
|
||
|
|
rivets(22, 'rgba(20,30,10,.85)'); scratches(80, 0.1);
|
||
|
|
break;
|
||
|
|
case 'hazard': // yellow/black stripes, darker band in the middle of the top
|
||
|
|
halves(h => {
|
||
|
|
c.fillStyle = '#16181c';
|
||
|
|
for (let k = -256; k < 512; k += 64) { c.beginPath(); c.moveTo(k, 0); c.lineTo(k + 32, 0); c.lineTo(k + 32 - 256, 256); c.lineTo(k - 256, 256); c.fill(); }
|
||
|
|
if (h === 0) { c.fillStyle = 'rgba(20,22,26,.9)'; c.fillRect(0, 96, 256, 64); }
|
||
|
|
});
|
||
|
|
scratches(140, 0.12);
|
||
|
|
break;
|
||
|
|
case 'twotone': // second colour on the top and as a band on the sides
|
||
|
|
c.fillStyle = css(look.accent2); c.fillRect(20, 30, 216, 196);
|
||
|
|
c.fillRect(256, 0, 256, 92);
|
||
|
|
c.fillStyle = 'rgba(0,0,0,.25)'; c.fillRect(256, 90, 256, 6);
|
||
|
|
rivets(32, 'rgba(0,0,0,.45)'); scratches(90, 0.1);
|
||
|
|
break;
|
||
|
|
case 'scratches':
|
||
|
|
scratches(260, 0.16); rivets(36, 'rgba(0,0,0,.5)');
|
||
|
|
break;
|
||
|
|
case 'dark': // dark hex plates with faint green seams
|
||
|
|
halves(() => {
|
||
|
|
c.strokeStyle = 'rgba(80,255,128,.18)'; c.lineWidth = 2;
|
||
|
|
for (let y = 0; y < 280; y += 36) for (let x = (y / 36) % 2 ? 0 : 21; x < 280; x += 42) {
|
||
|
|
c.beginPath(); for (let k = 0; k < 6; k++) { const a = k * Math.PI / 3; c.lineTo(x + Math.cos(a) * 20, y + Math.sin(a) * 20); } c.closePath(); c.stroke();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
scratches(70, 0.1);
|
||
|
|
break;
|
||
|
|
case 'redstripe': // racing stripe along the top, red band on the sides
|
||
|
|
c.fillStyle = css(look.accent2); c.fillRect(0, 100, 256, 56);
|
||
|
|
c.fillStyle = 'rgba(255,255,255,.8)'; c.fillRect(0, 96, 256, 4); c.fillRect(0, 156, 256, 4);
|
||
|
|
c.fillStyle = css(look.accent2); c.fillRect(256, 120, 256, 36);
|
||
|
|
scratches(110, 0.12);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
cache[id] = cv;
|
||
|
|
return cv;
|
||
|
|
};
|
||
|
|
})(window);
|