diff --git a/BuGS/game.s b/BuGS/game.s index f906ca2..b5ad584 100644 --- a/BuGS/game.s +++ b/BuGS/game.s @@ -208,6 +208,7 @@ nextWord anop startGame entry stz gameRunning stz numSegments + jsl addRandomMushrooms jsl initPlayer jsl spiderInitGame jsl levelInit diff --git a/BuGS/gameMushroom.s b/BuGS/gameMushroom.s index bacd0e4..de0c96d 100644 --- a/BuGS/gameMushroom.s +++ b/BuGS/gameMushroom.s @@ -13,6 +13,35 @@ gameMushroom start using globalData + +STARTING_NUM_MUSHROOMS equ 30 + + +addRandomMushrooms entry + stz numInfieldMushrooms + ldy #STARTING_NUM_MUSHROOMS + +addRandomMushrooms_loop anop + phy +addRandomMushrooms_tryAgain anop + jsl randomMushroomOffset + tax + lda tileType,x + bne addRandomMushrooms_tryAgain + lda #TILE_MUSHROOM4 + sta tileType,x + lda #TILE_STATE_DIRTY + sta tileDirty,x + cpx #SPIDER_STARTING_TOP_ROW_OFFSET + blt addRandomMushrooms_notInfield + inc numInfieldMushrooms +addRandomMushrooms_notInfield anop + ply + dey + bne addRandomMushrooms_loop + rtl + + ; Call this with the tile offset of the mushroom being shot in the X register shootMushroom entry ldy tileType,x @@ -52,11 +81,7 @@ shootRandomMushroom entry bra shootRandomMushroom_testTile shootRandomMushroom_doRandom anop - jsl rand0_to_65534 - and #1023 - cmp #24*25 - bge shootRandomMushroom_doRandom - asl a + jsl randomMushroomOffset tax shootRandomMushroom_testTile anop lda tileType,x diff --git a/BuGS/globals.s b/BuGS/globals.s index 25a0669..d870dce 100644 --- a/BuGS/globals.s +++ b/BuGS/globals.s @@ -159,7 +159,7 @@ scoreWithin20000 dc i2'0' scoreNum20000 dc i2'0' centipedeLevelNum dc i2'0' colourLevelNum dc i2'0' -; numInfieldMushrooms +numInfieldMushrooms dc i2'0' ; tileType diff --git a/BuGS/main.c b/BuGS/main.c index 7a695a1..4aae96a 100644 --- a/BuGS/main.c +++ b/BuGS/main.c @@ -34,6 +34,14 @@ unsigned int randomSeed; /* Implementation */ +tTileOffset randomMushroomOffset(void) +{ + /* We do not put mushrooms in the bottom tile so we subtract the width here to find + a tile number above that last line */ + return (rand() % (NUM_GAME_TILES - GAME_NUM_TILES_WIDE)) * sizeof(word); +} + + int main(void) { int event; @@ -65,7 +73,6 @@ int main(void) initTiles(); initNonGameTiles(); - addStartingMushrooms(); game(); diff --git a/BuGS/tiles.c b/BuGS/tiles.c index c3b613c..1e79def 100644 --- a/BuGS/tiles.c +++ b/BuGS/tiles.c @@ -34,11 +34,8 @@ #define SCREEN_ADDRESS_FOR_TILE_AT_X_Y(X, Y) \ (0x2000 + (0xa0 * (Y)) + ((X) / 2) + 3) -#define STARTING_NUM_MUSHROOMS 30 #define STARTING_NUM_PLAYERS 3 -#define ADD_DIRTY_GAME_TILE(tileNum) tileDirty[tileNum] = 1; - #define ADD_DIRTY_NON_GAME_TILE(tileNum) \ if (!tileDirty[tileNum]) { \ tileDirty[tileNum] = 1; \ @@ -61,10 +58,6 @@ word tileBitMask[NUM_GAME_TILES]; tTileOffset dirtyNonGameTiles[NUM_NON_GAME_TILES]; word numDirtyNonGameTiles; -word numPlayers; - -word numInfieldMushrooms; - /* Implementation */ @@ -295,9 +288,8 @@ void initNonGameTiles(void) tileType[tileNum] = TILE_SYMBOL_COLON; ADD_DIRTY_NON_GAME_TILE(tileNum); - numPlayers = STARTING_NUM_PLAYERS; tileNum = LHS_FIRST_TILE + (10 * LHS_NUM_TILES_WIDE) - 2; - for (i = 0; i < numPlayers; i++) + for (i = 0; i < STARTING_NUM_PLAYERS; i++) { tileType[tileNum] = TILE_PLAYER; ADD_DIRTY_NON_GAME_TILE(tileNum); @@ -430,35 +422,11 @@ void initNonGameTiles(void) tileType[tileNum] = TILE_SYMBOL_COLON; ADD_DIRTY_NON_GAME_TILE(tileNum); - numPlayers = STARTING_NUM_PLAYERS; tileNum = LHS_FIRST_TILE + (23 * LHS_NUM_TILES_WIDE) - 2; - for (i = 0; i < numPlayers; i++) + for (i = 0; i < STARTING_NUM_PLAYERS; i++) { tileType[tileNum] = TILE_PLAYER; ADD_DIRTY_NON_GAME_TILE(tileNum); tileNum--; } } - - -void addStartingMushrooms(void) -{ - tTileNum tileNum; - unsigned int numMushrooms = 0; - numInfieldMushrooms = 0; - - while (numMushrooms < STARTING_NUM_MUSHROOMS) - { - /* We do not put mushrooms in the bottom tile so we subtract the width here to find - a tile number above that last line */ - tileNum = rand() % (NUM_GAME_TILES - GAME_NUM_TILES_WIDE); - if (tileType[tileNum] != TILE_EMPTY) - continue; - - tileType[tileNum] = TILE_MUSHROOM4; - ADD_DIRTY_GAME_TILE(tileNum); - numMushrooms++; - if ((tileNum / GAME_NUM_TILES_WIDE) >= GAME_NUM_TILES_TALL - 10) - numInfieldMushrooms++; - } -} diff --git a/BuGS/tiles.h b/BuGS/tiles.h index 2b9dae6..61338ad 100644 --- a/BuGS/tiles.h +++ b/BuGS/tiles.h @@ -120,13 +120,11 @@ extern word tileBitMask[NUM_GAME_TILES]; extern tTileOffset dirtyNonGameTiles[NUM_NON_GAME_TILES]; extern word numDirtyNonGameTiles; -extern word numInfieldMushrooms; /* API */ extern void initTiles(void); -extern void addStartingMushrooms(void); #endif /* define _GUARD_PROJECTBuGS_FILEtiles_ */