Refactor scrolling, added road tile, first sprites drawn but not implemented
This commit is contained in:
parent
4688bdccb0
commit
28f98c20b2
BIN
sprite.tif
Executable file
BIN
sprite.tif
Executable file
Binary file not shown.
106
testbed.c
106
testbed.c
|
@ -461,25 +461,39 @@ typedef struct {
|
|||
unsigned int h;
|
||||
int scrollX;
|
||||
int scrollY;
|
||||
unsigned int pageOffset;
|
||||
unsigned char *tiles;
|
||||
} TilePage_t;
|
||||
unsigned int pageOffset[2];
|
||||
unsigned char currentPage;
|
||||
unsigned int tilesOffset;
|
||||
unsigned int *memTiles;
|
||||
unsigned char *map;
|
||||
} TiledScreen_t;
|
||||
|
||||
#define OFF_TILES 0x4840
|
||||
TiledScreen_t screen = { 0, 0, 0, 0, { 0x0400, 0x2620 }, 0, 0, NULL, NULL };
|
||||
|
||||
void scrollPage(TilePage_t *page, int x, int y) {
|
||||
x = min(max(x, 0), (page->w << 4) - 320);
|
||||
y = min(max(y, 0), (page->h << 4) - 176);
|
||||
page->scrollX = x;
|
||||
page->scrollY = y;
|
||||
void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) {
|
||||
screen.tilesOffset = tilesOffset;
|
||||
screen.memTiles = memTiles;
|
||||
}
|
||||
|
||||
void drawPage(TilePage_t *page) {
|
||||
unsigned int startX = page->scrollX >> 4;
|
||||
unsigned int startY = page->scrollY >> 4;
|
||||
unsigned int offsetX = page->scrollX - (startX << 4);
|
||||
unsigned int offsetY = page->scrollY - (startY << 4);
|
||||
unsigned int drawOffset = page->pageOffset;
|
||||
void loadMap(unsigned char *map, unsigned int w, unsigned int h) {
|
||||
screen.map = map;
|
||||
screen.w = w;
|
||||
screen.h = h;
|
||||
}
|
||||
|
||||
void scroll(int x, int y) {
|
||||
x = min(max(x, 0), (screen.w << 4) - 320);
|
||||
y = min(max(y, 0), (screen.h << 4) - 176);
|
||||
screen.scrollX = x;
|
||||
screen.scrollY = y;
|
||||
}
|
||||
|
||||
void drawScreen() {
|
||||
unsigned int startX = screen.scrollX >> 4;
|
||||
unsigned int startY = screen.scrollY >> 4;
|
||||
unsigned int offsetX = screen.scrollX - (startX << 4);
|
||||
unsigned int offsetY = screen.scrollY - (startY << 4);
|
||||
unsigned int drawOffset = screen.pageOffset[screen.currentPage];
|
||||
unsigned int scrollOffset = drawOffset + (offsetX >> 3) + (offsetY * PAGE_STRIDE);
|
||||
unsigned int x, y;
|
||||
|
||||
|
@ -487,47 +501,44 @@ void drawPage(TilePage_t *page) {
|
|||
|
||||
for (y = startY; y < startY + 13; y ++) {
|
||||
for (x = startX; x < startX + 21; x ++) {
|
||||
blitTile(OFF_TILES + page->tiles[x + (y * page->w)], drawOffset);
|
||||
blitTile(screen.tilesOffset + screen.map[x + (y * screen.w)], drawOffset);
|
||||
drawOffset += 2;
|
||||
}
|
||||
drawOffset += PAGE_STRIDE * 15;
|
||||
}
|
||||
|
||||
setDisplayOffset(scrollOffset);
|
||||
screen.currentPage ^= 1;
|
||||
}
|
||||
|
||||
/*** S C R A T C H ***/
|
||||
|
||||
unsigned char tiles[10000];
|
||||
TilePage_t pages[2] = {
|
||||
{ 100, 100, 0, 0, 0x0400, tiles },
|
||||
{ 100, 100, 0, 0, 0x2620, tiles }
|
||||
};
|
||||
unsigned int tiles[2*16 * 128];
|
||||
#define OFF_TILES 0x4840
|
||||
|
||||
void fillTiles() {
|
||||
unsigned char map[10000];
|
||||
|
||||
void fillMap() {
|
||||
unsigned int x, y, z;
|
||||
z = 0;
|
||||
|
||||
for (y = 0; y < 100; y ++) {
|
||||
for (x = 0; x < 100; x ++) {
|
||||
tiles[x + (y * 100)] = (((x + y + z) >> 2) % 3) << 5;
|
||||
map[x + (y * 100)] = (((x + y + z) >> 2) % 4) << 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
void game_init() {
|
||||
FILE *f;
|
||||
TifImageMeta_t meta;
|
||||
int plane;
|
||||
int x;
|
||||
int y;
|
||||
int z = 0;
|
||||
unsigned int drawOffset;
|
||||
unsigned int page = 0;
|
||||
|
||||
setEGAMode();
|
||||
atexit(vid_cleanup);
|
||||
|
||||
tile_init();
|
||||
fillMap();
|
||||
|
||||
f = fopen("FOOTER.TIF", "rb");
|
||||
meta = tifLoadMeta(f);
|
||||
tifLoadEGA(f, meta, 0, 24, 336);
|
||||
|
@ -536,28 +547,35 @@ int main() {
|
|||
f = fopen("TILES.TIF", "rb");
|
||||
meta = tifLoadMeta(f);
|
||||
tifLoadEGA(f, meta, OFF_TILES, 256, 16);
|
||||
tifLoad(f, meta, tiles, 128 * 16, 16);
|
||||
fclose(f);
|
||||
|
||||
kbd_init();
|
||||
tile_init();
|
||||
setSplitScreen(351);
|
||||
|
||||
fillTiles();
|
||||
loadTiles(OFF_TILES, tiles);
|
||||
loadMap(map, 100, 100);
|
||||
scroll(0, 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int x;
|
||||
int y;
|
||||
int z = 0;
|
||||
|
||||
game_init();
|
||||
kbd_init();
|
||||
|
||||
while (!keyPressed(K_ESC)) {
|
||||
page ^= 1;
|
||||
|
||||
x = pages[page].scrollX;
|
||||
y = pages[page].scrollY;
|
||||
if (keyPressed(K_LEFT)) x -= 4;
|
||||
if (keyPressed(K_RIGHT)) x += 4;
|
||||
if (keyPressed(K_UP)) y -= 4;
|
||||
if (keyPressed(K_DOWN)) y += 4;
|
||||
scrollPage(&pages[0], x, y);
|
||||
scrollPage(&pages[1], x, y);
|
||||
drawPage(&pages[page]);
|
||||
x = screen.scrollX;
|
||||
y = screen.scrollY;
|
||||
if (keyPressed(K_LEFT)) x -= 8;
|
||||
if (keyPressed(K_RIGHT)) x += 8;
|
||||
if (keyPressed(K_UP)) y -= 8;
|
||||
if (keyPressed(K_DOWN)) y += 8;
|
||||
scroll(x, y);
|
||||
drawScreen();
|
||||
|
||||
// kbd_wait();
|
||||
z++;
|
||||
}
|
||||
|
||||
|
|
BIN
testbed.exe
BIN
testbed.exe
Binary file not shown.
Loading…
Reference in a new issue