Stop bullets when they hit a wall
This commit is contained in:
@@ -251,14 +251,16 @@
|
|||||||
|
|
||||||
function updateBullets(elapsed) {
|
function updateBullets(elapsed) {
|
||||||
const deleteCount = 1;
|
const deleteCount = 1;
|
||||||
|
const pt = document.querySelector('svg').createSVGPoint();
|
||||||
|
|
||||||
bullets.forEach((bullet, index) => {
|
[...bullets].forEach((bullet, index) => {
|
||||||
bullet.time -= elapsed;
|
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) {
|
if (bullet.time > 0 && !wall.isPointInFill(pt)) {
|
||||||
let y = bullet.y + 0.001 * elapsed * bullet.vy;
|
|
||||||
let x = bullet.x + 0.001 * elapsed * bullet.vx;
|
|
||||||
|
|
||||||
[bullet.x, bullet.y] = wrapPos(x, y);
|
[bullet.x, bullet.y] = wrapPos(x, y);
|
||||||
bullet.node.style.transform = `translate(${bullet.x}px, ${bullet.y}px)`;
|
bullet.node.style.transform = `translate(${bullet.x}px, ${bullet.y}px)`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user