diff --git a/html/images/space.svg b/html/images/space.svg
index 1efb736..bf12694 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -184,24 +184,22 @@
}
function updateBullets(elapsed) {
+ const deleteCount = 1;
+
bullets.forEach((bullet, index) => {
- const deleteCount = 1;
- bullets[index].time -= elapsed;
+ bullet.time -= elapsed;
- if (bullets[index].time > 0) {
- bullets[index].y += 0.001 * elapsed * bullets[index].vy;
- bullets[index].x += 0.001 * elapsed * bullets[index].vx;
+ if (bullet.time > 0) {
+ let y = bullet.y + 0.001 * elapsed * bullet.vy;
+ let x = bullet.x + 0.001 * elapsed * bullet.vx;
- let [bx, by] = wrapPos(bullets[index].x, bullets[index].y)
- bullets[index].x = bx;
- bullets[index].y = by;
- bullet.node.style.transform = `translate(${bx}px, ${by}px)`;
+ [bullet.x, bullet.y] = wrapPos(x, y);
+ bullet.node.style.transform = `translate(${bullet.x}px, ${bullet.y}px)`;
} else {
bullet.node.remove();
bullets.splice(index, deleteCount);
}
});
-
}
function updateLines([positionX, positionY]) {
@@ -219,7 +217,6 @@
line.setAttribute('y2', line.getAttribute('y1'));
}
});
-
}
requestAnimationFrame(firstFrame);
@@ -240,7 +237,7 @@
info.innerText = `velocity ${velocity}\n`
+ 'bullets\nx\ty\tvx\tvy\n'
- + bullets.map((b, index) => {
+ + bullets.map(b => {
return `${b.x.toFixed(2)}\t${b.y.toFixed(2)}\t${b.vx.toFixed(2)}\t${b.vy.toFixed(2)}`;
}).join("\n");