this.baseFrame = Math.random() * 4;
...
const frame = (gameState.currentTime * 8 + this.baseFrame) & 3;
const i = this.scoreReward ?
(1 - Math.min(1, gameState.currentTime - this.creationTime)) ** 2
: 0;
const s = 16 + gameState.size * i;
ctx.globalAlpha = 1 - i;
ctx.drawImage(
gameState.sprites,
this.sprite * 16, frame * 16, 16, 16,
Math.round(this.x - s / 2), Math.round(this.y - s / 2), s, s
);