mirror of
https://github.com/jeremysrand/BuGS.git
synced 2025-01-04 04:31:44 +00:00
More work on tiles. A tile now knows the tile number of its neighbours. This will make it easier for a sprite to mark the dirty tiles when drawing.
This commit is contained in:
parent
bff623af89
commit
5c188bf91e
@ -52,6 +52,7 @@ handleDirtyTile anop
|
|||||||
asl a
|
asl a
|
||||||
asl a
|
asl a
|
||||||
asl a
|
asl a
|
||||||
|
asl a
|
||||||
tax
|
tax
|
||||||
|
|
||||||
stz tiles,x
|
stz tiles,x
|
||||||
@ -91,6 +92,7 @@ handleDirtyTile2 anop
|
|||||||
asl a
|
asl a
|
||||||
asl a
|
asl a
|
||||||
asl a
|
asl a
|
||||||
|
asl a
|
||||||
tax
|
tax
|
||||||
|
|
||||||
stz tiles,x
|
stz tiles,x
|
||||||
|
96
BuGS/tiles.c
96
BuGS/tiles.c
@ -22,6 +22,15 @@
|
|||||||
#define GAME_LEFT_MOST_X_POS (13 * TILE_WIDTH) /* 13 tiles from the left */
|
#define GAME_LEFT_MOST_X_POS (13 * TILE_WIDTH) /* 13 tiles from the left */
|
||||||
#define GAME_TOP_MOST_Y_POS (0 * TILE_HEIGHT)
|
#define GAME_TOP_MOST_Y_POS (0 * TILE_HEIGHT)
|
||||||
|
|
||||||
|
#define GAME_X_Y_TO_TILE_NUM(X, Y) \
|
||||||
|
(((Y) * GAME_NUM_TILES_WIDE) + (X))
|
||||||
|
|
||||||
|
#define RHS_X_Y_TO_TILE_NUM(X, Y) \
|
||||||
|
(RHS_FIRST_TILE + ((Y) * RHS_NUM_TILES_WIDE) + (X))
|
||||||
|
|
||||||
|
#define LHS_X_Y_TO_TILE_NUM(X, Y) \
|
||||||
|
(LHS_FIRST_TILE + ((Y) * LHS_NUM_TILES_WIDE) + (X))
|
||||||
|
|
||||||
#define TILE_OFFSET_FOR_X_Y(X, Y) \
|
#define TILE_OFFSET_FOR_X_Y(X, Y) \
|
||||||
(0x2000 + (0xa0 * (Y)) + ((X) / 2) + 3)
|
(0x2000 + (0xa0 * (Y)) + ((X) / 2) + 3)
|
||||||
|
|
||||||
@ -33,22 +42,22 @@
|
|||||||
|
|
||||||
tTile tiles[TOTAL_GAME_TILES];
|
tTile tiles[TOTAL_GAME_TILES];
|
||||||
|
|
||||||
unsigned int dirtyGameTiles[NUM_GAME_TILES + GAME_NUM_TILES_TALL];
|
tTileNum dirtyGameTiles[NUM_GAME_TILES + GAME_NUM_TILES_TALL];
|
||||||
unsigned int numDirtyGameTiles;
|
word numDirtyGameTiles;
|
||||||
|
|
||||||
unsigned int dirtyNonGameTiles[NUM_NON_GAME_TILES];
|
tTileNum dirtyNonGameTiles[NUM_NON_GAME_TILES];
|
||||||
unsigned int numDirtyNonGameTiles;
|
word numDirtyNonGameTiles;
|
||||||
|
|
||||||
unsigned int numPlayers;
|
word numPlayers;
|
||||||
|
|
||||||
|
|
||||||
/* Implementation */
|
/* Implementation */
|
||||||
|
|
||||||
void initTiles(void)
|
void initTiles(void)
|
||||||
{
|
{
|
||||||
int tileX;
|
word tileX;
|
||||||
int tileY;
|
word tileY;
|
||||||
int lastOffset;
|
word lastOffset;
|
||||||
tTile * tilePtr = &(tiles[0]);
|
tTile * tilePtr = &(tiles[0]);
|
||||||
tTile * rhsTilePtr = &(tiles[RHS_FIRST_TILE]);
|
tTile * rhsTilePtr = &(tiles[RHS_FIRST_TILE]);
|
||||||
tTile * lhsTilePtr = &(tiles[LHS_FIRST_TILE]);
|
tTile * lhsTilePtr = &(tiles[LHS_FIRST_TILE]);
|
||||||
@ -62,7 +71,29 @@ void initTiles(void)
|
|||||||
lhsTilePtr->dirty = 0;
|
lhsTilePtr->dirty = 0;
|
||||||
lhsTilePtr->offset = lastOffset;
|
lhsTilePtr->offset = lastOffset;
|
||||||
lhsTilePtr->type = TILE_EMPTY;
|
lhsTilePtr->type = TILE_EMPTY;
|
||||||
|
|
||||||
|
if (tileY == 0)
|
||||||
|
lhsTilePtr->tileAbove = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
lhsTilePtr->tileAbove = LHS_X_Y_TO_TILE_NUM(tileX, tileY - 1);
|
||||||
|
|
||||||
|
if (tileY == GAME_NUM_TILES_TALL - 1)
|
||||||
|
lhsTilePtr->tileBelow = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
lhsTilePtr->tileBelow = LHS_X_Y_TO_TILE_NUM(tileX, tileY + 1);
|
||||||
|
|
||||||
|
if (tileX == 0)
|
||||||
|
lhsTilePtr->tileLeft = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
lhsTilePtr->tileLeft = LHS_X_Y_TO_TILE_NUM(tileX - 1, tileY);
|
||||||
|
|
||||||
|
if (tileX == LHS_NUM_TILES_WIDE - 1)
|
||||||
|
lhsTilePtr->tileRight = GAME_X_Y_TO_TILE_NUM(0, tileY);
|
||||||
|
else
|
||||||
|
lhsTilePtr->tileRight = LHS_X_Y_TO_TILE_NUM(tileX + 1, tileY);
|
||||||
|
|
||||||
lhsTilePtr->dummy = 0;
|
lhsTilePtr->dummy = 0;
|
||||||
|
|
||||||
lhsTilePtr++;
|
lhsTilePtr++;
|
||||||
|
|
||||||
lastOffset += 4;
|
lastOffset += 4;
|
||||||
@ -73,6 +104,27 @@ void initTiles(void)
|
|||||||
tilePtr->dirty = 0;
|
tilePtr->dirty = 0;
|
||||||
tilePtr->offset = lastOffset;
|
tilePtr->offset = lastOffset;
|
||||||
tilePtr->type = TILE_EMPTY;
|
tilePtr->type = TILE_EMPTY;
|
||||||
|
|
||||||
|
if (tileY == 0)
|
||||||
|
tilePtr->tileAbove = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
tilePtr->tileAbove = GAME_X_Y_TO_TILE_NUM(tileX, tileY - 1);
|
||||||
|
|
||||||
|
if (tileY == GAME_NUM_TILES_TALL - 1)
|
||||||
|
tilePtr->tileBelow = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
tilePtr->tileBelow = GAME_X_Y_TO_TILE_NUM(tileX, tileY + 1);
|
||||||
|
|
||||||
|
if (tileX == 0)
|
||||||
|
tilePtr->tileLeft = LHS_X_Y_TO_TILE_NUM(LHS_NUM_TILES_WIDE - 1, tileY);
|
||||||
|
else
|
||||||
|
tilePtr->tileLeft = GAME_X_Y_TO_TILE_NUM(tileX - 1, tileY);
|
||||||
|
|
||||||
|
if (tileX == GAME_NUM_TILES_WIDE - 1)
|
||||||
|
tilePtr->tileRight = RHS_X_Y_TO_TILE_NUM(0, tileY);
|
||||||
|
else
|
||||||
|
tilePtr->tileRight = GAME_X_Y_TO_TILE_NUM(tileX + 1, tileY);
|
||||||
|
|
||||||
tilePtr->dummy = 0;
|
tilePtr->dummy = 0;
|
||||||
tilePtr++;
|
tilePtr++;
|
||||||
|
|
||||||
@ -84,6 +136,27 @@ void initTiles(void)
|
|||||||
rhsTilePtr->dirty = 0;
|
rhsTilePtr->dirty = 0;
|
||||||
rhsTilePtr->offset = lastOffset;
|
rhsTilePtr->offset = lastOffset;
|
||||||
rhsTilePtr->type = TILE_EMPTY;
|
rhsTilePtr->type = TILE_EMPTY;
|
||||||
|
|
||||||
|
if (tileY == 0)
|
||||||
|
rhsTilePtr->tileAbove = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
rhsTilePtr->tileAbove = RHS_X_Y_TO_TILE_NUM(tileX, tileY - 1);
|
||||||
|
|
||||||
|
if (tileY == GAME_NUM_TILES_TALL - 1)
|
||||||
|
rhsTilePtr->tileBelow = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
rhsTilePtr->tileBelow = RHS_X_Y_TO_TILE_NUM(tileX, tileY + 1);
|
||||||
|
|
||||||
|
if (tileX == 0)
|
||||||
|
rhsTilePtr->tileLeft = GAME_X_Y_TO_TILE_NUM(GAME_NUM_TILES_WIDE - 1, tileY);
|
||||||
|
else
|
||||||
|
rhsTilePtr->tileLeft = RHS_X_Y_TO_TILE_NUM(tileX - 1, tileY);
|
||||||
|
|
||||||
|
if (tileX == RHS_NUM_TILES_WIDE - 1)
|
||||||
|
rhsTilePtr->tileRight = INVALID_TILE_NUM;
|
||||||
|
else
|
||||||
|
rhsTilePtr->tileRight = RHS_X_Y_TO_TILE_NUM(tileX + 1, tileY);
|
||||||
|
|
||||||
rhsTilePtr->dummy = 0;
|
rhsTilePtr->dummy = 0;
|
||||||
rhsTilePtr++;
|
rhsTilePtr++;
|
||||||
|
|
||||||
@ -92,13 +165,14 @@ void initTiles(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
numDirtyGameTiles = 0;
|
numDirtyGameTiles = 0;
|
||||||
|
numDirtyNonGameTiles = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initNonGameTiles(void)
|
void initNonGameTiles(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int tileNum;
|
tTileNum tileNum;
|
||||||
numPlayers = STARTING_NUM_PLAYERS;
|
numPlayers = STARTING_NUM_PLAYERS;
|
||||||
for (i = 0; i < numPlayers; i++)
|
for (i = 0; i < numPlayers; i++)
|
||||||
{
|
{
|
||||||
@ -223,8 +297,8 @@ void initNonGameTiles(void)
|
|||||||
|
|
||||||
void addStartingMushrooms(void)
|
void addStartingMushrooms(void)
|
||||||
{
|
{
|
||||||
int tileNum;
|
tTileNum tileNum;
|
||||||
int numMushrooms = 0;
|
unsigned int numMushrooms = 0;
|
||||||
|
|
||||||
while (numMushrooms < STARTING_NUM_MUSHROOMS)
|
while (numMushrooms < STARTING_NUM_MUSHROOMS)
|
||||||
{
|
{
|
||||||
|
27
BuGS/tiles.h
27
BuGS/tiles.h
@ -10,6 +10,9 @@
|
|||||||
#define _GUARD_PROJECTBuGS_FILEtiles_
|
#define _GUARD_PROJECTBuGS_FILEtiles_
|
||||||
|
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
|
||||||
/* Defines */
|
/* Defines */
|
||||||
|
|
||||||
#define GAME_NUM_TILES_WIDE 25
|
#define GAME_NUM_TILES_WIDE 25
|
||||||
@ -29,9 +32,14 @@
|
|||||||
|
|
||||||
#define TOTAL_GAME_TILES (NUM_GAME_TILES + NUM_NON_GAME_TILES)
|
#define TOTAL_GAME_TILES (NUM_GAME_TILES + NUM_NON_GAME_TILES)
|
||||||
|
|
||||||
|
#define INVALID_TILE_NUM 0xffff
|
||||||
|
|
||||||
|
|
||||||
/* Types */
|
/* Types */
|
||||||
|
|
||||||
|
typedef word tTileNum;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TILE_EMPTY = 0,
|
TILE_EMPTY = 0,
|
||||||
TILE_MUSHROOM1 = 1,
|
TILE_MUSHROOM1 = 1,
|
||||||
@ -96,20 +104,25 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned int dirty;
|
word dirty;
|
||||||
unsigned int offset;
|
word offset;
|
||||||
tTileType type;
|
tTileType type;
|
||||||
unsigned int dummy; /* I want a size which is a multiple of 2 */
|
|
||||||
|
tTileNum tileAbove;
|
||||||
|
tTileNum tileBelow;
|
||||||
|
tTileNum tileLeft;
|
||||||
|
tTileNum tileRight;
|
||||||
|
word dummy; /* I want a size which is a multiple of 2 */
|
||||||
} tTile;
|
} tTile;
|
||||||
|
|
||||||
|
|
||||||
/* Globals */
|
/* Globals */
|
||||||
|
|
||||||
extern tTile tiles[TOTAL_GAME_TILES];
|
extern tTile tiles[TOTAL_GAME_TILES];
|
||||||
extern unsigned int dirtyGameTiles[NUM_GAME_TILES + GAME_NUM_TILES_TALL];
|
extern tTileNum dirtyGameTiles[NUM_GAME_TILES + GAME_NUM_TILES_TALL];
|
||||||
extern unsigned int numDirtyGameTiles;
|
extern word numDirtyGameTiles;
|
||||||
extern unsigned int dirtyNonGameTiles[NUM_NON_GAME_TILES];
|
extern tTileNum dirtyNonGameTiles[NUM_NON_GAME_TILES];
|
||||||
extern unsigned int numDirtyNonGameTiles;
|
extern word numDirtyNonGameTiles;
|
||||||
|
|
||||||
|
|
||||||
/* API */
|
/* API */
|
||||||
|
Loading…
Reference in New Issue
Block a user