Dead snakes are gray

This commit is contained in:
Klemek
2019-01-07 15:17:23 +01:00
parent 5016f1191c
commit 7b55763b89
+4 -5
View File
@@ -20,8 +20,9 @@ function ellipse(cx, cy, rx, ry) {
} }
function drawPlayer(ratio, p) { function drawPlayer(ratio, p) {
ctx.fillStyle = p.color; ctx.fillStyle = p.alive ? p.color : '#757575';
ctx.fillText(p.name, p.pos.x, p.pos.y - ratio * 10); ctx.fillText(p.name, p.pos.x, p.pos.y - ratio * 10);
if (p.alive) {
ellipse(p.pos.x, p.pos.y, ratio * 3, ratio * 3); ellipse(p.pos.x, p.pos.y, ratio * 3, ratio * 3);
if (p.starting > 0) if (p.starting > 0)
return; return;
@@ -35,10 +36,9 @@ function drawPlayer(ratio, p) {
history[p.name].list[history[p.name].i0] = p.pos; history[p.name].list[history[p.name].i0] = p.pos;
} }
function drawHistory(p) {
if (history[p.name]) { if (history[p.name]) {
const h = history[p.name]; const h = history[p.name];
ctx.strokeStyle = p.color; ctx.strokeStyle = p.alive ? p.color : '#757575';
ctx.beginPath(); ctx.beginPath();
if(!h.list[h.i0]) if(!h.list[h.i0])
return; return;
@@ -63,6 +63,7 @@ function drawHistory(p) {
} }
ctx.stroke(); ctx.stroke();
} }
} }
function drawGame() { function drawGame() {
@@ -86,11 +87,9 @@ function drawGame() {
const names = Object.keys(players); const names = Object.keys(players);
names.forEach(function (name) { names.forEach(function (name) {
const p = players[name]; const p = players[name];
if(p.alive)
drawPlayer(ratio, players[name]); drawPlayer(ratio, players[name]);
if (name === current.name) if (name === current.name)
current = players[name]; current = players[name];
drawHistory(players[name]);
}); });
requestAnimationFrame(drawGame); requestAnimationFrame(drawGame);