aboutsummaryrefslogtreecommitdiff
path: root/src/enemies.s
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 /src/enemies.s
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>
Diffstat (limited to 'src/enemies.s')
-rw-r--r--src/enemies.s9
1 files changed, 9 insertions, 0 deletions
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