Make more globals per player and index into them with the player number at game time.

This commit is contained in:
Jeremy Rand 2021-01-10 23:17:05 -05:00
parent 1cd4ccea3a
commit 384a9ea233
12 changed files with 127 additions and 71 deletions

View File

@ -98,7 +98,7 @@
9D6DB0B825932CA600CDBF05 /* scorpion.raw */ = {isa = PBXFileReference; lastKnownFileType = text; path = scorpion.raw; sourceTree = "<group>"; };
9D6DB164259D759C00CDBF05 /* tileConvert.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = tileConvert.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
9D6DB18625A411DA00CDBF05 /* BuGS.2mg */ = {isa = PBXFileReference; lastKnownFileType = file; path = BuGS.2mg; sourceTree = "<group>"; };
9D8AF0B72535542400C10E3C /* level.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = level.s; sourceTree = "<group>"; };
9D8AF0B72535542400C10E3C /* level.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = level.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
9D8AF0B82535543000C10E3C /* score.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = score.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
9D8FFC602491CA28005C9327 /* game.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = game.s; sourceTree = "<group>"; };
9D8FFC612491CAF0005C9327 /* game.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = game.h; sourceTree = "<group>"; };

View File

@ -188,9 +188,9 @@ startGame entry
startGame_notRunning anop
sta isSinglePlayer
stz gameRunning
jsl addRandomMushrooms
jsl scoreStartGame
jsl initPlayer
jsl scoreStartGame
jsl addRandomMushrooms
jsl spiderInitGame
jsl levelInit
jsl soundInit

View File

@ -98,9 +98,10 @@ updateFlea_explosionDone anop
updateFlea_maybeAdd anop
lda gameRunning
bne updateFlea_doNotAdd
lda gameLevel
ldx playerNum
lda gameLevel,x
beq updateFlea_doNotAdd
lda scoreNum20000
lda scoreNum20000,x
bne updateFlea_moreThan20000
; Below 20000 points, 5 or more mushrooms do not result in a flea
lda #4
@ -119,7 +120,7 @@ updateFlea_moreThan120000 anop
clc
adc #8
updateFlea_checkNumMushrooms anop
cmp numInfieldMushrooms
cmp numInfieldMushrooms,x
blt updateFlea_doNotAdd
jmp addFlea
@ -181,7 +182,8 @@ updateFlea_nextTile anop
sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt updateFlea_nextAction
inc numInfieldMushrooms
ldx playerNum
inc numInfieldMushrooms,x
bra updateFlea_nextAction
updateFlea_bottom anop
@ -203,7 +205,8 @@ addFlea entry
lda fleaState
bne addFlea_done
lda scoreNum20000
ldx playerNum
lda scoreNum20000,x
cmp #3
bge addFlea_fast
lda #SPRITE_SPEED_SLOW

View File

@ -98,39 +98,41 @@ addRandomMushrooms entry
lda #INVALID_TILE_NUM
sta mushroomToRefresh
ldx #RHS_FIRST_TILE_OFFSET-2
ldy #RHS_FIRST_TILE_OFFSET-2
addRandomMushrooms_clear anop
lda tileType,x
lda tileType,y
beq addRandomMushrooms_skipClear
lda #TILE_EMPTY
sta tileType,x
sta tileType,y
lda #TILE_STATE_DIRTY
sta tileDirty,x
sta tileDirty,y
addRandomMushrooms_skipClear anop
dex
dex
dey
dey
bpl addRandomMushrooms_clear
stz numInfieldMushrooms
ldy #STARTING_NUM_MUSHROOMS
ldx playerNum
stz numInfieldMushrooms,x
ldx #STARTING_NUM_MUSHROOMS
addRandomMushrooms_loop anop
phy
phx
addRandomMushrooms_tryAgain anop
jsl randomMushroomOffset
tax
lda tileType,x
tay
lda tileType,y
bne addRandomMushrooms_tryAgain
lda #TILE_MUSHROOM4
sta tileType,x
sta tileType,y
lda #TILE_STATE_DIRTY
sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET
sta tileDirty,y
cpy #SPIDER_STARTING_TOP_ROW_OFFSET
blt addRandomMushrooms_notInfield
inc numInfieldMushrooms
ldx playerNum
inc numInfieldMushrooms,x
addRandomMushrooms_notInfield anop
ply
dey
plx
dex
bne addRandomMushrooms_loop
rtl
@ -157,7 +159,8 @@ shootMushroom_poisoned anop
shootMushroom_empty anop
cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt shootMushrom_notInfield
dec numInfieldMushrooms
ldx playerNum
dec numInfieldMushrooms,x
shootMushrom_notInfield anop
jmp scoreAddOne

View File

@ -110,9 +110,9 @@ playerAddLife_playerOne anop
lda #P1_LIVES_OFFSET
playerAddLife_cont anop
sec
sbc numLives
sbc numLives,x
sec
sbc numLives
sbc numLives,x
inc numLives,x
tax
lda #TILE_PLAYER

View File

@ -90,7 +90,8 @@ updateScorpion entry
updateScorpion_playerOnscreen anop
lda scorpionState
bne updateScorpion_cont
lda gameLevel
ldx playerNum
lda gameLevel,x
cmp #3
blt updateScorpion_doNotAdd
jsl rand0_to_65534
@ -265,7 +266,8 @@ addScorpion entry
rtl
addScorpion_doit anop
lda scoreNum20000
ldx playerNum
lda scoreNum20000,x
bne addScorpion_randomSpeed
addScorpion_slow anop
lda #SPRITE_SPEED_SLOW

View File

@ -1811,7 +1811,8 @@ shootSegment_doneScore anop
shootSegment_noMushroom anop
cpy #SPIDER_STARTING_TOP_ROW_OFFSET
blt shootSegment_normalMushroom
inc numInfieldMushrooms
ldx playerNum
inc numInfieldMushrooms,x
shootSegment_normalMushroom anop
lda #TILE_MUSHROOM4
shootSegment_dirtyTile anop

View File

@ -444,7 +444,10 @@ updateSpider_tilesUp anop
sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt updateSpider_tilesUpCont
dec numInfieldMushrooms
ldy playerNum
lda numInfieldMushrooms,y
dec a
sta numInfieldMushrooms,y
updateSpider_tilesUpCont anop
ldx spiderTileOffsets+10
@ -523,7 +526,10 @@ updateSpider_tilesDown anop
sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt updateSpider_tilesDownCont
dec numInfieldMushrooms
ldy playerNum
lda numInfieldMushrooms,y
dec a
sta numInfieldMushrooms,y
updateSpider_tilesDownCont anop
ldx spiderTileOffsets+8
@ -581,9 +587,12 @@ addSpider entry
rtl
addSpider_checkSpeed anop
lda gameScore+2
lda playerNum
asl a
tax
lda gameScore+2,x
bne addSpider_fast
lda gameScore
lda gameScore,x
cmp #5000
bge addSpider_fast
lda #SPRITE_SPEED_SLOW
@ -602,7 +611,8 @@ addSpider_setHeight anop
; 120,000 to 139,999 - 9th row from bottom
; 140,000 to 159,999 - 8th row from bottom
; 160,000 to ... - 7th row from bottom
lda scoreNum20000
ldx playerNum
lda scoreNum20000,x
cmp #6
blt addSpider_height10
beq addSpider_height9

View File

@ -218,16 +218,20 @@ _dirtyNonGameTile_skip&SYSCNT anop
; Update the score
macro
_incrementScore &increment
lda playerNum
asl a
tax
lda #&increment
clc
adc gameScore
sta gameScore
adc gameScore,x
sta gameScore,x
bcc _incrementScore_noCarry&SYSCNT
inc gameScore+2
inc gameScore+2,x
_incrementScore_noCarry&SYSCNT anop
ldx playerNum
lda #&increment
clc
adc scoreWithin12000
adc scoreWithin12000,x
cmp #12000
blt _incrementScore_noExtraMan&SYSCNT
sec
@ -235,16 +239,17 @@ _incrementScore_noCarry&SYSCNT anop
pha
jsl playerAddLife
pla
ldx playerNum
_incrementScore_noExtraMan&SYSCNT anop
sta scoreWithin12000
sta scoreWithin12000,x
lda #&increment
clc
adc scoreWithin20000
adc scoreWithin20000,x
cmp #20000
blt _incrementScore_no2000&SYSCNT
sec
sbc #20000
inc scoreNum20000
inc scoreNum20000,x
_incrementScore_no2000&SYSCNT anop
sta scoreWithin20000
sta scoreWithin20000,x
mend

View File

@ -143,15 +143,6 @@ gameRunning dc i2'1'
; The following data values hold the game state and when/if 2 player is supported,
; this information will need to be copied to a backup location when the player
; switches.
numSegments dc i2'0'
gameLevel dc i2'0'
gameScore dc i4'0'
scoreWithin12000 dc i2'0'
scoreWithin20000 dc i2'0'
scoreNum20000 dc i2'0'
centipedeLevelNum dc i2'0'
colourLevelNum dc i2'0'
numInfieldMushrooms dc i2'0'
scoreOnesOffset dc i2'0'
scoreTensOffset dc i2'0'
scoreHundredsOffset dc i2'0'
@ -159,17 +150,37 @@ scoreThousandsOffset dc i2'0'
; tileType
; Two values for each of these, indexed by playerNum
gameScore dc i4'0'
dc i4'0'
scoreWithin12000 dc i2'0'
dc i2'0'
scoreWithin20000 dc i2'0'
dc i2'0'
scoreNum20000 dc i2'0'
dc i2'0'
numInfieldMushrooms dc i2'0'
dc i2'0'
numLives dc i2'0'
dc i2'0'
gameLevel dc i2'0'
dc i2'0'
colourLevelNum dc i2'0'
dc i2'0'
centipedeLevelNum dc i2'0'
dc i2'0'
playerState dc i2'PLAYER_STATE_NONE'
playerNum dc i2'0'
isSinglePlayer dc i2'0'
numLives dc i2'0' ; Two values for this, indexed by playerNum
dc i2'0'
mouseX dc i2'0'
mouseY dc i2'0'
mouseAddress dc i2'0'
backupStack dc i2'0'
collision dc i2'0'
collisionAddr dc i2'0'
numSegments dc i2'0'
tileJumpTable dc a4'solid0'

View File

@ -19,19 +19,24 @@ NEXT_LEVEL_FRAME_COUNT equ 60
levelInit entry
stz gameLevel
stz gameLevel+2
stz centipedeLevelNum
stz centipedeLevelNum+2
stz colourLevelNum
stz colourLevelNum+2
lda #SEGMENT_SPEED_FAST
sta levelOne+2
rtl
levelStart entry
lda colourLevelNum
ldx playerNum
lda colourLevelNum,x
jsl setColour
jsl startSegmentSound
ldx centipedeLevelNum
ldy playerNum
ldx centipedeLevelNum,y
lda levelTable,x
tax
lda |$0,x
@ -50,7 +55,7 @@ levelStart entry
asl a
asl a
asl a
ldx centipedeLevelNum
ldx centipedeLevelNum,y
clc
adc levelTable,x
tax
@ -98,20 +103,23 @@ updateLevel_done anop
rtl
levelNext entry
lda colourLevelNum
ldx playerNum
lda colourLevelNum,x
inc a
cmp #NUM_COLOUR_PALETTES
blt levelNext_skip
lda #0
levelNext_skip anop
sta colourLevelNum
inc gameLevel
sta colourLevelNum,x
ldx playerNum
inc gameLevel,x
lda scoreNum20000
lda scoreNum20000,x
cmp #2
bge levelNext_fastOnly
ldy centipedeLevelNum
ldx playerNum
ldy centipedeLevelNum,x
ldx levelTable,y
lda |$2,x
cmp #SEGMENT_SPEED_FAST
@ -121,7 +129,8 @@ levelNext_skip anop
rtl
levelNext_slowIncrement anop
lda centipedeLevelNum
ldx playerNum
lda centipedeLevelNum,x
cmp #LEVEL_TABLE_LAST_OFFSET
bge levelNext_slowWrap
inc a
@ -130,7 +139,7 @@ levelNext_slowIncrement anop
levelNext_slowWrap anop
lda #0
levelNext_slowNoWrap anop
sta centipedeLevelNum
sta centipedeLevelNum,x
tay
ldx levelTable,y
lda #SEGMENT_SPEED_SLOW
@ -138,7 +147,8 @@ levelNext_slowNoWrap anop
rtl
levelNext_fastOnly anop
lda centipedeLevelNum
ldx playerNum
lda centipedeLevelNum,x
cmp #LEVEL_TABLE_LAST_OFFSET
bge levelNext_fastWrap
inc a
@ -147,7 +157,7 @@ levelNext_fastOnly anop
levelNext_fastWrap anop
lda #0
levelNext_fastNoWrap anop
sta centipedeLevelNum
sta centipedeLevelNum,x
tay
ldx levelTable,y
lda #SEGMENT_SPEED_FAST

View File

@ -91,9 +91,14 @@ updateHighScore entry
scoreStartGame entry
stz gameScore
stz gameScore+2
stz gameScore+4
stz gameScore+6
stz scoreWithin12000
stz scoreWithin12000+2
stz scoreWithin20000
stz scoreWithin20000+2
stz scoreNum20000
stz scoreNum20000+2
ldx #P1_SCORE_ONES_OFFSET
lda #TILE_NUMBER_0
@ -378,12 +383,15 @@ scoreAddOneThousand_skipZeroHundreds anop
checkHighScore entry
ldy #0
checkHighScore_loop anop
lda playerNum
asl a
tax
lda settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET+2,y
cmp gameScore+2
cmp gameScore+2,x
blt checkHighScore_isHighScore
bne checkHighScore_next
lda settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET,y
cmp gameScore
cmp gameScore,x
blt checkHighScore_isHighScore
checkHighScore_next anop
tya
@ -411,9 +419,12 @@ checkHighScore_copyLoop anop
bra checkHighScore_copyLoop
checkHighScore_doneCopy anop
ldy scoreIndex
lda gameScore
lda playerNum
asl a
tax
lda gameScore,x
sta settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET,y
lda gameScore+2
lda gameScore+2,x
sta settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET+2,y
lda playerNum