Stop bullets when they hit a wall

This commit is contained in:
2025-12-19 13:20:49 -08:00
parent 5a5b4e9272
commit 7b63f0524c

View File

@@ -251,14 +251,16 @@
function updateBullets(elapsed) {
const deleteCount = 1;
const pt = document.querySelector('svg').createSVGPoint();
bullets.forEach((bullet, index) => {
[...bullets].forEach((bullet, index) => {
bullet.time -= elapsed;
const x = bullet.x + 0.001 * elapsed * bullet.vx;
const y = bullet.y + 0.001 * elapsed * bullet.vy;
pt.x = x;
pt.y = y;
if (bullet.time > 0) {
let y = bullet.y + 0.001 * elapsed * bullet.vy;
let x = bullet.x + 0.001 * elapsed * bullet.vx;
if (bullet.time > 0 && !wall.isPointInFill(pt)) {
[bullet.x, bullet.y] = wrapPos(x, y);
bullet.node.style.transform = `translate(${bullet.x}px, ${bullet.y}px)`;
} else {

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB