Allow for multiple shots at once.

This commit is contained in:
Colin McMillen 2015-05-25 15:35:22 -04:00
parent 2bf56bb422
commit 292cb079a5

View File

@ -14,7 +14,9 @@
; [gap] ; [gap]
; 0020-0021: (x, y) coordinates of player. ; 0020-0021: (x, y) coordinates of player.
; 0022: shot cooldown timer. ; 0022: shot cooldown timer.
; 0030-0032: enable / x / y of shot. ; 0023-0024: index of next shot.
; [gap]
; 0030-003F: {enable, x, y, unused} per shot (max 4 shots).
; ;
; Sprite table buffers -- copied each frame to OAM during VBlank, using DMA. ; Sprite table buffers -- copied each frame to OAM during VBlank, using DMA.
; 0100-02FF: table 1 (4 bytes each: x/y coord, tile #, flip/priority/palette) ; 0100-02FF: table 1 (4 bytes each: x/y coord, tile #, flip/priority/palette)
@ -29,6 +31,7 @@
.define playerX $20 .define playerX $20
.define playerY $21 .define playerY $21
.define shotCooldown $22 .define shotCooldown $22
.define nextShotPtr $23
.define shotData $30 .define shotData $30
; TODO(mcmillen): verify that we can relocate these without messing things up. ; TODO(mcmillen): verify that we can relocate these without messing things up.
@ -139,7 +142,6 @@ LoadPaletteAndTileData:
; Now, BG3 palette data. ; Now, BG3 palette data.
; Palette entries for BG3 start at 0. ; Palette entries for BG3 start at 0.
; TODO(mcmillen): BG2 started at 32, but maybe that's only in mode 0?
ldx #0 ldx #0
lda #0 lda #0
sta CGADDR sta CGADDR
@ -256,10 +258,9 @@ InitializeSpriteTables:
lda #$01 lda #$01
- -
sta spriteTableStart, X sta spriteTableStart, X
.rept 4
inx inx
inx .endr
inx
inx
cpx #spriteTable1Size cpx #spriteTable1Size
bne - bne -
@ -290,6 +291,10 @@ InitializeWorld:
sta playerX sta playerX
lda #((224 - 32) / 2) lda #((224 - 32) / 2)
sta playerY sta playerY
; Next shot pointer starts at the beginning.
ldx #shotData
stx nextShotPtr
rts rts
@ -436,23 +441,37 @@ MaybeShoot:
; If the cooldown timer is non-zero, don't shoot. ; If the cooldown timer is non-zero, don't shoot.
lda shotCooldown lda shotCooldown
cmp #0 cmp #0
bne + bne ++
ldx nextShotPtr
stx $0060
; Enable shot; set its position to player position. ; Enable shot; set its position to player position.
lda #1 lda #1
sta shotData sta 0, X
lda playerX lda playerX
sta shotData + 1 sta 1, X
lda playerY lda playerY
sta shotData + 2 sta 2, X
; Update nextShotPtr.
.rept 4
inx
.endr
cpx #$0040 ; TODO(mcmillen): use a constant.
bne +
ldx #shotData
+
stx nextShotPtr
; Set cooldown timer. ; Set cooldown timer.
lda #16 lda #16
sta shotCooldown sta shotCooldown
+ ++
rts rts
UpdateWorld: UpdateWorld:
; TODO(mcmillen): separate out "update world" from "update sprite table".
; Update shot cooldown. ; Update shot cooldown.
lda shotCooldown lda shotCooldown
cmp #0 cmp #0
@ -478,51 +497,57 @@ UpdateWorld:
ora #%00000010 ; ... and make it the large size. (32x32) ora #%00000010 ; ... and make it the large size. (32x32)
sta spriteTable2Start sta spriteTable2Start
; Move shot coords. ; Move shot coords and copy into sprite table.
ldx $0 ldx #0
lda shotData ; To modify sprite table 2 - one bit set for each active shot.
; These bits will be *removed* from the sprite table entry.
stz $00
UpdateShot:
lsr $00
lsr $00
lda shotData, X
cmp #1 cmp #1
bne DisableShot bne DisableShot
; Add to the x-coordinate. If the carry bit is set, we went off the edge
; of the screen, so disable the shot.
lda shotData + 1, X
clc
adc #6 ; x velocity
bcs DisableShot
sta shotData + 1, X ; Store new x-coord.
lda shotData + 1 ; Set up shot in sprite table.
; TODO(mcmillen): do this with an add, then check the carry bit? lda shotData + 1, X ; x
.rept 6 ; TODO(mcmillen): document that shots start at $110?
ina sta $0110, X
cmp #$00 ; If it wraps around, disable it. lda shotData + 2, X ; y
bne + sta $0111, X
stz shotData lda #8 ; which sprite?
+ sta $0112, X
.endr
sta shotData + 1 ; Store new x-coord.
; See if sprite is still enabled after move. lda $00
lda shotData ora #%01000000
cmp #1 sta $00
bne DisableShot
; Set up shot sprite.
lda shotData + 1 ; x
sta $0104
lda shotData + 2 ; y
sta $0105
lda #8 ; which sprite
sta $0106
lda $0300
and #%11111011 ; Display it.
ora #%00001000 ; and set it to large size.
sta $0300
jmp ShotDone jmp ShotDone
DisableShot: DisableShot:
; Disable it by setting x-position to 1 and setting the high x-bit. ; Disable it by setting x-position to 1 and setting the high x-bit.
lda #1 lda #1
sta $104 sta $110, X
lda $0300
ora #%00000100
sta $0300
ShotDone: ShotDone:
; TODO(mcmillen): in places where we .rept inx (etc), is it faster to use
; actual addition?
.rept 4
inx
.endr
cpx #16
bne UpdateShot
; Set the enable/disable (and size) bits of the shot sprites.
lda #$ff
eor $00
sta $0301
; Make the background scroll. Horizontal over time; vertical depending on ; Make the background scroll. Horizontal over time; vertical depending on
; player's y-coordinate. ; player's y-coordinate.
lda vBlankCounter lda vBlankCounter