Skip to content

Commit bddb285

Browse files
Copilotjbampton
andauthored
Space Invaders: reclaim off-screen bullets, enforce black playfield, preserve ESC exit (#441)
* 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> * Space Invaders: extract bullet cleanup buffer constant 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> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jbampton <418747+jbampton@users.noreply.github.com> Co-authored-by: John Bampton <jbampton@users.noreply.github.com>
1 parent bf607c7 commit bddb285

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const SpaceInvaders = (() => {
1212
const ALIEN_ROWS = ["👾", "👽", "🛸", "🐙", "👾"];
1313
const GAME_ID = "space-invaders";
14+
const BULLET_CLEANUP_BUFFER = 40;
1415

1516
// ─── Public entry-point ──────────────────────────────────────────────────
1617

@@ -36,6 +37,7 @@ const SpaceInvaders = (() => {
3637
height: "100vh",
3738
zIndex: "10000",
3839
pointerEvents: "auto",
40+
background: "#000000",
3941
});
4042
document.body.appendChild(canvas);
4143

@@ -44,7 +46,8 @@ const SpaceInvaders = (() => {
4446
canvas: canvas,
4547
width: window.innerWidth,
4648
height: window.innerHeight,
47-
transparent: true,
49+
transparent: false,
50+
backgroundColor: "#000000",
4851
physics: {
4952
default: "arcade",
5053
arcade: { gravity: { y: 0 }, debug: false },
@@ -79,6 +82,18 @@ const SpaceInvaders = (() => {
7982
if (this.si_cursors.space.isDown) {
8083
_fireBullet(this);
8184
}
85+
86+
const bullets = this.si_bullets?.getChildren?.() || [];
87+
bullets.forEach((bullet) => {
88+
if (!bullet.active) return;
89+
if (
90+
bullet.y < -BULLET_CLEANUP_BUFFER ||
91+
bullet.x < -BULLET_CLEANUP_BUFFER ||
92+
bullet.x > this.scale.width + BULLET_CLEANUP_BUFFER
93+
) {
94+
bullet.destroy();
95+
}
96+
});
8297
}
8398

8499
// ─── Game setup ──────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)