pete286/testbed.c

168 lines
3.4 KiB
C
Raw Normal View History

2019-01-05 21:16:08 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "video.h"
#include "kbd.h"
#include "mouse.h"
#include "tiff.h"
#include "tiles.h"
2019-01-30 00:35:48 +00:00
#include "serial.h"
2019-01-19 04:02:50 +00:00
/*** S C R A T C H ***/
#define NUM_TILES 128
#define NUM_SPRITES 64
#define OFF_TILES 0x5000
#define TILE_STRIDE 64
#define SPRITE_STRIDE 80
unsigned int tiles[NUM_TILES * TILE_STRIDE];
unsigned int sprites[NUM_SPRITES * SPRITE_STRIDE];
unsigned char map[10000];
2019-01-19 04:02:50 +00:00
void fillMap() {
2019-01-19 04:02:50 +00:00
unsigned int x, y, z;
z = 0;
for (y = 0; y < 100; y ++) {
for (x = 0; x < 100; x ++) {
map[x + (y * 100)] = ((x + y + z) >> 2) % 4;
2019-01-19 04:02:50 +00:00
}
2019-01-05 21:16:08 +00:00
}
}
#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 (keyIsDown(K_LEFT)) { self->x -= 3; self->dir = DIR_W; }
if (keyIsDown(K_RIGHT)) { self->x += 3; self->dir = DIR_E; }
if (keyIsDown(K_UP)) { self->y -= 3; self->dir = DIR_N; }
if (keyIsDown(K_DOWN)) { self->y += 3; self->dir = DIR_S; }
}
typedef struct {
int dy;
int y;
} Footer_t;
typedef struct {
Entity_t player;
Footer_t footer;
int state;
} Game_t;
Game_t game;
void game_init() {
2019-01-05 21:16:08 +00:00
FILE *f;
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;
2019-01-05 21:16:08 +00:00
setEGAMode();
2019-01-07 02:29:20 +00:00
atexit(vid_cleanup);
kbd_init();
tile_init();
fillMap();
2019-01-07 02:29:20 +00:00
f = fopen("FOOTER.TIF", "rb");
meta = tifLoadMeta(f);
2019-01-19 04:02:50 +00:00
tifLoadEGA(f, meta, 0, 24, 336);
2019-01-07 02:29:20 +00:00
fclose(f);
2019-01-05 21:16:08 +00:00
f = fopen("TILES.TIF", "rb");
meta = tifLoadMeta(f);
tifLoad(f, meta, tiles, NUM_TILES * 16, 16, 4);
tifLoadEGA(f, meta, OFF_TILES, NUM_TILES * 16, 16);
fclose(f);
f = fopen("SPRITE.TIF", "rb");
meta = tifLoadMeta(f);
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
2019-01-05 21:16:08 +00:00
fclose(f);
loadTiles(OFF_TILES, tiles);
loadMap(map, 100, 100);
scroll(0, 0);
}
2019-01-30 00:35:48 +00:00
void showDialog() {
game.state = STATE_DIALOG;
game.footer.dy = 1;
}
void dialogThink() {
if (keyWasPressed(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));
}
void overworldThink() {
if (keyWasPressed(K_SPACE)) {
showDialog();
}
playerThink(&game.player);
scroll(game.player.x - 152, game.player.y - 92);
}
int main() {
game_init();
2019-01-30 00:35:48 +00:00
ser_init(SER_COM2, BAUD_19200, SER_8N1);
ser_write("JORTS QUEST DEBUG OUTPUT\r\n");
2019-01-05 21:16:08 +00:00
while (!keyIsDown(K_ESC)) {
kbd_debounce();
if (game.state == STATE_MAP) {
2019-01-30 00:35:48 +00:00
overworldThink();
} else if (game.state == STATE_DIALOG) {
2019-01-30 00:35:48 +00:00
dialogThink();
}
drawEntity(&game.player);
drawScreen();
2019-01-05 21:16:08 +00:00
}
return 0;
}