1 #include "src\lib\modex16.h"
\r
4 #include "src\lib\dos_kb.h"
\r
5 #include "src\lib\wtest\wtest.c"
\r
7 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
29 int tx; //appears to be the top left tile position on the viewable screen map
\r
30 int ty; //appears to be the top left tile position on the viewable screen map
\r
31 word dxThresh; //????
\r
32 word dyThresh; //????
\r
36 int x; //player exact position on the viewable map
\r
37 int y; //player exact position on the viewable map
\r
38 int tx; //player tile position on the viewable map
\r
39 int ty; //player tile position on the viewable map
\r
40 int triggerx; //player's trigger box tile position on the viewable map
\r
41 int triggery; //player's trigger box tile position on the viewable map
\r
42 word q; //loop variable
\r
44 int hp; //hitpoints of the player
\r
48 map_t allocMap(int w, int h);
\r
49 void initMap(map_t *map);
\r
50 void mapScrollRight(map_view_t *mv, byte offset);
\r
51 void mapScrollLeft(map_view_t *mv, byte offest);
\r
52 void mapScrollUp(map_view_t *mv, byte offset);
\r
53 void mapScrollDown(map_view_t *mv, byte offset);
\r
54 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
55 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
56 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
57 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
58 void animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp);
\r
61 #define QUADWH (TILEWH/4)
\r
63 //#define LOOPMAX (TILEWH/SPEED)
\r
65 //place holder definitions
\r
70 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
\r
72 bitmap_t ptmp; // player sprite
\r
74 static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
\r
75 page_t screen, screen2, screen3;
\r
77 map_view_t mv, mv2, mv3;
\r
78 map_view_t *bg, *spri, *mask;//, *tmp;
84 /* save the palette */
\r
85 pal = modexNewPal();
\r
87 modexFadeOff(4, pal);
\r
90 /* create the map */
\r
91 map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
\r
97 /* draw the tiles */
\r
100 ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
\r
104 modexPalUpdate(ptmp.palette);
\r
105 modexFadeOn(4, ptmp.palette);
\r
106 screen = modexDefaultPage();
\r
107 screen.width += (TILEWH*2);
\r
108 screen.height += (TILEWH*2)+QUADWH;
\r
110 screen2 = modexNextPage(mv.page);
\r
111 mv2.page = &screen2;
\r
113 mv3.page = &screen3;
\r
115 /* set up paging */
\r
120 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
\r
122 mapGoTo(spri, 0, 0);
\r
123 //mapGoTo(mask, 0, 0);
\r
125 //TODO: put player in starting position of spot
\r
126 //default player position on the viewable map
127 player.tx = bg->tx + 10;
\r
128 player.ty = bg->ty + 8;
\r
129 player.x = player.tx*TILEWH;
\r
130 player.y = player.ty*TILEWH;
\r
131 player.triggerx = player.tx;
\r
132 player.triggery = player.ty+1;
\r
135 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
\r
137 modexClearRegion(spri->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
\r
138 modexClearRegion(bg->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
\r
139 modexShowPage(spri->page);
\r
142 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
143 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
144 //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
145 #define INC_PER_FRAME if(player.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
148 if((keyp(77) && !keyp(75) && player.d == 0) || player.d == 2)
\r
150 if(player.d == 0){ player.d = 2; }
\r
151 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
\r
153 if(player.q<=(TILEWH/SPEED))
\r
156 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
157 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
158 mapScrollRight(bg, SPEED);
\r
159 mapScrollRight(spri, SPEED);
\r
160 //mapScrollRight(mask, SPEED);
\r
161 modexShowPage(spri->page);
\r
163 } else { player.q = 1; player.d = 0; player.tx++; }
\r
165 else if(player.tx < MAPX && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
\r
167 if(player.q<=(TILEWH/SPEED))
\r
171 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
172 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
173 modexShowPage(spri->page);
\r
175 } else { player.q = 1; player.d = 0; player.tx++; }
\r
179 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
180 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
\r
181 modexShowPage(spri->page);
\r
184 player.triggerx = player.tx+1;
\r
185 player.triggery = player.ty;
\r
189 if((keyp(75) && !keyp(77) && player.d == 0) || player.d == 4)
\r
191 if(player.d == 0){ player.d = 4; }
\r
192 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
\r
194 if(player.q<=(TILEWH/SPEED))
\r
197 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
198 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
199 mapScrollLeft(bg, SPEED);
\r
200 mapScrollLeft(spri, SPEED);
\r
201 //mapScrollLeft(mask, SPEED);
\r
202 modexShowPage(spri->page);
\r
204 } else { player.q = 1; player.d = 0; player.tx--; }
\r
206 else if(player.tx > 1 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
\r
208 if(player.q<=(TILEWH/SPEED))
\r
212 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
213 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
214 modexShowPage(spri->page);
\r
216 } else { player.q = 1; player.d = 0; player.tx--; }
\r
220 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
221 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
\r
222 modexShowPage(spri->page);
\r
225 player.triggerx = player.tx-1;
\r
226 player.triggery = player.ty;
\r
230 if((keyp(80) && !keyp(72) && player.d == 0) || player.d == 3)
\r
232 if(player.d == 0){ player.d = 3; }
\r
233 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
\r
235 if(player.q<=(TILEWH/SPEED))
\r
238 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
239 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
240 mapScrollDown(bg, SPEED);
\r
241 mapScrollDown(spri, SPEED);
\r
242 //mapScrollDown(mask, SPEED);
\r
243 modexShowPage(spri->page);
\r
245 } else { player.q = 1; player.d = 0; player.ty++; }
\r
247 else if(player.ty < MAPY && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
\r
249 if(player.q<=(TILEWH/SPEED))
\r
253 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
254 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
255 modexShowPage(spri->page);
\r
257 } else { player.q = 1; player.d = 0; player.ty++; }
\r
261 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
262 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
\r
263 modexShowPage(spri->page);
\r
266 player.triggerx = player.tx;
\r
267 player.triggery = player.ty+1;
\r
271 if((keyp(72) && !keyp(80) && player.d == 0) || player.d == 1)
\r
273 if(player.d == 0){ player.d = 1; }
\r
274 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
\r
276 if(player.q<=(TILEWH/SPEED))
\r
279 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
280 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
281 mapScrollUp(bg, SPEED);
\r
282 mapScrollUp(spri, SPEED);
\r
283 //mapScrollUp(mask, SPEED);
\r
284 modexShowPage(spri->page);
\r
286 } else { player.q = 1; player.d = 0; player.ty--; }
\r
288 else if(player.ty > 1 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
\r
290 if(player.q<=(TILEWH/SPEED))
\r
294 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
295 modexShowPage(spri->page);
\r
296 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
298 } else { player.q = 1; player.d = 0; player.ty--; }
\r
302 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
303 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
\r
304 modexShowPage(spri->page);
\r
307 player.triggerx = player.tx;
\r
308 player.triggery = player.ty-1;
\r
310 //modexClearRegion(mask->page, 66, 66, 2, 40, 0);
\r
312 if((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER))
\r
315 for(i=600; i>=400; i--)
\r
323 /* fade back to text mode */
\r
324 modexFadeOff(4, ptmp.palette);
\r
328 printf("Project 16 scroll.exe\n");
\r
329 printf("tx: %d\n", bg->tx);
\r
330 printf("ty: %d\n", bg->ty);
\r
331 printf("player.x: %d\n", player.x);
\r
332 printf("player.y: %d\n", player.y);
\r
333 printf("player.tx: %d\n", player.tx);
\r
334 printf("player.ty: %d\n", player.ty);
\r
335 printf("player.triggx: %d\n", player.triggerx);
\r
336 printf("player.triggy: %d\n", player.triggery);
\r
337 printf("player.q: %d\n", player.q);
\r
338 printf("player.d: %d\n", player.d);
\r
339 printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
\r
340 printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
\r
342 switch(detectcpu())
\r
344 case 0: cpus = "8086/8088 or 186/88"; break;
\r
345 case 1: cpus = "286"; break;
\r
346 case 2: cpus = "386 or newer"; break;
\r
347 default: cpus = "internal error"; break;
\r
349 printf("detected CPU type: %s\n", cpus);
\r
351 modexFadeOn(4, pal);
\r
356 allocMap(int w, int h) {
\r
361 result.data = malloc(sizeof(byte) * w * h);
\r
368 initMap(map_t *map) {
\r
369 /* just a place holder to fill out an alternating pattern */
\r
373 map->tiles = malloc(sizeof(tiles_t));
\r
375 /* create the tile set */
\r
376 map->tiles->data = malloc(sizeof(bitmap_t));
\r
377 map->tiles->data->width = (TILEWH*2);
\r
378 map->tiles->data->height= TILEWH;
\r
379 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
380 map->tiles->tileHeight = TILEWH;
\r
381 map->tiles->tileWidth =TILEWH;
\r
382 map->tiles->rows = 1;
\r
383 map->tiles->cols = 2;
\r
386 for(y=0; y<TILEWH; y++) {
\r
387 for(x=0; x<(TILEWH*2); x++) {
\r
389 map->tiles->data->data[i] = 28;//0x24;
\r
391 map->tiles->data->data[i] = 0;//0x34;
\r
397 for(y=0; y<map->height; y++) {
\r
398 for(x=0; x<map->width; x++) {
\r
399 map->data[i] = tile;
\r
400 tile = tile ? 0 : 1;
\r
403 tile = tile ? 0 : 1;
\r
409 mapScrollRight(map_view_t *mv, byte offset) {
\r
410 word x, y; /* coordinate for drawing */
\r
412 /* increment the pixel position and update the page */
\r
413 mv->page->dx += offset;
\r
415 /* check to see if this changes the tile */
\r
416 if(mv->page->dx >= mv->dxThresh ) {
\r
417 /* go forward one tile */
\r
419 /* Snap the origin forward */
\r
420 mv->page->data += 4;
\r
421 mv->page->dx = mv->map->tiles->tileWidth;
\r
424 /* draw the next column */
\r
425 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
426 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
432 mapScrollLeft(map_view_t *mv, byte offset) {
\r
433 word x, y; /* coordinate for drawing */
\r
435 /* increment the pixel position and update the page */
\r
436 mv->page->dx -= offset;
\r
438 /* check to see if this changes the tile */
\r
439 if(mv->page->dx == 0) {
\r
440 /* go backward one tile */
\r
443 /* Snap the origin backward */
\r
444 mv->page->data -= 4;
\r
445 mv->page->dx = mv->map->tiles->tileWidth;
\r
447 /* draw the next column */
\r
448 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
454 mapScrollUp(map_view_t *mv, byte offset) {
\r
455 word x, y; /* coordinate for drawing */
\r
457 /* increment the pixel position and update the page */
\r
458 mv->page->dy -= offset;
\r
460 /* check to see if this changes the tile */
\r
461 if(mv->page->dy == 0 ) {
\r
462 /* go down one tile */
\r
464 /* Snap the origin downward */
\r
465 mv->page->data -= mv->page->width*4;
\r
466 mv->page->dy = mv->map->tiles->tileHeight;
\r
469 /* draw the next row */
\r
471 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
477 mapScrollDown(map_view_t *mv, byte offset) {
\r
478 word x, y; /* coordinate for drawing */
\r
480 /* increment the pixel position and update the page */
\r
481 mv->page->dy += offset;
\r
483 /* check to see if this changes the tile */
\r
484 if(mv->page->dy >= mv->dyThresh ) {
\r
485 /* go down one tile */
\r
487 /* Snap the origin downward */
\r
488 mv->page->data += mv->page->width*4;
\r
489 mv->page->dy = mv->map->tiles->tileHeight;
\r
492 /* draw the next row */
\r
493 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
494 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
501 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
505 /* set up the coordinates */
\r
508 mv->page->dx = mv->map->tiles->tileWidth;
\r
509 mv->page->dy = mv->map->tiles->tileHeight;
\r
511 /* set up the thresholds */
\r
512 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
513 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
515 /* draw the tiles */
\r
516 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
518 i=mv->ty * mv->map->width + mv->tx;
\r
519 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
520 mapDrawRow(mv, tx-1, ty, py);
\r
521 i+=mv->map->width - tx;
\r
527 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
530 rx = (i % t->cols) * t->tileWidth;
\r
531 ry = (i / t->cols) * t->tileHeight;
\r
532 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
\r
537 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
541 /* the position within the map array */
\r
542 i=ty * mv->map->width + tx;
\r
543 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
545 /* we are in the map, so copy! */
\r
546 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
553 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
557 /* location in the map array */
\r
558 i=ty * mv->map->width + tx;
\r
560 /* We'll copy all of the columns in the screen,
\r
561 i + 1 row above and one below */
\r
562 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
564 /* we are in the map, so copy away! */
\r
565 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
567 i += mv->map->width;
\r
572 animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)
\r
574 short dire=32*d1; //direction
\r
575 short qq; //scroll offset
\r
578 else qq = ((lp)*SPEED);
\r
602 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
603 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
\r
604 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
\r
605 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
\r
606 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
\r
607 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
608 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
\r
609 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
\r
610 //turn this off if XT
\r
611 if(detectcpu() > 0) modexWaitBorder();
\r