pete286/testbed.c

173 lines
3.5 KiB
C
Executable file

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "video.h"
#include "kbd.h"
#include "mouse.h"
#include "tiff.h"
#include "tiles.h"
#include "serial.h"
#include "forp.h"
/*** 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];
void fillMap() {
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;
}
}
}
#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() {
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;
setEGAMode();
atexit(vid_cleanup);
kbd_init();
tile_init();
fillMap();
f = fopen("FOOTER.TIF", "rb");
meta = tifLoadMeta(f);
tifLoadEGA(f, meta, 0, 24, 336);
fclose(f);
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);
fclose(f);
loadTiles(OFF_TILES, tiles);
loadMap(map, 100, 100);
scroll(0, 0);
}
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() {
f_init();
f_repl();
}
int main2() {
game_init();
ser_init(SER_COM2, BAUD_19200, SER_8N1);
ser_write("JORTS QUEST DEBUG OUTPUT\r\n");
while (!keyIsDown(K_ESC)) {
kbd_debounce();
if (game.state == STATE_MAP) {
overworldThink();
} else if (game.state == STATE_DIALOG) {
dialogThink();
}
drawEntity(&game.player);
drawScreen();
}
return 0;
}