diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-01 23:02:39 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-01 23:02:39 +0100 |
| commit | c9e7a7ab06732f5e9fb0cde1cd01f46d059b0259 (patch) | |
| tree | e9d35f2620f651d850eb4b651e86cae77800ec05 | |
| parent | 2170ffa5346667c0f20b388d58a30d204c7bce47 (diff) | |
| download | jetpac.nes-c9e7a7ab06732f5e9fb0cde1cd01f46d059b0259.tar.gz jetpac.nes-c9e7a7ab06732f5e9fb0cde1cd01f46d059b0259.zip | |
Finish up the 'homing' algorithm
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | .nasm/segments.txt | 2 | ||||
| -rw-r--r-- | src/enemies.s | 36 |
2 files changed, 22 insertions, 16 deletions
diff --git a/.nasm/segments.txt b/.nasm/segments.txt index c89718c..03c9b6c 100644 --- a/.nasm/segments.txt +++ b/.nasm/segments.txt @@ -1,4 +1,4 @@ - HEADER: 16/16 (100%) -- ROM0: 5245/32762 (16.01%) +- ROM0: 5254/32762 (16.04%) - ROMV: 6/6 (100%) - ROM2: 8192/8192 (100%) diff --git a/src/enemies.s b/src/enemies.s index 25f041b..f69e9fd 100644 --- a/src/enemies.s +++ b/src/enemies.s @@ -957,22 +957,28 @@ ;; We are done going up and down. Now it's time to change the state of ;; this enemy, and home towards the player depending on its position. @start_homing: - ;; Ensure the 'state' bit is set. - tya - ora #$02 - sta Enemies::zp_enemies_pool_base + 3, x - - lda Enemies::zp_enemies_pool_base + 1, x - cmp Player::zp_screen_y - bcc @home_down - ;; TODO: up - nop - @home_down: - ;; TODO: subtract the same portion over and over. If overflow is set, then - ;; we know we are passed it. - ;; TODO: down + ;; Out of simplicity, the movement kind is picked at random. Hence, + ;; initialize the 'a' register with a random number. + stx Globals::zp_tmp0 + jsr Prng::random_valid_y_coordinate + ldx Globals::zp_tmp0 - @end: + ;; Ensure the 'state' bit is set whenever we enter back at the 'homing' + ;; function, so we can jump right into 'basic'. The 'downwards' bit is + ;; set in the next step, so zero it out for now. And set the timer to + ;; '1'. + ora #$12 + and #%00011110 + + ;; Compare the current Y position to that of the player. Then set the + ;; 'downwards' bit if it needs to go down. + ldy Enemies::zp_enemies_pool_base + 1, x + cpy Player::zp_screen_y + bcs @set_homing_to_basic + ora #$01 + + @set_homing_to_basic: + sta Enemies::zp_enemies_pool_base + 3, x rts .endproc |
