1 //#include "modex16.h"
\r
2 #include "src/lib/16_vl.h"
\r
3 #include "16/src/lib/bitmap.h"
\r
6 //#include "dos_kb.h"
\r
7 #define SCREEN_WIDTH 320
\r
8 #define SCREEN_HEIGHT 240
\r
10 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
18 unsigned int tilex,tiley; // tile position on the map
\r
33 int tx; //???? appears to be the tile position on the viewable screen map
\r
34 int ty; //???? appears to be the tile position on the viewable screen map
\r
35 word dxThresh; //????
\r
36 word dyThresh; //????
\r
40 int tx; //player position on the viewable map
\r
41 int ty; //player position on the viewable map
\r
45 omap_t allocMap(int w, int h);
\r
46 void oinitMap(omap_t *map);
\r
47 void omapScrollRight(omap_view_t *mv, byte offset);
\r
48 void omapScrollLeft(omap_view_t *mv, byte offest);
\r
49 void omapScrollUp(omap_view_t *mv, byte offset);
\r
50 void omapScrollDown(omap_view_t *mv, byte offset);
\r
51 void omapGoTo(omap_view_t *mv, int tx, int ty);
\r
52 void omapDrawTile(otiles_t *t, word i, page_t *page, word x, word y);
\r
53 void omapDrawRow(omap_view_t *mv, int tx, int ty, word y);
\r
54 void omapDrawCol(omap_view_t *mv, int tx, int ty, word x);
\r
56 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
58 static global_game_variables_t gvar;
\r
65 page_t screen;//,screen2;
\r
67 omap_view_t mv;//, mv2;
\r
68 omap_view_t *draw;//, *show, *tmp;
\r
71 //default player position on the viewable map
\r
77 /* create the map */
\r
78 map = allocMap(160,120); //20x15 is the resolution of the screen you can make omapS smaller than 20x15 but the null space needs to be drawn properly
\r
83 /* draw the tiles */
\r
85 modexEnter(1, 1, &gvar);
\r
86 screen = modexDefaultPage(&screen, &gvar);
\r
87 screen.width += (TILEWH*2);
\r
89 omapGoTo(&mv, 16, 16);
\r
90 // screen2=modexNextPage(mv.page);
\r
91 // mv2.page = &screen2;
\r
92 // omapGoTo(&mv2, 16, 16);
\r
93 // modexShowPage(mv.page);
\r
100 //TODO: set player position data here according to the viewable map screen thingy
\r
102 while(!gvar.in.inst->Keyboard[sc_Escape]) {
\r
103 //TODO: top left corner & bottem right corner of map veiw be set as map edge trigger since omapS are actually square
\r
104 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
105 //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map
\r
106 while(!gvar.in.inst->Keyboard[77]){
\r
107 // for(q=0; q<TILEWH; q++) {
\r
108 omapScrollRight(draw, 1);
\r
109 // modexShowPage(draw->page);
\r
110 // omapScrollRight(draw, 1);
\r
111 // SWAP(draw, show);
\r
115 while(!gvar.in.inst->Keyboard[75]){
\r
116 // for(q=0; q<TILEWH; q++) {
\r
117 omapScrollLeft(draw, 1);
\r
118 // modexShowPage(draw->page);
\r
119 // omapScrollLeft(show, 1);
\r
120 // SWAP(draw, show);
\r
124 while(!gvar.in.inst->Keyboard[80]){
\r
125 // for(q=0; q<TILEWH; q++) {
\r
126 omapScrollDown(draw, 1);
\r
127 // modexShowPage(draw->page);
\r
128 // omapScrollDown(show, 1);
\r
129 // SWAP(draw, show);
\r
133 while(!gvar.in.inst->Keyboard[72]){
\r
134 // for(q=0; q<TILEWH; q++) {
\r
135 omapScrollUp(draw, 1);
\r
136 // modexShowPage(draw->page);
\r
137 // omapScrollUp(show, 1);
\r
138 // SWAP(draw, show);
\r
143 modexShowPage(draw->page);
\r
150 IN_Shutdown(&gvar);
\r
155 allocMap(int w, int h) {
\r
160 result.data = malloc(sizeof(byte) * w * h);
\r
167 oinitMap(omap_t *map) {
\r
168 /* just a place holder to fill out an alternating pattern */
\r
172 map->tiles = malloc(sizeof(otiles_t));
\r
174 /* create the tile set */
\r
175 map->tiles->data = malloc(sizeof(bitmap_t));
\r
176 map->tiles->data->width = (TILEWH*2);
\r
177 map->tiles->data->height= TILEWH;
\r
178 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
179 map->tiles->tileHeight = TILEWH;
\r
180 map->tiles->tileWidth =TILEWH;
\r
181 map->tiles->rows = 1;
\r
182 map->tiles->cols = 2;
\r
185 for(y=0; y<TILEWH; y++) {
\r
186 for(x=0; x<(TILEWH*2); x++) {
\r
188 map->tiles->data->data[i] = 0x24;
\r
190 map->tiles->data->data[i] = 0x34;
\r
196 for(y=0; y<map->height; y++) {
\r
197 for(x=0; x<map->width; x++) {
\r
198 map->data[i] = tile;
\r
199 tile = tile ? 0 : 1;
\r
202 tile = tile ? 0 : 1;
\r
208 omapScrollRight(omap_view_t *mv, byte offset) {
\r
209 word x;//, y; /* coordinate for drawing */
\r
211 /* increment the pixel position and update the page */
\r
212 mv->page->dx += offset;
\r
214 /* check to see if this changes the tile */
\r
215 if(mv->page->dx >= mv->dxThresh ) {
\r
216 /* go forward one tile */
\r
218 /* Snap the origin forward */
\r
219 mv->page->data += 4;
\r
220 mv->page->dx = mv->map->tiles->tileWidth;
\r
223 /* draw the next column */
\r
224 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
225 omapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
231 omapScrollLeft(omap_view_t *mv, byte offset) {
\r
232 //word x, y; /* coordinate for drawing */
\r
234 /* increment the pixel position and update the page */
\r
235 mv->page->dx -= offset;
\r
237 /* check to see if this changes the tile */
\r
238 if(mv->page->dx == 0) {
\r
239 /* go backward one tile */
\r
242 /* Snap the origin backward */
\r
243 mv->page->data -= 4;
\r
244 mv->page->dx = mv->map->tiles->tileWidth;
\r
246 /* draw the next column */
\r
247 omapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
253 omapScrollUp(omap_view_t *mv, byte offset) {
\r
254 word /*x,*/ y; /* coordinate for drawing */
\r
256 /* increment the pixel position and update the page */
\r
257 mv->page->dy -= offset;
\r
259 /* check to see if this changes the tile */
\r
260 if(mv->page->dy == 0 ) {
\r
261 /* go down one tile */
\r
263 /* Snap the origin downward */
\r
264 mv->page->data -= mv->page->width*4;
\r
265 mv->page->dy = mv->map->tiles->tileHeight;
\r
268 /* draw the next row */
\r
270 omapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
276 omapScrollDown(omap_view_t *mv, byte offset) {
\r
277 word /*x,*/ y; /* coordinate for drawing */
\r
279 /* increment the pixel position and update the page */
\r
280 mv->page->dy += offset;
\r
282 /* check to see if this changes the tile */
\r
283 if(mv->page->dy >= mv->dyThresh ) {
\r
284 /* go down one tile */
\r
286 /* Snap the origin downward */
\r
287 mv->page->data += mv->page->width*4;
\r
288 mv->page->dy = mv->map->tiles->tileHeight;
\r
291 /* draw the next row */
\r
292 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
293 omapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
300 omapGoTo(omap_view_t *mv, int tx, int ty) {
\r
304 /* set up the coordinates */
\r
307 mv->page->dx = mv->map->tiles->tileWidth;
\r
308 mv->page->dy = mv->map->tiles->tileHeight;
\r
310 /* set up the thresholds */
\r
311 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
312 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
314 /* draw the tiles */
\r
315 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
317 i=mv->ty * mv->map->width + mv->tx;
\r
318 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
319 omapDrawRow(mv, tx-1, ty, py);
\r
320 i+=mv->map->width - tx;
\r
326 omapDrawTile(otiles_t *t, word i, page_t *page, word x, word y) {
\r
329 rx = (i % t->cols) * t->tileWidth;
\r
330 ry = (i / t->cols) * t->tileHeight;
\r
331 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
336 omapDrawRow(omap_view_t *mv, int tx, int ty, word y) {
\r
340 /* the position within the map array */
\r
341 i=ty * mv->map->width + tx;
\r
342 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
344 /* we are in the map, so copy! */
\r
345 omapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
353 omapDrawCol(omap_view_t *mv, int tx, int ty, word x) {
\r
357 /* location in the map array */
\r
358 i=ty * mv->map->width + tx;
\r
360 /* We'll copy all of the columns in the screen,
\r
361 i + 1 row above and one below */
\r
362 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
364 /* we are in the map, so copy away! */
\r
365 omapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
367 i += mv->map->width;
\r