Add shots that come from enemy ships.
This commit is contained in:
parent
1a37dfe08b
commit
08fae310e8
95
pewpew.asm
95
pewpew.asm
@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; TODO(mcmillen): define screen / ship / shot dimensions as constants.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; Sets A to 8-bit (& enables 8-bit "B" register).
|
; Sets A to 8-bit (& enables 8-bit "B" register).
|
||||||
.MACRO SetA8Bit
|
.MACRO SetA8Bit
|
||||||
sep #%00100000 ; 8-bit A/B.
|
sep #%00100000 ; 8-bit A/B.
|
||||||
@ -471,10 +475,10 @@ MaybeShootDone:
|
|||||||
|
|
||||||
UpdateWorld:
|
UpdateWorld:
|
||||||
jsr UpdateShotCooldown
|
jsr UpdateShotCooldown
|
||||||
jsr SpawnEnemyShips
|
|
||||||
jsr SpawnEnemyShots
|
|
||||||
jsr UpdateEnemyShips
|
|
||||||
jsr UpdateShotPositions
|
jsr UpdateShotPositions
|
||||||
|
jsr SpawnEnemyShips
|
||||||
|
jsr UpdateEnemyShips
|
||||||
|
|
||||||
jsr CheckCollisionsWithPlayer
|
jsr CheckCollisionsWithPlayer
|
||||||
jsr UpdateBackgroundScroll
|
jsr UpdateBackgroundScroll
|
||||||
rts
|
rts
|
||||||
@ -529,7 +533,7 @@ SpawnEnemyShips:
|
|||||||
sta enemyShipArray + 3, Y ; move AI type.
|
sta enemyShipArray + 3, Y ; move AI type.
|
||||||
sta enemyShipArray + 4, Y ; shoot AI type.
|
sta enemyShipArray + 4, Y ; shoot AI type.
|
||||||
|
|
||||||
lda #8
|
lda #12
|
||||||
sta enemyShipArray + 5, Y ; shot cooldown.
|
sta enemyShipArray + 5, Y ; shot cooldown.
|
||||||
|
|
||||||
rts
|
rts
|
||||||
@ -539,14 +543,17 @@ SpawnEnemyShips:
|
|||||||
; TODO(mcmillen): reap ships if they move off the top, bottom, or right too.
|
; TODO(mcmillen): reap ships if they move off the top, bottom, or right too.
|
||||||
UpdateEnemyShips:
|
UpdateEnemyShips:
|
||||||
ldy #0
|
ldy #0
|
||||||
|
sty $00 ; Index into enemyShotArray.
|
||||||
--
|
--
|
||||||
lda enemyShipArray, Y
|
lda enemyShipArray, Y
|
||||||
cmp #0
|
cmp #0 ; If it's not enabled, skip it.
|
||||||
beq ++
|
beq ++
|
||||||
|
|
||||||
|
; Move the ship.
|
||||||
|
; TODO(mcmillen): implement different movement based on AI-type.
|
||||||
lda enemyShipArray + 1, Y ; x
|
lda enemyShipArray + 1, Y ; x
|
||||||
clc
|
clc
|
||||||
adc #-2
|
adc #-2 ; x-velocity.
|
||||||
bcs +
|
bcs +
|
||||||
lda #0
|
lda #0
|
||||||
sta enemyShipArray, Y ; reap it.
|
sta enemyShipArray, Y ; reap it.
|
||||||
@ -554,8 +561,26 @@ UpdateEnemyShips:
|
|||||||
+
|
+
|
||||||
sta enemyShipArray + 1, Y ; move it.
|
sta enemyShipArray + 1, Y ; move it.
|
||||||
|
|
||||||
|
lda enemyShipArray + 5, Y ; shot cooldown
|
||||||
|
cmp #0
|
||||||
|
beq +
|
||||||
|
dec A
|
||||||
|
sta enemyShipArray + 5, Y ; new shot cooldown
|
||||||
|
bra ++
|
||||||
|
|
||||||
++
|
+ ; Add a shot.
|
||||||
|
; TODO(mcmillen): implement different shooting based on shoot-type.
|
||||||
|
lda enemyShipArray + 1, Y
|
||||||
|
sta $02 ; Enemy ship X.
|
||||||
|
lda enemyShipArray + 2, Y
|
||||||
|
sta $03 ; Enemy ship Y.
|
||||||
|
lda #12
|
||||||
|
sta enemyShipArray + 5, Y ; new shot cooldown
|
||||||
|
phy
|
||||||
|
jsr SpawnEnemyShot
|
||||||
|
ply
|
||||||
|
|
||||||
|
++ ; Done processing this ship.
|
||||||
.rept enemyShipSize
|
.rept enemyShipSize
|
||||||
iny
|
iny
|
||||||
.endr
|
.endr
|
||||||
@ -566,48 +591,52 @@ UpdateEnemyShips:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
SpawnEnemyShots:
|
; Expects:
|
||||||
lda vBlankCounter
|
; $00: index into enemyShotArray (bytes).
|
||||||
bit #%00011111 ; Spawn shots every this-many frames.
|
; $02: enemy ship x-position.
|
||||||
beq +
|
; $03: enemy ship y-position.
|
||||||
|
;
|
||||||
|
; Modifies: A & Y.
|
||||||
|
; $00: new index into enemyShotArray (bytes).
|
||||||
|
SpawnEnemyShot:
|
||||||
|
ldy $00
|
||||||
|
-
|
||||||
|
; Bail if at end of array.
|
||||||
|
cpy #(enemyShotArrayLength * shotSize)
|
||||||
|
bne +
|
||||||
|
sty $00
|
||||||
rts
|
rts
|
||||||
+
|
+
|
||||||
; Find an empty spot in the array.
|
|
||||||
ldy #0
|
|
||||||
-
|
|
||||||
lda enemyShotArray, Y
|
lda enemyShotArray, Y
|
||||||
cmp #0
|
cmp #0
|
||||||
beq +
|
beq +
|
||||||
.rept 6
|
; Try next slot.
|
||||||
|
.rept shotSize
|
||||||
iny
|
iny
|
||||||
.endr
|
.endr
|
||||||
cpy #(enemyShotArrayLength * shotSize)
|
bra -
|
||||||
bne -
|
|
||||||
rts ; Too many shots; bail.
|
|
||||||
|
|
||||||
+
|
+
|
||||||
|
|
||||||
|
; OK, found a spot.
|
||||||
lda #9 ; Sprite number.
|
lda #9 ; Sprite number.
|
||||||
sta enemyShotArray, Y
|
sta enemyShotArray, Y
|
||||||
|
|
||||||
lda #254
|
lda $02 ; Get enemy x.
|
||||||
sta enemyShotArray + 1, Y ; x.
|
sta enemyShotArray + 1, Y ; Save as shot x.
|
||||||
|
|
||||||
lda #((224 - 32) / 2)
|
lda $03 ; Get enemy y.
|
||||||
and #%01111111
|
clc
|
||||||
sta enemyShotArray + 2, Y ; y.
|
adc #((32 - 4) / 2) ; Center it with enemy ship.
|
||||||
|
sta enemyShotArray + 2, Y ; Save as shot y.
|
||||||
|
|
||||||
lda #-4
|
lda #-6
|
||||||
sta enemyShotArray + 3, Y ; x-velocity.
|
sta enemyShotArray + 3, Y ; x-velocity.
|
||||||
|
|
||||||
GetRandomByte
|
lda #0
|
||||||
and #%00000111 ; [0, 7]
|
|
||||||
clc
|
|
||||||
adc #-3 ; [-3, 4]
|
|
||||||
cmp #4
|
|
||||||
bne +
|
|
||||||
lda #0 ; [-3, 3] with 2x chance of zero.
|
|
||||||
+
|
|
||||||
sta enemyShotArray + 4, Y ; y-velocity.
|
sta enemyShotArray + 4, Y ; y-velocity.
|
||||||
|
|
||||||
|
sty $00
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user