1 #include "src\lib\modex16.h"
4 #include "src\lib\dos_kb.h"
5 #include "src\lib\wtest\wtest.c"
7 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
29 int tx; //appears to be the top left tile position on the viewable screen map
30 int ty; //appears to be the top left tile position on the viewable screen map
35 //TODO: make this into actor_t
37 int x; //player exact position on the viewable map
38 int y; //player exact position on the viewable map
39 int tx; //player tile position on the viewable map
40 int ty; //player tile position on the viewable map
41 int triggerx; //player's trigger box tile position on the viewable map
42 int triggery; //player's trigger box tile position on the viewable map
43 int hp; //hitpoints of the player
47 map_t allocMap(int w, int h);
48 void initMap(map_t *map);
49 void mapScrollRight(map_view_t *mv, byte offset, short lp);
50 void mapScrollLeft(map_view_t *mv, byte offest, short lp);
51 void mapScrollUp(map_view_t *mv, byte offset, short lp);
52 void mapScrollDown(map_view_t *mv, byte offset, short lp);
53 void mapGoTo(map_view_t *mv, int tx, int ty);
54 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
55 void mapDrawRow(map_view_t *mv, int tx, int ty, word y, word poopoffset);
56 void mapDrawCol(map_view_t *mv, int tx, int ty, word x, word poopoffset);
57 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y);
58 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x);
59 void animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp);
62 #define QUADWH (TILEWH/4)
65 //place holder definitions
70 //#define SWAP(a, b) tmp=a; a=b; b=tmp;
72 bitmap_t ptmp; // player sprite
75 //static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
76 page_t screen, screen2, screen3;
78 map_view_t mv, mv2, mv3;
79 map_view_t *bg, *spri, *mask;//, *tmp;
83 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
92 ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
95 modexPalUpdate(ptmp.palette);
96 screen = modexDefaultPage();
97 screen.width += (TILEWH*2);
98 screen.height += (TILEWH*2)+QUADWH;
100 screen2 = modexNextPage(mv.page);
110 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
113 //mapGoTo(mask, 0, 0);
115 //TODO: put player in starting position of spot
116 //default player position on the viewable map
117 player.tx = bg->tx + 10;
118 player.ty = bg->ty + 8;
119 player.x = player.tx*TILEWH;
120 player.y = player.ty*TILEWH;
121 player.triggerx = player.tx;
122 player.triggery = player.ty+1;
123 //TODO: erase player initial draw
124 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
125 //temp draw trigger box
126 modexClearRegion(spri->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
127 modexClearRegion(bg->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
128 modexShowPage(spri->page);
129 while(!keyp(1))//!keyp(1))
131 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
132 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
133 //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
135 #define INC_PER_FRAME if(q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
138 /*if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
140 for(q=1; q<=(TILEWH/SPEED); q++)
143 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
144 //animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
145 mapScrollRight(bg, SPEED);
146 //mapScrollRight(spri, SPEED);
147 //mapScrollRight(mask, SPEED);
148 modexShowPage(bg->page);
152 else if(player.tx < MAPX)
154 for(q=1; q<=(TILEWH/SPEED); q++)
158 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
159 animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
160 modexShowPage(spri->page);
168 if(keyp(77) && !keyp(75))
170 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
172 for(q=1; q<=(TILEWH/SPEED); q++)
175 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
176 animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
177 mapScrollRight(bg, SPEED, q);
178 mapScrollRight(spri, SPEED, q);
179 //mapScrollRight(mask, SPEED);
180 modexShowPage(spri->page);
184 else if(player.tx < MAPX && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
186 for(q=1; q<=(TILEWH/SPEED); q++)
190 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
191 animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
192 modexShowPage(spri->page);
198 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
199 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
200 modexShowPage(spri->page);
202 player.triggerx = player.tx+1;
203 player.triggery = player.ty;
206 if(keyp(75) && !keyp(77))
208 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
210 for(q=1; q<=(TILEWH/SPEED); q++)
213 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
214 animatePlayer(bg, spri, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
215 mapScrollLeft(bg, SPEED, q);
216 mapScrollLeft(spri, SPEED, q);
217 //mapScrollLeft(mask, SPEED);
218 modexShowPage(spri->page);
222 else if(player.tx > 1 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
224 for(q=1; q<=(TILEWH/SPEED); q++)
228 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
229 animatePlayer(bg, spri, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
230 modexShowPage(spri->page);
236 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
237 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
238 modexShowPage(spri->page);
240 player.triggerx = player.tx-1;
241 player.triggery = player.ty;
244 if(keyp(80) && !keyp(72))
246 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
248 for(q=1; q<=(TILEWH/SPEED); q++)
251 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
252 animatePlayer(bg, spri, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
253 mapScrollDown(bg, SPEED, q);
254 mapScrollDown(spri, SPEED, q);
255 //mapScrollDown(mask, SPEED);
256 modexShowPage(spri->page);
260 else if(player.ty < MAPY && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
262 for(q=1; q<=(TILEWH/SPEED); q++)
266 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
267 animatePlayer(bg, spri, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
268 modexShowPage(spri->page);
274 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
275 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
276 modexShowPage(spri->page);
278 player.triggerx = player.tx;
279 player.triggery = player.ty+1;
282 if(keyp(72) && !keyp(80))
284 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
286 for(q=1; q<=(TILEWH/SPEED); q++)
289 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
290 animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
291 mapScrollUp(bg, SPEED, q);
292 mapScrollUp(spri, SPEED, q);
293 //mapScrollUp(mask, SPEED);
294 modexShowPage(spri->page);
298 else if(player.ty > 1 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
300 for(q=1; q<=(TILEWH/SPEED); q++)
304 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
305 modexShowPage(spri->page);
306 animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
312 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
313 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
314 modexShowPage(spri->page);
316 player.triggerx = player.tx;
317 player.triggery = player.ty-1;
319 //modexClearRegion(mask->page, 66, 66, 2, 40, 0);
321 if((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER))
324 for(i=600; i>=400; i--)
334 printf("Project 16 scroll.exe\n");
335 printf("tx: %d\n", bg->tx);
336 printf("ty: %d\n", bg->ty);
337 printf("player.x: %d\n", player.x);
338 printf("player.y: %d\n", player.y);
339 printf("player.tx: %d\n", player.tx);
340 printf("player.ty: %d\n", player.ty);
341 printf("player.triggx: %d\n", player.triggerx);
342 printf("player.triggy: %d\n", player.triggery);
343 printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
344 printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
348 case 0: cpus = "8086/8088 or 186/88"; break;
349 case 1: cpus = "286"; break;
350 case 2: cpus = "386 or newer"; break;
351 default: cpus = "internal error"; break;
353 printf("detected CPU type: %s\n", cpus);
358 allocMap(int w, int h) {
363 result.data = malloc(sizeof(byte) * w * h);
370 initMap(map_t *map) {
371 /* just a place holder to fill out an alternating pattern */
375 map->tiles = malloc(sizeof(tiles_t));
377 /* create the tile set */
378 map->tiles->data = malloc(sizeof(bitmap_t));
379 map->tiles->data->width = (TILEWH*2);
380 map->tiles->data->height= TILEWH;
381 map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
382 map->tiles->tileHeight = TILEWH;
383 map->tiles->tileWidth =TILEWH;
384 map->tiles->rows = 1;
385 map->tiles->cols = 2;
388 for(y=0; y<TILEWH; y++) {
389 for(x=0; x<(TILEWH*2); x++) {
391 map->tiles->data->data[i] = 28;//0x24;
393 map->tiles->data->data[i] = 0;//0x34;
399 for(y=0; y<map->height; y++) {
400 for(x=0; x<map->width; x++) {
411 mapScrollRight(map_view_t *mv, byte offset, short lp) {
412 word x, y; /* coordinate for drawing */
414 /* increment the pixel position and update the page */
415 mv->page->dx += offset;
417 /* check to see if this changes the tile */
418 if(mv->page->dx >= mv->dxThresh ) {
419 /* go forward one tile */
421 /* Snap the origin forward */
423 mv->page->dx = mv->map->tiles->tileWidth;
426 /* draw the next column */
427 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
429 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x, mv->page->dx);
435 mapScrollLeft(map_view_t *mv, byte offset, short lp) {
436 word x, y; /* coordinate for drawing */
438 /* increment the pixel position and update the page */
439 mv->page->dx -= offset;
441 /* check to see if this changes the tile */
442 if(mv->page->dx == 0) {
443 /* go backward one tile */
446 /* Snap the origin backward */
448 mv->page->dx = mv->map->tiles->tileWidth;
450 /* draw the next column */
452 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0, mv->page->dx);
458 mapScrollUp(map_view_t *mv, byte offset, short lp) {
459 word x, y; /* coordinate for drawing */
461 /* increment the pixel position and update the page */
462 mv->page->dy -= offset;
464 /* check to see if this changes the tile */
465 if(mv->page->dy == 0 ) {
466 /* go down one tile */
468 /* Snap the origin downward */
469 mv->page->data -= mv->page->width*4;
470 mv->page->dy = mv->map->tiles->tileHeight;
473 /* draw the next row */
476 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y, mv->page->dy);
482 mapScrollDown(map_view_t *mv, byte offset, short lp) {
483 word x, y; /* coordinate for drawing */
485 /* increment the pixel position and update the page */
486 mv->page->dy += offset;
488 /* check to see if this changes the tile */
489 if(mv->page->dy >= mv->dyThresh ) {
490 /* go down one tile */
492 /* Snap the origin downward */
493 mv->page->data += mv->page->width*4;
494 mv->page->dy = mv->map->tiles->tileHeight;
497 /* draw the next row */
498 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
500 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y, mv->page->dy);
507 mapGoTo(map_view_t *mv, int tx, int ty) {
511 /* set up the coordinates */
514 mv->page->dx = mv->map->tiles->tileWidth;
515 mv->page->dy = mv->map->tiles->tileHeight;
517 /* set up the thresholds */
518 mv->dxThresh = mv->map->tiles->tileWidth * 2;
519 mv->dyThresh = mv->map->tiles->tileHeight * 2;
522 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
524 i=mv->ty * mv->map->width + mv->tx;
525 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
526 mapDrawWRow(mv, tx-1, ty, py);
527 i+=mv->map->width - tx;
533 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
536 rx = (i % t->cols) * t->tileWidth;
537 ry = (i / t->cols) * t->tileHeight;
538 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data);
543 mapDrawRow(map_view_t *mv, int tx, int ty, word y, word poopoffset) {
547 //printf("y: %d\n", poopoffset);
548 /* the position within the map array */
549 i=ty * mv->map->width + tx;
550 for(x=poopoffset; x<(SCREEN_WIDTH+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
552 /* we are in the map, so copy! */
553 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
561 mapDrawCol(map_view_t *mv, int tx, int ty, word x, word poopoffset) {
565 //printf("x: %d\n", poopoffset);
566 /* location in the map array */
567 i=ty * mv->map->width + tx;
569 /* We'll copy all of the columns in the screen,
570 i + 1 row above and one below */
571 for(y=poopoffset; y<(SCREEN_HEIGHT+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
573 /* we are in the map, so copy away! */
574 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
581 mapDrawWRow(map_view_t *mv, int tx, int ty, word y) {
585 /* the position within the map array */
586 i=ty * mv->map->width + tx;
587 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
589 /* we are in the map, so copy! */
590 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
597 mapDrawWCol(map_view_t *mv, int tx, int ty, word x) {
601 /* location in the map array */
602 i=ty * mv->map->width + tx;
604 /* We'll copy all of the columns in the screen,
605 i + 1 row above and one below */
606 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
608 /* we are in the map, so copy away! */
609 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
615 // animatePlayer(map_view_t *src, map_view_t *dest, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
616 // animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
617 // animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
618 // animatePlayer(map_view_t *src, map_view_t *dest, player_t *player, word playnum, sword scrolloffsetswitch, int ls, bitmap_t *bmp)
619 void animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)
621 short dire=32*d1; //direction
622 short qq; //scroll offset
625 else qq = ((lp)*SPEED);
649 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
650 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
651 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
652 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
653 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
654 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
655 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
656 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
657 //turn this off if XT
658 if(detectcpu() > 0) modexWaitBorder();