Fullscreen scrolling, initial cut at game logic
This commit is contained in:
parent
b1366fe3b2
commit
e5d1ac5c79
102
testbed.c
102
testbed.c
|
@ -469,7 +469,7 @@ int tifLoad(FILE *f, TifImageMeta_t meta, unsigned int *planeBuf, int maxY, int
|
||||||
// 89ABCDEF 01234567 << 3 => BCDEFXXX 3456789A byteswap => 3456789A BCDEFXXX
|
// 89ABCDEF 01234567 << 3 => BCDEFXXX 3456789A byteswap => 3456789A BCDEFXXX
|
||||||
|
|
||||||
#define PAGE_TILES_W 21
|
#define PAGE_TILES_W 21
|
||||||
#define PAGE_TILES_H 12
|
#define PAGE_TILES_H 14
|
||||||
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
|
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
|
||||||
#define PAGE_STRIDE (PAGE_TILES_W << 1)
|
#define PAGE_STRIDE (PAGE_TILES_W << 1)
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ typedef struct {
|
||||||
unsigned char firstBuffer;
|
unsigned char firstBuffer;
|
||||||
} TiledScreen_t;
|
} TiledScreen_t;
|
||||||
|
|
||||||
TiledScreen_t screen = { 0, 0, 0, 0, { 0x0400, 0x2400 }, 0, 0, NULL, NULL,
|
TiledScreen_t screen = { 0, 0, 0, 0, { 0x0600, 0x2B00 }, 0, 0, NULL, NULL,
|
||||||
0, 0, 0, 0, 0 };
|
0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) {
|
void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) {
|
||||||
|
@ -598,7 +598,7 @@ void drawSprite(unsigned int *sprite, int x, int y) {
|
||||||
|
|
||||||
void scroll(int newX, int newY) {
|
void scroll(int newX, int newY) {
|
||||||
newX = min(max(newX, 0), (screen.w << 4) - 320);
|
newX = min(max(newX, 0), (screen.w << 4) - 320);
|
||||||
newY = min(max(newY, 0), (screen.h << 4) - 176);
|
newY = min(max(newY, 0), (screen.h << 4) - 200);
|
||||||
if ((screen.scrollX & 0xfff0) != (newX & 0xfff0) ||
|
if ((screen.scrollX & 0xfff0) != (newX & 0xfff0) ||
|
||||||
(screen.scrollY & 0xfff0) != (newY & 0xfff0)) {
|
(screen.scrollY & 0xfff0) != (newY & 0xfff0)) {
|
||||||
int mapX, mapY;
|
int mapX, mapY;
|
||||||
|
@ -675,7 +675,7 @@ void drawScreen() {
|
||||||
/*** S C R A T C H ***/
|
/*** S C R A T C H ***/
|
||||||
#define NUM_TILES 128
|
#define NUM_TILES 128
|
||||||
#define NUM_SPRITES 64
|
#define NUM_SPRITES 64
|
||||||
#define OFF_TILES 0x4840
|
#define OFF_TILES 0x5000
|
||||||
#define TILE_STRIDE 64
|
#define TILE_STRIDE 64
|
||||||
#define SPRITE_STRIDE 80
|
#define SPRITE_STRIDE 80
|
||||||
unsigned int tiles[NUM_TILES * TILE_STRIDE];
|
unsigned int tiles[NUM_TILES * TILE_STRIDE];
|
||||||
|
@ -695,10 +695,64 @@ void fillMap() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DIR_N 0
|
||||||
|
#define DIR_E 1
|
||||||
|
#define DIR_W 2
|
||||||
|
#define DIR_S 3
|
||||||
|
|
||||||
|
#define STATE_MAP 0
|
||||||
|
#define STATE_DIALOG 1
|
||||||
|
|
||||||
|
struct entity;
|
||||||
|
typedef struct entity Entity_t;
|
||||||
|
|
||||||
|
struct entity {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int dir;
|
||||||
|
int sprites[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
void drawEntity(Entity_t *entity) {
|
||||||
|
int isprite = entity->sprites[entity->dir];
|
||||||
|
drawSprite(&sprites[isprite * SPRITE_STRIDE], entity->x, entity->y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void playerThink(Entity_t *self) {
|
||||||
|
if (keyPressed(K_LEFT)) { self->x -= 3; self->dir = DIR_W; }
|
||||||
|
if (keyPressed(K_RIGHT)) { self->x += 3; self->dir = DIR_E; }
|
||||||
|
if (keyPressed(K_UP)) { self->y -= 3; self->dir = DIR_N; }
|
||||||
|
if (keyPressed(K_DOWN)) { self->y += 3; self->dir = DIR_S; }
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int dy;
|
||||||
|
int y;
|
||||||
|
int debounce;
|
||||||
|
} Footer_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Entity_t player;
|
||||||
|
Footer_t footer;
|
||||||
|
int state;
|
||||||
|
} Game_t;
|
||||||
|
|
||||||
|
Game_t game;
|
||||||
|
|
||||||
void game_init() {
|
void game_init() {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
TifImageMeta_t meta;
|
TifImageMeta_t meta;
|
||||||
|
|
||||||
|
game.player.x = 100;
|
||||||
|
game.player.y = 100;
|
||||||
|
game.player.dir = DIR_E;
|
||||||
|
game.player.sprites[DIR_E] = 0;
|
||||||
|
game.player.sprites[DIR_N] = 1;
|
||||||
|
game.player.sprites[DIR_W] = 2;
|
||||||
|
game.player.sprites[DIR_S] = 3;
|
||||||
|
game.footer.y = 0;
|
||||||
|
game.state = STATE_MAP;
|
||||||
|
|
||||||
setEGAMode();
|
setEGAMode();
|
||||||
atexit(vid_cleanup);
|
atexit(vid_cleanup);
|
||||||
|
|
||||||
|
@ -721,7 +775,7 @@ void game_init() {
|
||||||
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
|
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
setSplitScreen(351);
|
// setSplitScreen(351);
|
||||||
|
|
||||||
loadTiles(OFF_TILES, tiles);
|
loadTiles(OFF_TILES, tiles);
|
||||||
loadMap(map, 100, 100);
|
loadMap(map, 100, 100);
|
||||||
|
@ -729,21 +783,37 @@ void game_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int x = -1;
|
|
||||||
int y = -1;
|
|
||||||
int dir = 0;
|
|
||||||
|
|
||||||
game_init();
|
game_init();
|
||||||
kbd_init();
|
kbd_init();
|
||||||
|
|
||||||
while (!keyPressed(K_ESC)) {
|
while (!keyPressed(K_ESC)) {
|
||||||
|
if (game.state == STATE_MAP) {
|
||||||
if (keyPressed(K_LEFT)) { x -= 3; dir = 2; }
|
if (keyPressed(K_SPACE)) {
|
||||||
if (keyPressed(K_RIGHT)) { x += 3; dir = 0; }
|
game.state = STATE_DIALOG;
|
||||||
if (keyPressed(K_UP)) { y -= 3; dir = 1; }
|
game.footer.debounce = 1;
|
||||||
if (keyPressed(K_DOWN)) { y += 3; dir = 3; }
|
game.footer.dy = 1;
|
||||||
scroll(x - 152, y - 90);
|
}
|
||||||
drawSprite(&sprites[dir * SPRITE_STRIDE], x, y);
|
playerThink(&game.player);
|
||||||
|
scroll(game.player.x - 152, game.player.y - 92);
|
||||||
|
} else if (game.state == STATE_DIALOG) {
|
||||||
|
if (game.footer.debounce && !keyPressed(K_SPACE)) {
|
||||||
|
game.footer.debounce = 0;
|
||||||
|
}
|
||||||
|
if (!game.footer.debounce && keyPressed(K_SPACE)) {
|
||||||
|
game.footer.dy = -1;
|
||||||
|
}
|
||||||
|
game.footer.y += game.footer.dy;
|
||||||
|
if (game.footer.dy > 0 && game.footer.y > 24) {
|
||||||
|
game.footer.y = 24;
|
||||||
|
game.footer.dy = 0;
|
||||||
|
} else if (game.footer.dy < 0 && game.footer.y < 0) {
|
||||||
|
game.footer.y = 0;
|
||||||
|
game.footer.dy = 0;
|
||||||
|
game.state = STATE_MAP;
|
||||||
|
}
|
||||||
|
setSplitScreen(399 - (game.footer.y << 1));
|
||||||
|
}
|
||||||
|
drawEntity(&game.player);
|
||||||
drawScreen();
|
drawScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
testbed.exe
BIN
testbed.exe
Binary file not shown.
Loading…
Reference in a new issue