aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-03-06 21:27:20 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-03-06 21:27:20 +0100
commitfb3f09ad7691765a7f578309a80c4a0cf4012236 (patch)
tree7aec78921117eadaf98c9000a59f9bf122e850e3
parentbc99212539f6da721ab50f4cd5e3ab0b4e76827e (diff)
downloadjetpac.nes-fb3f09ad7691765a7f578309a80c4a0cf4012236.tar.gz
jetpac.nes-fb3f09ad7691765a7f578309a80c4a0cf4012236.zip
Check for enemy death after its movement
Some enemies might die right after moving (e.g. asteroids exploding into the ground). In these cases, there's no point on checking for player collision. Moreover, this also avoids the corner case of having two explosions on a single death. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--.nasm/segments.txt2
-rw-r--r--src/enemies.s9
2 files changed, 10 insertions, 1 deletions
diff --git a/.nasm/segments.txt b/.nasm/segments.txt
index 96d2f66..5907869 100644
--- a/.nasm/segments.txt
+++ b/.nasm/segments.txt
@@ -1,4 +1,4 @@
- HEADER: 16/16 (100%)
-- ROM0: 6555/32762 (20.01%)
+- ROM0: 6561/32762 (20.03%)
- ROMV: 6/6 (100%)
- ROM2: 8192/8192 (100%)
diff --git a/src/enemies.s b/src/enemies.s
index 64e4b23..000b50d 100644
--- a/src/enemies.s
+++ b/src/enemies.s
@@ -386,6 +386,15 @@
;; Restore the value from the 'x' register.
ldx Enemies::zp_pool_index
+ ;; The enemy might have been burst to dust due to ground
+ ;; collision. Let's check it here and skip player collision if that's
+ ;; the case. This is not just an optimization detail, but otherwise we
+ ;; might get two explosions on the corner case of an enemy exploding due
+ ;; to background collision and colliding with the player at the same.
+ lda Enemies::zp_enemies_pool_base, x
+ cmp #$FF
+ beq @increase_index_next
+
;; Save the current tile coordinates for this enemy.
lda Enemies::zp_enemies_pool_base + 1, x
lsr