Skip to content

Commit c292564

Browse files
Copilotjbampton
andauthored
Space Invaders: cleanup offscreen bullets and black canvas background
Agent-Logs-Url: https://github.com/NextCommunity/NextCommunity.github.io/sessions/4a92f727-d408-427a-8bee-fc96696e3d01 Co-authored-by: jbampton <418747+jbampton@users.noreply.github.com>
1 parent a8d7d51 commit c292564

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/assets/js/games/space-invaders.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const SpaceInvaders = (() => {
3636
height: "100vh",
3737
zIndex: "10000",
3838
pointerEvents: "auto",
39+
background: "#000000",
3940
});
4041
document.body.appendChild(canvas);
4142

@@ -44,7 +45,8 @@ const SpaceInvaders = (() => {
4445
canvas: canvas,
4546
width: window.innerWidth,
4647
height: window.innerHeight,
47-
transparent: true,
48+
transparent: false,
49+
backgroundColor: "#000000",
4850
physics: {
4951
default: "arcade",
5052
arcade: { gravity: { y: 0 }, debug: false },
@@ -79,6 +81,14 @@ const SpaceInvaders = (() => {
7981
if (this.si_cursors.space.isDown) {
8082
_fireBullet(this);
8183
}
84+
85+
const bullets = this.si_bullets?.getChildren?.() || [];
86+
bullets.forEach((bullet) => {
87+
if (!bullet.active) return;
88+
if (bullet.y < -40 || bullet.x < -40 || bullet.x > this.scale.width + 40) {
89+
bullet.destroy();
90+
}
91+
});
8292
}
8393

8494
// ─── Game setup ──────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)