Open
Description
- Use
const
instead oflet
here https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L20 - Put all tanks to collection https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L31-L35
- Use collection instead of if-else sequence https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L143-L156
- Add eslint
arrow-parens
rule: https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L160 - Change https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L171-L173 to
setInterval(func, fps);
and changeSetInit
to lowerCamepCase - Check: maybe it would be better to call
turn
andcollision
from that place where you callTurnToCollision
https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L183-L190 - Try to use collection instead https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L196-L207
- Try to optimize this function (need more experiments): https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L223-L238
function run() {
if (!player.run) return;
const { side, x, y, speed, width, height } = player;
const rect = gamezone.getBoundingClientRect();
if (side === 'top' && y > 0) player.y -= speed;
else if (side === 'right' && x < rect.width - width) player.x += speed;
else if (side === 'bottom' && y < rect.height - height) player.y += speed;
else if (side === 'left' && x > 0) player.x -= speed;
player.el.style.top = `${y}px`;
player.el.style.left = `${x}px`;
}
- Use for..of instead: https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L251
- Try to optimize: https://github.com/Dimdim28/Webgames/blob/62a35dbdfc7b5fa68173ea7f68f36baabc20ebfb/tanks.js#L256-L259
const sign = (direction === 'top' || direction === 'left') ? 1 : -1;
moveBull(tank, direction, bullet, sign);
Metadata
Metadata
Assignees
Labels
No labels