Get the scorpion moving to the right and to the left and poisoning the mushrooms. Still need to handle exploding the scorpion and double speed scorpions.

This commit is contained in:
Jeremy Rand 2020-07-22 00:06:01 -04:00
parent 44cb944f22
commit b3da2023e4
3 changed files with 184 additions and 17 deletions

View File

@ -172,7 +172,7 @@ updateFlea_nextTile anop
lda tiles+TILE_TYPE_OFFSET,x lda tiles+TILE_TYPE_OFFSET,x
bne updateFlea_nextAction bne updateFlea_nextAction
jsl rand65535 jsl rand0_to_65534
and #$7 and #$7
bne updateFlea_nextAction bne updateFlea_nextAction
lda #TILE_MUSHROOM4 lda #TILE_MUSHROOM4

View File

@ -22,6 +22,10 @@ SCORPION_STATE_EXPLODING equ 3
SCORPION_SLOW_UPDATES_PER_TILE equ TILE_PIXEL_WIDTH-1 SCORPION_SLOW_UPDATES_PER_TILE equ TILE_PIXEL_WIDTH-1
SCORPION_FAST_UPDATES_PER_TILE equ TILE_PIXEL_WIDTH/2-1 SCORPION_FAST_UPDATES_PER_TILE equ TILE_PIXEL_WIDTH/2-1
; A scorpion will only be generated in the top N rows. This defines that number.
SCORPION_NUM_POSSIBLE_ROWS equ 15
drawScorpion entry drawScorpion entry
lda scorpionState lda scorpionState
bne drawScorpion_cont bne drawScorpion_cont
@ -149,31 +153,64 @@ jumpInst jmp >leftScorpion1
updateScorpion entry updateScorpion entry
lda scorpionState lda scorpionState
beq updateScorpion_done bne updateScorpion_cont
rtl
updateScorpion_cont anop
cmp #SCORPION_STATE_EXPLODING
bra updateScorpion_notExploding
jmp updateScorpion_exploding
updateScorpion_notExploding anop
; Common code for left or right moving scorpions
lda scorpionSprite lda scorpionSprite
beq updateScorpionLeft_resetSprite beq updateScorpion_resetSprite
sec sec
sbc #$4 sbc #$4
sta scorpionSprite sta scorpionSprite
bra updateScorpionLeft_nextAction bra updateScorpion_nextAction
updateScorpionLeft_resetSprite anop updateScorpion_resetSprite anop
lda #SCORPION_SPRITE_LAST_OFFSET lda #SCORPION_SPRITE_LAST_OFFSET
sta scorpionSprite sta scorpionSprite
updateScorpionLeft_nextAction anop updateScorpion_nextAction anop
lda scorpionShiftInTile lda scorpionShiftInTile
beq updateScorpionLeft_nextTile beq updateScorpion_nextTile
dec a dec a
sta scorpionShiftInTile sta scorpionShiftInTile
and #$1 and #$1
beq updateScorpion_done beq updateScorpion_done
dec scorpionScreenOffset lda scorpionState
bra updateScorpion_done cmp #SCORPION_STATE_LEFT
beq updateScorpion_screenLeft
inc scorpionScreenOffset
rtl
updateScorpion_screenLeft anop
dec scorpionScreenOffset
rtl
updateScorpion_nextTile anop
lda scorpionState
cmp #SCORPION_STATE_LEFT
beq updateScorpionLeft_nextTile
updateScorpionRight_nextTile anop
inc scorpionScreenOffset
lda #SCORPION_SLOW_UPDATES_PER_TILE
sta scorpionShiftInTile
ldx scorpionTileOffsets+2
cpx #RHS_FIRST_TILE_OFFSET
blt updateScorpionRight_notOffScreen
cpx #LHS_FIRST_TILE_OFFSET
bge updateScorpionRight_notOffScreen
bra updateScorpion_offScreen
updateScorpionLeft_nextTile anop updateScorpionLeft_nextTile anop
dec scorpionScreenOffset dec scorpionScreenOffset
lda #SCORPION_SLOW_UPDATES_PER_TILE lda #SCORPION_SLOW_UPDATES_PER_TILE
@ -188,11 +225,32 @@ updateScorpionLeft_nextTile anop
stx scorpionTileOffsets+2 stx scorpionTileOffsets+2
lda tiles+TILE_LEFT_OFFSET,x lda tiles+TILE_LEFT_OFFSET,x
sta scorpionTileOffsets sta scorpionTileOffsets
bra updateScorpion_maybePoison
updateScorpionRight_notOffScreen anop
stx scorpionTileOffsets+4
ldx scorpionTileOffsets
stx scorpionTileOffsets+2
lda tiles+TILE_RIGHT_OFFSET,x
sta scorpionTileOffsets
updateScorpion_maybePoison anop
lda tiles+TILE_TYPE_OFFSET,x
beq updateScorpion_done
cmp #TILE_MUSHROOM4+1
bge updateScorpion_done
ora #32
sta tiles+TILE_TYPE_OFFSET,x
rtl rtl
updateScorpion_offScreen anop updateScorpion_offScreen anop
stz scorpionState stz scorpionState
rtl
updateScorpion_exploding anop
; Write this code
updateScorpion_done anop updateScorpion_done anop
rtl rtl
@ -201,11 +259,20 @@ addScorpion entry
lda scorpionState lda scorpionState
bne addScorpion_done bne addScorpion_done
jsl rand0_to_14
asl a
tay
jsl rand0_to_65534
and #1
beq addScorpion_right
lda #SCORPION_STATE_LEFT lda #SCORPION_STATE_LEFT
sta scorpionState sta scorpionState
ldx #(24+25)*16 ldx scorpionLeftTileOffset,y
stx scorpionTileOffsets stx scorpionTileOffsets
lda tiles+TILE_SCREEN_OFFSET_OFFSET,x lda tiles+TILE_SCREEN_OFFSET_OFFSET,x
dec a dec a
sta scorpionScreenOffset sta scorpionScreenOffset
@ -217,6 +284,30 @@ addScorpion entry
lda tiles+TILE_RIGHT_OFFSET,x lda tiles+TILE_RIGHT_OFFSET,x
sta scorpionTileOffsets+4 sta scorpionTileOffsets+4
bra addScorpion_common
addScorpion_right anop
lda #SCORPION_STATE_RIGHT
sta scorpionState
ldx scorpionRightTileOffset,y
stx scorpionTileOffsets
lda tiles+TILE_LEFT_OFFSET,x
sta scorpionTileOffsets+2
tax
lda tiles+TILE_LEFT_OFFSET,x
sta scorpionTileOffsets+4
tax
lda tiles+TILE_SCREEN_OFFSET_OFFSET,x
dec a
dec a
sta scorpionScreenOffset
addScorpion_common anop
lda #SCORPION_SLOW_UPDATES_PER_TILE lda #SCORPION_SLOW_UPDATES_PER_TILE
sta scorpionShiftInTile sta scorpionShiftInTile
@ -275,6 +366,40 @@ scorpionRightJumpTable dc i4'rightScorpion4'
dc i4'rightScorpion1s' dc i4'rightScorpion1s'
dc i4'rightScorpion1' dc i4'rightScorpion1'
dc i4'rightScorpion1s' dc i4'rightScorpion1s'
scorpionLeftTileOffset dc i2'((0*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((1*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((2*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((3*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((4*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((5*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((6*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((7*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((8*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((9*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((10*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((11*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((12*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((13*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
dc i2'((14*GAME_NUM_TILES_WIDE)+GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO'
scorpionRightTileOffset dc i2'0*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'1*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'2*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'3*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'4*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'5*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'6*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'7*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'8*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'9*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'10*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'11*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'12*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'13*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
dc i2'14*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO'
end end

View File

@ -4,6 +4,27 @@
; ;
; Created by Jeremy Rand on 2020-07-19. ; Created by Jeremy Rand on 2020-07-19.
;Copyright © 2020 Jeremy Rand. All rights reserved. ;Copyright © 2020 Jeremy Rand. All rights reserved.
;
;
; This code was suggested by John Brooks
;
; If you need a random range less than 16 bits, here the smaller EOR constants:
; BITS EOR_CONST
; 2 $0003
; 3 $0006
; 4 $000C
; 5 $0014
; 6 $0030
; 7 $0060
; 8 $00B8
; 9 $0110
; 10 $0240
; 11 $0500
; 12 $0CA0
; 13 $1B00
; 14 $3500
; 15 $6000
; 16 $B400
; ;
case on case on
@ -15,44 +36,65 @@ random start
randInit entry randInit entry
lda randomSeed lda randomSeed
sta seed65535 sta seed65535
and #$1f and #$1f
bne randInit_store32 bne randInit_store32
lda #$1f lda #$1f
randInit_store32 anop randInit_store32 anop
sta seed32 sta seed32
and #$f
bne randInit_store16
lda #$f
randInit_store16 anop
sta seed16
rtl rtl
; Returns a number from 0 to 14
rand0_to_14 entry
lda seed16
lsr a
bcc skipEor16
eor #$000c
skipEor16 anop
sta seed16
dec a
rtl
; Returns a number from 1 to 31 ; Returns a number from 0 to 30
rand32 entry rand0_to_30 entry
lda seed32 lda seed32
lsr a lsr a
bcc skipEor32 bcc skipEor32
eor #$0014 eor #$0014
skipEor32 anop skipEor32 anop
sta seed32 sta seed32
dec a
rtl rtl
; returns a number from 0 to 24 ; returns a number from 0 to 24
rand25 entry rand25 entry
jsl rand32 jsl rand0_to_30
dec a
cmp #25 cmp #25
bge rand25 bge rand25
rtl rtl
; Returns a number from 1 to 65535 ; Returns a number from 0 to 65534
rand65535 entry rand0_to_65534 entry
lda seed65535 lda seed65535
lsr a lsr a
bcc skipEor65535 bcc skipEor65535
eor #$b400 eor #$b400
skipEor65535 anop skipEor65535 anop
sta seed65535 sta seed65535
dec a
rtl rtl
seed65535 dc i2'0' seed65535 dc i2'0'
seed32 dc i2'0' seed32 dc i2'0'
seed16 dc i2'0'
end end