Skip to content

Commit c99ea46

Browse files
Copilotjbampton
andauthored
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>
1 parent c292564 commit c99ea46

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 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

@@ -85,7 +86,11 @@ const SpaceInvaders = (() => {
8586
const bullets = this.si_bullets?.getChildren?.() || [];
8687
bullets.forEach((bullet) => {
8788
if (!bullet.active) return;
88-
if (bullet.y < -40 || bullet.x < -40 || bullet.x > this.scale.width + 40) {
89+
if (
90+
bullet.y < -BULLET_CLEANUP_BUFFER ||
91+
bullet.x < -BULLET_CLEANUP_BUFFER ||
92+
bullet.x > this.scale.width + BULLET_CLEANUP_BUFFER
93+
) {
8994
bullet.destroy();
9095
}
9196
});

0 commit comments

Comments
 (0)