Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/assets/js/games/space-invaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const SpaceInvaders = (() => {
const ALIEN_ROWS = ["👾", "👽", "🛸", "🐙", "👾"];
const GAME_ID = "space-invaders";
const BULLET_CLEANUP_BUFFER = 40;

// ─── Public entry-point ──────────────────────────────────────────────────

Expand All @@ -36,6 +37,7 @@ const SpaceInvaders = (() => {
height: "100vh",
zIndex: "10000",
pointerEvents: "auto",
background: "#000000",
});
document.body.appendChild(canvas);

Expand All @@ -44,7 +46,8 @@ const SpaceInvaders = (() => {
canvas: canvas,
width: window.innerWidth,
height: window.innerHeight,
transparent: true,
transparent: false,
backgroundColor: "#000000",
physics: {
default: "arcade",
arcade: { gravity: { y: 0 }, debug: false },
Expand Down Expand Up @@ -79,6 +82,18 @@ const SpaceInvaders = (() => {
if (this.si_cursors.space.isDown) {
_fireBullet(this);
}

const bullets = this.si_bullets?.getChildren?.() || [];
bullets.forEach((bullet) => {
if (!bullet.active) return;
if (
bullet.y < -BULLET_CLEANUP_BUFFER ||
bullet.x < -BULLET_CLEANUP_BUFFER ||
bullet.x > this.scale.width + BULLET_CLEANUP_BUFFER
) {
bullet.destroy();
}
});
}

// ─── Game setup ──────────────────────────────────────────────────────────
Expand Down
Loading