aboutsummaryrefslogtreecommitdiff
path: root/src/driver.s
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-03-11 23:44:13 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-03-11 23:44:13 +0100
commit9ae51a4c210b8f01718e21eda592c498715a642b (patch)
tree90867f95c133b8c4383a9559075b73b77b92c98b /src/driver.s
parenta0ef7b9c4d341de3f3f518626c40576e45cbf244 (diff)
downloadjetpac.nes-9ae51a4c210b8f01718e21eda592c498715a642b.tar.gz
jetpac.nes-9ae51a4c210b8f01718e21eda592c498715a642b.zip
Initial implementation for items
This now only supports the appearance of shuttle parts and the fact that the player can collect them at a very specific order and drop them so to stack up the final shuttle. This is of course just the skeleton and there's a bunch of TODO's left. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'src/driver.s')
-rw-r--r--src/driver.s42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/driver.s b/src/driver.s
index 7404b94..8b366b7 100644
--- a/src/driver.s
+++ b/src/driver.s
@@ -126,6 +126,9 @@
ora #%00001000
sta Player::zp_state
+ ;; Prepare the items for the scene.
+ jsr Items::prepare_scene
+
;; Mark the state of the game as "game". That is, the player has
;; started. Also set the `ppu` flag and unset the `title over` one.
lda #%01000001
@@ -159,6 +162,15 @@
dey
bne @bullets_reset_loop
+ ;; Invalidate all items.
+ ldx #0
+ ldy #Items::POOL_CAPACITY
+ @items_reset_loop:
+ sta Items::zp_pool_base, x
+ NEXT_ITEM_INDEX_X
+ dey
+ bne @items_reset_loop
+
;; Set that we have done this operation so it's not done in future
;; cycles.
lda #1
@@ -208,6 +220,7 @@
jsr Bullets::init
jsr Enemies::init
jsr Explosions::init
+ jsr Items::init
;; Initialize pause timer and some boolean values.
lda #0
@@ -286,6 +299,7 @@
jsr Enemies::update
@do_minimal_update:
jsr Explosions::update
+ jsr Items::update
;; Has the player died? If it is dead, then we need to remove all
;; sprites except for objects and explosions, and whenever
@@ -414,11 +428,24 @@
@set_next_enemies_cycle:
stx zp_next_enemy_cycle
- ;; TODO: ensure 1 item
- ;; iny
- ;; iny
- ;; iny
- ;; iny
+ ;; Allocate all valid items. Items, contrary to other sprites, don't get
+ ;; the special "you get a fixed first position" like others, mainly
+ ;; because there are so few of them on screen at any given time. For
+ ;; this reason as well, it's ok to just dump them all here before the
+ ;; rest of sprites are churned in.
+ ldx #0
+ @rest_o_items:
+ cpx #Items::POOL_CAPACITY_BYTES
+ beq @rest_o_bullets
+
+ lda Items::zp_pool_base, x
+ cmp #$FF
+ beq @next_item
+ jsr Items::allocate_x_y
+
+ @next_item:
+ NEXT_ITEM_INDEX_X
+ jmp @rest_o_items
;; Allocate the rest of valid bullets from the pool.
ldx #0
@@ -483,7 +510,7 @@
;; enemies, then jump to items. If the current indexed enemy is the one
;; we allocated as the first fixed one, then skip it.
cpx #Enemies::ENEMIES_POOL_CAPACITY_BYTES
- beq @rest_o_items
+ beq @do_explosions
cpx zp_first_enemy
beq @next_enemy
@@ -506,9 +533,6 @@
NEXT_ENEMY_INDEX_X
jmp @rest_o_enemies_loop
- @rest_o_items:
- ;;; TODO
-
;; At the very end, we allocate any active explosion.
@do_explosions:
ldx #0