aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-03-02 23:18:55 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-03-02 23:18:55 +0100
commit2f85b4c7820d919497878d54dea530fe73a486c9 (patch)
treea7e06700a1bcdf7b4ab11282980f86966a718e93
parentb7c41567892a7b3bd3782128926c6a223658a034 (diff)
downloadjetpac.nes-2f85b4c7820d919497878d54dea530fe73a486c9.tar.gz
jetpac.nes-2f85b4c7820d919497878d54dea530fe73a486c9.zip
Move enemy initialization into its own function
This will be useful whenever we implement the re-appearance of enemies. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--.nasm/segments.txt2
-rw-r--r--src/enemies.s19
2 files changed, 17 insertions, 4 deletions
diff --git a/.nasm/segments.txt b/.nasm/segments.txt
index 3c85c8f..5b1f542 100644
--- a/.nasm/segments.txt
+++ b/.nasm/segments.txt
@@ -1,4 +1,4 @@
- HEADER: 16/16 (100%)
-- ROM0: 5467/32762 (16.69%)
+- ROM0: 5471/32762 (16.70%)
- ROMV: 6/6 (100%)
- ROM2: 8192/8192 (100%)
diff --git a/src/enemies.s b/src/enemies.s
index 7aa8df1..53f6685 100644
--- a/src/enemies.s
+++ b/src/enemies.s
@@ -116,6 +116,21 @@
sty zp_enemies_pool_size
@enemies_init_loop:
+ jsr init_enemy_x
+
+ ;; Next enemy!
+ dey
+ bne @enemies_init_loop
+
+ rts
+ .endproc
+
+ ;; Initialize the enemy from the pool as indexed by the 'x' register.
+ ;;
+ ;; NOTE: the 'x' register will be advanced by the amount of bytes it takes
+ ;; to store an enemy on the poll (i.e. 4 bytes).
+ ;; NOTE: the 'y' register is not touched.
+ .proc init_enemy_x
;; The state is set at random.
stx Globals::zp_tmp0
jsr Prng::random_valid_y_coordinate
@@ -148,10 +163,8 @@
inx
sta zp_enemies_pool_base, x
- ;; Next enemy!
+ ;; And point to the next enemy.
inx
- dey
- bne @enemies_init_loop
rts
.endproc