Loop through shots array to find an empty spot.

This commit is contained in:
Colin McMillen 2015-05-31 11:31:18 -04:00
parent 7d0140d233
commit e39f802bd5

View File

@ -14,8 +14,7 @@
; [gap] ; [gap]
; 0020-0021: (x, y) coordinates of player. ; 0020-0021: (x, y) coordinates of player.
; 0022: shot cooldown timer. ; 0022: shot cooldown timer.
; 0023-0024: index of next shot. ; 0023: next-shot state.
; 0025: next-shot state.
; [gap] ; [gap]
; 0030-008F: {sprite, x, y, x-velocity, y-velocity, unused} per shot. ; 0030-008F: {sprite, x, y, x-velocity, y-velocity, unused} per shot.
; If sprite is 0, the shot is disabled. ; If sprite is 0, the shot is disabled.
@ -33,8 +32,7 @@
.define playerX $20 .define playerX $20
.define playerY $21 .define playerY $21
.define shotCooldown $22 .define shotCooldown $22
.define nextShotPtr $23 .define nextShotState $23
.define nextShotState $25
.define shotArray $30 .define shotArray $30
.define shotArrayLength 16 .define shotArrayLength 16
.define shotSize 6 .define shotSize 6
@ -306,9 +304,6 @@ InitializeWorld:
lda #((224 - 32) / 2) lda #((224 - 32) / 2)
sta playerY sta playerY
; Next shot pointer starts at the beginning.
ldx #shotArray
stx nextShotPtr
rts rts
@ -455,9 +450,21 @@ MaybeShoot:
lda shotCooldown lda shotCooldown
cmp #0 cmp #0
bne MaybeShootDone bne MaybeShootDone
ldx nextShotPtr ; Find the first empty spot in the shots array.
ldx #shotArray
-
lda 0, X
cmp #0
beq +
.rept shotSize
inx
.endr
; If we went all the way to the end, bail out.
cpx #(shotArray + shotArrayLength * shotSize)
beq MaybeShootDone
jmp -
+
; Enable shot; set its position to player position. ; Enable shot; set its position to player position.
; TODO(mcmillen): loop through the array until we find an unused shot.
; TODO(mcmillen): it might be easier/faster to keep N arrays: one for each ; TODO(mcmillen): it might be easier/faster to keep N arrays: one for each
; field of shot (shotSpriteArray, shotXArray, shotYArray, ...) ; field of shot (shotSpriteArray, shotXArray, shotYArray, ...)
lda #8 ; Sprite number. lda #8 ; Sprite number.
@ -466,28 +473,20 @@ MaybeShoot:
sta 1, X sta 1, X
lda playerY lda playerY
sta 2, X sta 2, X
lda #6 ; x-velocity. lda #3 ; x-velocity.
sta 3, X sta 3, X
lda nextShotState lda nextShotState
cmp #1 cmp #1
beq + beq +
lda #3 lda #1
sta 4, X sta 4, X
inc nextShotState inc nextShotState
jmp ++ jmp ++
+ +
lda #-3 lda #-1
sta 4, X sta 4, X
dec nextShotState dec nextShotState
++ ++
.rept shotSize
inx
.endr
cpx #(shotArray + shotArrayLength * shotSize)
bne +
ldx #shotArray
+
stx nextShotPtr
; Set cooldown timer. ; Set cooldown timer.
lda #10 lda #10