aboutsummaryrefslogtreecommitdiff
path: root/src/enemies.s
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-02-28 00:26:07 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-02-28 00:26:07 +0100
commitc87cad0b873c2f1c45c420dd96f828f35de6a4ba (patch)
treeedc2a1b94be38b5f0c1be3a09f39c4a92f3e6972 /src/enemies.s
parent90c2a76952e2f2bb30f41e5218e2f5e02d78b8d2 (diff)
downloadjetpac.nes-c87cad0b873c2f1c45c420dd96f828f35de6a4ba.tar.gz
jetpac.nes-c87cad0b873c2f1c45c420dd96f828f35de6a4ba.zip
Move the 'extra' initialization to a function
This allows us to be able to initialize each enemy separately, giving a more random appearance to it all. This will also come in handy whenever we want to make enemies re-appear. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src/enemies.s')
-rw-r--r--src/enemies.s104
1 files changed, 53 insertions, 51 deletions
diff --git a/src/enemies.s b/src/enemies.s
index 23ae18f..c93f1c2 100644
--- a/src/enemies.s
+++ b/src/enemies.s
@@ -92,58 +92,15 @@
lda movement_hi, x
sta zp_enemy_movement_fn + 1
- ;; TODO: rest of the enemies.
- ;; TODO: there are ways to optimize this
+ ;; Initialize the enemy arg, which is always 1 except for homing
+ ;; attacks.
+ ldy #1
txa
- beq @init_basic
- cmp #1
- beq @init_bounce_1
- cmp #2
- beq @init_erratic
cmp #3
- beq @init_homing
- cmp #5
- beq @init_bounce_2
- cmp #6
- __fallthrough__ @init_basic
-
- @init_basic:
- lda #1
- sta Enemies::zp_enemy_arg
- jsr Prng::random_valid_y_coordinate
- and #$0F
- ora #$11
- bne @set
- @init_erratic:
- lda #1
- sta Enemies::zp_enemy_arg
- jsr Prng::random_valid_y_coordinate
- and #$01
- jmp @set
- @init_homing:
- lda #1
- sta Enemies::zp_enemy_arg
- jsr Prng::random_valid_y_coordinate
- and #$01
- ora #$10
- jmp @set
- @init_bounce_1:
- lda #1
- sta Enemies::zp_enemy_arg
- jsr Prng::random_valid_y_coordinate
- and #$01
- jmp @set
- @init_bounce_2:
- lda #2
- sta Enemies::zp_enemy_arg
- jsr Prng::random_valid_y_coordinate
- and #$01
- __fallthrough__ @set
-
- @set:
- ;; The 'init_pool' wants an argument which is the 'extra' state to be
- ;; set up for all enemies of the pool.
- sta Globals::zp_arg0
+ bne @set_enemy_arg
+ iny
+ @set_enemy_arg:
+ sty Enemies::zp_enemy_arg
__fallthrough__ init_pool
.endproc
@@ -185,8 +142,10 @@
sta zp_enemies_pool_base, x
;; And set the 'extra' state as passed down by the 'init' function.
+ stx Globals::zp_tmp0
+ jsr generate_extra
+ ldx Globals::zp_tmp0
inx
- lda Globals::zp_arg0
sta zp_enemies_pool_base, x
;; Next enemy!
@@ -197,6 +156,49 @@
rts
.endproc
+ ;; Generate a value for the 'extra' value depending on the current level
+ ;; kind. The result is left in 'a'.
+ ;;
+ ;; NOTE: the 'x' register is touched, while the 'y' register is not.
+ .proc generate_extra
+ ;; TODO: rest of the enemies.
+ lda Globals::zp_level_kind
+ beq @init_basic
+ cmp #1
+ beq @init_bounce_1
+ cmp #2
+ beq @init_erratic
+ cmp #3
+ beq @init_homing
+ cmp #5
+ beq @init_bounce_2
+ cmp #6
+ __fallthrough__ @init_basic
+
+ @init_basic:
+ jsr Prng::random_valid_y_coordinate
+ and #$0F
+ ora #$11
+ rts
+ @init_erratic:
+ jsr Prng::random_valid_y_coordinate
+ and #$01
+ rts
+ @init_homing:
+ jsr Prng::random_valid_y_coordinate
+ and #$01
+ ora #$10
+ rts
+ @init_bounce_1:
+ jsr Prng::random_valid_y_coordinate
+ and #$01
+ rts
+ @init_bounce_2:
+ jsr Prng::random_valid_y_coordinate
+ and #$01
+ rts
+ .endproc
+
;; Update the state and movement of all active enemies.
;;
;; NOTE: this function does not do collision checking with bullets as