1
0
Fork 0

Custom apple sprite

This commit is contained in:
Ethanell 2021-03-27 11:00:39 +01:00
parent 120e58e88e
commit 4af6a0602f

View file

@ -48,8 +48,53 @@ export class Tile {
this.game.ctx.rect(...canvasPos, ...size); this.game.ctx.rect(...canvasPos, ...size);
break; break;
case tiles.APPLE: case tiles.APPLE:
this.game.ctx.fillStyle = "#ff0000"; let pxsize = Math.round(size[0]/12);
this.game.ctx.fillRect(...canvasPos, ...size); if (!pxsize) {
this.game.ctx.fillStyle = "#ff0000";
this.game.ctx.fillRect(...canvasPos, ...size);
} else {
let width = canvasPos[0];
let height = canvasPos[1];
this.game.ctx.fillStyle = "#00ffff";
this.game.ctx.fillRect(width+pxsize, height+pxsize, 10*pxsize, 10*pxsize);
this.game.ctx.fillStyle = "#000000";
this.game.ctx.fillRect(width+4*pxsize, height, pxsize*4, pxsize);
this.game.ctx.fillRect(width+4*pxsize, height+11*pxsize, pxsize*4, pxsize);
for (const i of [2,5,8])
this.game.ctx.fillRect(width+i*pxsize, height+pxsize, pxsize*2, pxsize);
for (const i of [1,4,7,10])
this.game.ctx.fillRect(width+i*pxsize, height+2*pxsize, pxsize, pxsize*2);
this.game.ctx.fillRect(width, height+4*pxsize, pxsize, pxsize*4);
this.game.ctx.fillRect(width+11*pxsize, height+4*pxsize, pxsize, pxsize*4);
for (const i of [1,5,6,10])
this.game.ctx.fillRect(width+i*pxsize, height+8*pxsize, pxsize, pxsize*2);
for (const i of [2,5,8])
this.game.ctx.fillRect(width+i*pxsize, height+10*pxsize, pxsize*2, pxsize);
for (const i of [3,8,2,9])
this.game.ctx.fillRect(width+i*pxsize, height+4*pxsize, pxsize, pxsize);
for (const i of [1,3,8,10])
this.game.ctx.fillRect(width+i*pxsize, height+6*pxsize, pxsize, pxsize);
for (const i of [4,7])
this.game.ctx.fillRect(width+i*pxsize, height+7*pxsize, pxsize, pxsize);
this.game.ctx.globalCompositeOperation = "destination-out";
this.game.ctx.fillRect(width+1*pxsize, height+1*pxsize, pxsize, pxsize);
this.game.ctx.fillRect(width+10*pxsize, height+1*pxsize, pxsize, pxsize);
this.game.ctx.fillRect(width+1*pxsize, height+10*pxsize, pxsize, pxsize);
this.game.ctx.fillRect(width+10*pxsize, height+10*pxsize, pxsize, pxsize);
this.game.ctx.globalCompositeOperation = "source-over";
}
break; break;
case tiles.SNAKE: case tiles.SNAKE:
this.game.ctx.fillStyle = "#00ff5f"; this.game.ctx.fillStyle = "#00ff5f";