From 0dd822261185b8b2c3a83f6be8271523dbb2b14a Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Mon, 26 Oct 2020 22:32:46 -0400 Subject: [PATCH] Add the code to handle restricting the spider to lower and lower rows as the score goes up. This is the final bit of game logic necessary for the bugs in the game I think. --- BuGS/game.s | 4 --- BuGS/gameFlea.s | 2 +- BuGS/gameSegments.s | 2 +- BuGS/gameSpider.s | 68 ++++++++++++++++++++++++++++++++------------- BuGS/global.macros | 2 +- BuGS/globals.s | 26 ++++++++++++----- BuGS/level.s | 2 -- BuGS/score.s | 8 ++++-- 8 files changed, 76 insertions(+), 38 deletions(-) diff --git a/BuGS/game.s b/BuGS/game.s index 9f61a29..22882d0 100644 --- a/BuGS/game.s +++ b/BuGS/game.s @@ -161,10 +161,6 @@ drawTile entry jumpInst jmp >mushroom1 nop - -addPlayer entry -; TODO - Write code to add a new life. - rtl setupScreen entry diff --git a/BuGS/gameFlea.s b/BuGS/gameFlea.s index f13493a..9fe083d 100644 --- a/BuGS/gameFlea.s +++ b/BuGS/gameFlea.s @@ -163,7 +163,7 @@ updateFlea_nextTile anop bne updateFlea_nextAction lda #TILE_MUSHROOM4 sta tileType,x - cpx #SPIDER_TOP_ROW_OFFSET + cpx #SPIDER_STARTING_TOP_ROW_OFFSET blt updateFlea_nextAction inc numInfieldMushrooms bra updateFlea_nextAction diff --git a/BuGS/gameSegments.s b/BuGS/gameSegments.s index 337b6a6..107d973 100644 --- a/BuGS/gameSegments.s +++ b/BuGS/gameSegments.s @@ -1693,7 +1693,7 @@ shootSegment_doneScore anop lda #TILE_POISON_MUSHROOM4 bra shootSegment_dirtyTile shootSegment_noMushroom anop - cpy #SPIDER_TOP_ROW_OFFSET + cpy #SPIDER_STARTING_TOP_ROW_OFFSET blt shootSegment_normalMushroom inc numInfieldMushrooms shootSegment_normalMushroom anop diff --git a/BuGS/gameSpider.s b/BuGS/gameSpider.s index 2741138..373c8cb 100644 --- a/BuGS/gameSpider.s +++ b/BuGS/gameSpider.s @@ -26,8 +26,8 @@ SPIDER_STATE_RIGHT_DOWN equ 9 SPIDER_STATE_RIGHT_UP equ 10 -SPIDER_LHS_TILE_OFFSET equ SPIDER_TOP_ROW_OFFSET -SPIDER_RHS_TILE_OFFSET equ SPIDER_TOP_ROW_OFFSET+(GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO +SPIDER_LHS_TILE_OFFSET equ SPIDER_STARTING_TOP_ROW_OFFSET +SPIDER_RHS_TILE_OFFSET equ SPIDER_STARTING_TOP_ROW_OFFSET+(GAME_NUM_TILES_WIDE-1)*SIZEOF_TILE_INFO ; The spider starts 2 pixel rows above the top row offset so it can slide in on the edge of ; the screen on a diagonal and hit the centre of the tiles with the middle of its body. @@ -63,6 +63,8 @@ SPIDER_ADD_TIME equ 120 spiderInitGame entry stz spiderAddTime stz spiderState + lda #SPIDER_STARTING_TOP_ROW + sta spiderTopRow lda #SPRITE_SPEED_SLOW jmp setSpiderSpeed @@ -418,7 +420,7 @@ updateSpider_tilesUp anop beq updateSpider_tilesUpCont lda #TILE_EMPTY sta tileType,x - cpx #SPIDER_TOP_ROW_OFFSET + cpx #SPIDER_STARTING_TOP_ROW_OFFSET blt updateSpider_tilesUpCont dec numInfieldMushrooms @@ -493,7 +495,7 @@ updateSpider_tilesDown anop beq updateSpider_tilesDownCont lda #TILE_EMPTY sta tileType,x - cpx #SPIDER_TOP_ROW_OFFSET + cpx #SPIDER_STARTING_TOP_ROW_OFFSET blt updateSpider_tilesDownCont dec numInfieldMushrooms @@ -507,17 +509,10 @@ updateSpider_tilesDownCont anop updateSpider_downChangeDir anop lda spiderTargetRow sec -; TODO - The actual top row of the spider changes as the score goes up. -; The top row of the spider based on the score is: -; 0 to 119,000 - 10th row -; 120,000 to 139,999 - 9th row -; 140,000 to 159,999 - 8th row -; 160,000 to ... - 7th row - sbc #SPIDER_TOP_ROW + sbc spiderTopRow jsl randN - inc a clc - adc #SPIDER_TOP_ROW-1 + adc spiderTopRow sta spiderTargetRow jsl rand0_to_65534 @@ -561,14 +556,42 @@ addSpider_checkSpeed anop bne addSpider_fast lda gameScore cmp #5000 - blt addSpider_doit + bge addSpider_fast + lda #SPRITE_SPEED_SLOW + bra addSpider_setSpeed addSpider_fast anop lda #SPRITE_SPEED_FAST +addSpider_setSpeed anop cmp spiderSpeed - beq addSpider_doit + beq addSpider_setHeight jsl setSpiderSpeed -addSpider_doit anop +addSpider_setHeight anop +; The actual top row of the spider changes as the score goes up. +; The top row of the spider based on the score is: +; 0 to 119,000 - 10th row from bottom +; 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 + cmp #6 + blt addSpider_height10 + beq addSpider_height9 + cmp #7 + beq addSpider_height8 + lda #SPIDER_STARTING_TOP_ROW+3 + bra addSpider_doneHeight +addSpider_height10 anop + lda #SPIDER_STARTING_TOP_ROW + bra addSpider_doneHeight +addSpider_height9 anop + lda #SPIDER_STARTING_TOP_ROW+1 + bra addSpider_doneHeight +addSpider_height8 anop + lda #SPIDER_STARTING_TOP_ROW+2 +addSpider_doneHeight anop + sta spiderTopRow + lda spiderStartingShift sta spiderShiftInTile @@ -578,12 +601,18 @@ addSpider_doit anop lda #SPIDER_SPRITE_REFRESH_COUNT sta spiderSpriteRefresh - lda #SPIDER_TOP_ROW-1 + lda #SPIDER_STARTING_TOP_ROW-1 sta spiderCurrentRow - lda #SPIDER_NUM_POSSIBLE_ROWS-1 + lda #GAME_NUM_TILES_TALL-1 + sec + sbc spiderTopRow jsl randN - adc #SPIDER_TOP_ROW+1 +; We intentionally set carry before adding here. I want to add (spiderTopRow + 1) to the +; random number we already got. That way, the target row is (spiderTopRow + 1) to +; (GAME_NUM_TILES_TALL - 1) + sec + adc spiderTopRow sta spiderTargetRow jsl rand0_to_65534 @@ -768,6 +797,7 @@ spiderScreenShift dc i2'0' spiderShiftInTile dc i2'0' spiderAddTime dc i2'0' +spiderTopRow dc i2'SPIDER_STARTING_TOP_ROW' spiderCurrentRow dc i2'0' spiderTargetRow dc i2'0' diff --git a/BuGS/global.macros b/BuGS/global.macros index 6831da9..1edf209 100644 --- a/BuGS/global.macros +++ b/BuGS/global.macros @@ -158,7 +158,7 @@ _incrementScore_noCarry&SYSCNT anop sec sbc #12000 pha - jsl addPlayer + jsl scoreEvery12000 pla _incrementScore_noExtraMan&SYSCNT anop sta scoreWithin12000 diff --git a/BuGS/globals.s b/BuGS/globals.s index d67b224..ebaddb2 100644 --- a/BuGS/globals.s +++ b/BuGS/globals.s @@ -29,9 +29,9 @@ SEGMENT_SPEED_FAST equ 0 SEGMENT_SPEED_SLOW equ 1 ; A spider only travels in the bottom N rows. This defines that number. -SPIDER_NUM_POSSIBLE_ROWS equ 10 -SPIDER_TOP_ROW equ GAME_NUM_TILES_TALL-SPIDER_NUM_POSSIBLE_ROWS -SPIDER_TOP_ROW_OFFSET equ SPIDER_TOP_ROW*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO +SPIDER_MAX_NUM_POSSIBLE_ROWS equ 10 +SPIDER_STARTING_TOP_ROW equ GAME_NUM_TILES_TALL-SPIDER_MAX_NUM_POSSIBLE_ROWS +SPIDER_STARTING_TOP_ROW_OFFSET equ SPIDER_STARTING_TOP_ROW*GAME_NUM_TILES_WIDE*SIZEOF_TILE_INFO SCREEN_BYTES_PER_ROW gequ 160 @@ -141,11 +141,23 @@ BORDER_COLOUR_REGISTER gequ $e0c034 STATE_REGISTER gequ $e1c068 VERTICAL_COUNTER gequ $e0c02e + gameRunning dc i2'1' -numSegments dc i2'0' -gameLevel dc i2'0' -gameScore dc i4'0' -scoreNum20000 dc i2'0' + +; 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 +; tileType + backupStack dc i2'0' diff --git a/BuGS/level.s b/BuGS/level.s index 73a6b43..346f7b5 100644 --- a/BuGS/level.s +++ b/BuGS/level.s @@ -144,8 +144,6 @@ levelNext_fastNoWrap anop rtl -centipedeLevelNum dc i2'0' -colourLevelNum dc i2'0' centipedeNum dc i2'0' nextLevelFrameCount dc i2'0' diff --git a/BuGS/score.s b/BuGS/score.s index c3761b6..e406582 100644 --- a/BuGS/score.s +++ b/BuGS/score.s @@ -328,9 +328,11 @@ scoreAddTwentyThousand entry jmp scoreAddToTile - +scoreEvery12000 entry +; TODO - Write code to add a new life. + rtl + + highScore dc i4'0' -scoreWithin12000 dc i2'0' -scoreWithin20000 dc i2'0' end