+
0 fps
@@ -137,13 +144,25 @@
const radians = degrees * Math.PI / 180;
const vx = -Math.sin(radians);
const vy = Math.cos(radians);
+ const bulletTimeout = 5000; // miliseconds
+ const cannonLength = 8;
const el = document.createElementNS(namespaceURIsvg, 'circle');
+ el.classList.add('bullet');
el.setAttribute('r', 1);
el.setAttribute('cx', 0);
el.setAttribute('cy', 0);
const node = bulletsContainer.appendChild(el);
- const bullet = { x: x, y: y, vx: vx, vy: vy, time: 5000, node: node }
+
+ const bullet = {
+ x: x + vx * cannonLength,
+ y: y + vy * cannonLength,
+ vx: vx,
+ vy: vy,
+ time: bulletTimeout,
+ node: node
+ }
+
bullets.push(bullet);
}
@@ -208,6 +227,7 @@
const changeY = 0.001 * elapsed * velocityY;
bullets.forEach((bullet, index) => {
+ const deleteCount = 1;
bullets[index].time -= elapsed;
if (bullets[index].time > 0) {
@@ -220,7 +240,7 @@
bullet.node.style.transform = `translate(${bx}px, ${by}px)`;
} else {
bullet.node.remove();
- bullets.splice(index, 1);
+ bullets.splice(index, deleteCount);
}
});
@@ -293,7 +313,7 @@
fireButton.addEventListener("click", function (e) {
const [x, y] = getTranslate(hitbox);
- fireBullet(+x, +y);
+ fireBullet(x, y);
});