Stop bullets when they hit a wall
This commit is contained in:
@@ -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 |
Reference in New Issue
Block a user