1 #include "src/lib/dos_kb.h"
\r
2 #include "src/lib/mapread.c"
\r
3 //#include "16\lib\x\modex.h"
\r
4 #include "src/lib/wtest/wtest.c"
\r
5 #include "src/lib/planar.c"
\r
6 //====#include "src\lib\ems.c"
\r
8 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
\r
30 int tx; //appears to be the top left tile position on the viewable screen map
\r
31 int ty; //appears to be the top left tile position on the viewable screen map
\r
32 word dxThresh; //????
\r
33 word dyThresh; //????
\r
37 int x; //player exact position on the viewable map
\r
38 int y; //player exact position on the viewable map
\r
39 int tx; //player tile position on the viewable map
\r
40 int ty; //player tile position on the viewable map
\r
41 int triggerx; //player's trigger box tile position on the viewable map
\r
42 int triggery; //player's trigger box tile position on the viewable map
\r
43 int setx; //NOT USED YET! player sprite sheet set on the image x
\r
44 int sety; //NOT USED YET! player sprite sheet set on the image y
\r
45 word q; //loop variable
\r
47 bitmap_t data; //supposively the sprite sheet data
\r
48 int hp; //hitpoints of the player
\r
51 map_t allocMap(int w, int h);
\r
52 void initMap(map_t *map);
\r
53 void mapScrollRight(map_view_t *mv, byte offset);
\r
54 void mapScrollLeft(map_view_t *mv, byte offest);
\r
55 void mapScrollUp(map_view_t *mv, byte offset);
\r
56 void mapScrollDown(map_view_t *mv, byte offset);
\r
57 void mapGoTo(map_view_t *mv, int tx, int ty);
\r
58 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
\r
59 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
\r
60 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
\r
62 void pdump(map_view_t *pee);
\r
63 void animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, short scrolloffsetswitch, int x, int y, int ls, int lp, bitmap_t *bmp);
\r
66 #define QUADWH TILEWH/2
\r
68 //#define LOOPMAX (TILEWH/SPEED)
\r
70 //place holder definitions
\r
77 size_t oldfreemem=GetFreeSize();
\r
81 word panswitch=0, panq=1, pand=0; //for panning!
\r
83 static word paloffset=0;
\r
84 bitmap_t ptmp;//, npctmp; // player sprite
\r
87 static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */
\r
88 page_t screen, screen2, screen3;
\r
90 map_view_t mv, mv2, mv3;
\r
91 map_view_t *bg, *spri, *mask;//, *tmp;
\r
93 byte *ptr, *mappalptr;
\r
97 // atexit(qclean());
\r
100 printf("Expanded memory is not present\n");
\r
106 printf("Expanded memory manager is not present\n");
\r
110 emsavail = emmavail();
\r
113 printf("Expanded memory manager error\n");
\r
116 printf("There are %ld pages available\n",emsavail);
\r
118 if((emmhandle = emmalloc(emsavail)) < 0)
\r
120 printf("Insufficient pages available\n");
\r
124 /* create the map */
\r
125 //0000 printf("Total used @ before map load: %zu\n", oldfreemem-GetFreeSize());
\r
126 loadmap("data/test.map", &map);
\r
127 //---- map = allocMap(map.width,map.height); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
\r
128 //if(isEMS()) printf("%d tesuto\n", coretotalEMS());
\r
129 //---- initMap(&map);
\r
134 /* draw the tiles */
\r
136 mappalptr = map.tiles->data->palette;
\r
138 //0000 printf("Total used @ before image loading: %zu\n", oldfreemem-GetFreeSize());
\r
139 ptmp = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
\r
140 //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
\r
142 /* create the planar buffer */
\r
143 //0000 printf("Total used @ before planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
\r
144 p = planar_buf_from_bitmap(&ptmp);
\r
145 //0000 printf("Total used @ after planar buffer creation: %zu\n", oldfreemem-GetFreeSize());
\r
150 mm.length=sizeof(map);
\r
152 mm.sourceOff=(long)↦
\r
153 mm.destH=emmhandle;
\r
156 ist = move_emem(&mm);
\r
157 printf("%d\n", coretotalEMS());
\r
158 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
159 //printf("%d\n", emmhandle);
\r
165 mm.length=emmhandle;
\r
167 mm.sourceOff=(long)&ptmp;
\r
168 mm.destH=emmhandle;
\r
171 ist = move_emem(&mm);
\r
172 printf("%d\n", coretotalEMS());
\r
173 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
174 //printf("%d\n", emmhandle);
\r
178 /* save the palette */
\r
179 dpal = modexNewPal();
\r
180 modexPalSave(dpal);
\r
181 modexFadeOff(4, dpal);
\r
185 modexPalBlack(); //reset the palette~
\r
186 // printf("Total used @ before palette initiation: %zu\n", oldfreemem-GetFreeSize());
\r
187 ptmp.offset=(paloffset/3);
\r
188 modexPalUpdate(&ptmp, &paloffset, 0, 0);
\r
189 //printf(" %d\n", sizeof(ptmp.data));
\r
190 //printf("1: %d\n", paloffset);
\r
191 map.tiles->data->offset=(paloffset/3);
\r
192 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
\r
193 printf("\n====\n");
\r
194 printf("0 paloffset= %d\n", paloffset/3);
\r
195 printf("====\n\n");
\r
196 gpal = modexNewPal();
\r
197 modexPalSave(gpal);
\r
198 modexSavePalFile("data/g.pal", gpal);
\r
199 modexPalBlack(); //so player will not see loadings~
\r
201 /* setup camera and screen~ */
\r
202 screen = modexDefaultPage();
\r
203 screen.width += (TILEWH*2);
\r
204 screen.height += (TILEWH*2)+QUADWH;
\r
206 screen2 = modexNextPage(mv.page);
\r
207 mv2.page = &screen2;
\r
209 mv3.page = &screen3;
\r
211 /* set up paging */
\r
216 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
\r
218 mapGoTo(spri, 0, 0);
\r
219 //mapGoTo(mask, 0, 0);
\r
221 //TODO: put player in starting position of spot
\r
222 //default player position on the viewable map
\r
223 player.tx = bg->tx + 10;
\r
224 player.ty = bg->ty + 8;
\r
225 player.x = player.tx*TILEWH;
\r
226 player.y = player.ty*TILEWH;
\r
227 player.triggerx = player.tx;
\r
228 player.triggery = player.ty+1;
\r
233 /*npc0.tx = bg->tx + 1;
\r
234 npc0.ty = bg->ty + 1;
\r
235 npc0.x = npc0.tx*TILEWH;
\r
236 npc0.y = npc0.ty*TILEWH;
\r
237 npc0.triggerx = npc0.tx;
\r
238 npc0.triggery = npc0.ty+1;
\r
241 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
\r
242 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
\r
244 modexShowPage(spri->page);
\r
245 // printf("Total used @ before loop: %zu\n", oldfreemem-GetFreeSize());
\r
246 modexFadeOn(4, gpal);
\r
247 while(!keyp(1) && player.hp>0)
\r
249 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
\r
250 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
\r
251 //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
252 #define INC_PER_FRAME if(player.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
254 //modexClearRegion(bg->page, player.x, player.y, 16, 16, 4); //currently the over scan color!
\r
255 /*#define INC_PER_FRAME_NPC if(npc0.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;
\r
257 if(npc0.d == 0 && npc0.q == 1) npc0.d =rand()%8;
\r
264 if(npc0.tx < map.width && !(npc0.tx+1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty))
\r
266 if(npc0.q<=(TILEWH/SPEED))
\r
270 //animatePlayer(bg, spri, mask, 1, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
271 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
272 modexShowPage(spri->page);
\r
274 } else { npc0.q = 1; npc0.d = 0; npc0.tx++; }
\r
278 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
279 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 32, 24, 32, &npctmp);
\r
280 modexShowPage(spri->page);
\r
283 npc0.triggerx = npc0.tx+1;
\r
284 npc0.triggery = npc0.ty;
\r
290 if(npc0.tx > 1 && !(npc0.tx-1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx-1 == player.tx && npc0.ty == player.ty))
\r
292 if(npc0.q<=(TILEWH/SPEED))
\r
296 //animatePlayer(bg, spri, mask, 3, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
297 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
298 modexShowPage(spri->page);
\r
300 } else { npc0.q = 1; npc0.d = 0; npc0.tx--; }
\r
304 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
305 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 96, 24, 32, &npctmp);
\r
306 modexShowPage(spri->page);
\r
309 npc0.triggerx = npc0.tx-1;
\r
310 npc0.triggery = npc0.ty;
\r
316 if(npc0.ty < map.height && !(npc0.tx == TRIGGX && npc0.ty+1 == TRIGGY) && !(npc0.tx == player.tx && npc0.ty == player.ty+1))
\r
318 if(npc0.q<=(TILEWH/SPEED))
\r
322 //animatePlayer(bg, spri, mask, 2, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
323 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
324 modexShowPage(spri->page);
\r
326 } else { npc0.q = 1; npc0.d = 0; npc0.ty++; }
\r
330 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
331 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);
\r
332 modexShowPage(spri->page);
\r
335 npc0.triggerx = npc0.tx;
\r
336 npc0.triggery = npc0.ty+1;
\r
342 if(npc0.ty > 1 && !(npc0.tx == TRIGGX && npc0.ty-1 == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty-1))
\r
344 if(npc0.q<=(TILEWH/SPEED))
\r
348 //animatePlayer(bg, spri, mask, 0, 0, npc0.x, npc0.y, persist_aniframe, q, &npctmp);
\r
349 modexShowPage(spri->page);
\r
350 animatePlayer(bg, spri, npc0.d-1, 0, npc0.x, npc0.y, persist_aniframe, npc0.q, &npctmp);
\r
352 } else { npc0.q = 1; npc0.d = 0; npc0.ty--; }
\r
356 modexCopyPageRegion(spri->page, bg->page, npc0.x-4, npc0.y-TILEWH, npc0.x-4, npc0.y-TILEWH, 24, 32);
\r
357 modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 0, 24, 32, &npctmp);
\r
358 modexShowPage(spri->page);
\r
361 npc0.triggerx = npc0.tx;
\r
362 npc0.triggery = npc0.ty-1;
\r
365 if((npc0.triggery == player.ty && npc0.triggerx == player.tx) || (npc0.ty == player.ty && npc0.tx == player.tx)){ player.hp--; }
\r
369 //TODO: make movement into a function!
372 if((keyp(77) && !keyp(75) && player.d == 0) || player.d == 2)
\r
374 if(player.d == 0){ player.d = 2; }
\r
375 if(bg->tx >= 0 && bg->tx+20 < map.width && player.tx == bg->tx + 10 &&
376 !(bg->map->data[(player.tx)+(map.width*(player.ty-1))] == 0))//!(player.tx+1 == TRIGGX && player.ty == TRIGGY)) //collision detection!
\r
378 if(player.q<=(TILEWH/SPEED))
\r
381 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
382 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
383 mapScrollRight(bg, SPEED);
\r
384 mapScrollRight(spri, SPEED);
\r
385 //mapScrollRight(mask, SPEED);
\r
386 modexShowPage(spri->page);
\r
388 } else { player.q = 1; player.d = 0; player.tx++; }
\r
390 else if(player.tx < map.width && !(bg->map->data[(player.tx)+(map.width*(player.ty-1))] == 0))//!(player.tx+1 == TRIGGX && player.ty == TRIGGY))
\r
392 if(player.q<=(TILEWH/SPEED))
\r
396 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
397 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
398 modexShowPage(spri->page);
\r
400 } else { player.q = 1; player.d = 0; player.tx++; }
\r
404 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
405 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
\r
406 modexShowPage(spri->page);
\r
409 player.triggerx = player.tx+1;
\r
410 player.triggery = player.ty;
\r
414 if((keyp(75) && !keyp(77) && player.d == 0) || player.d == 4)
\r
416 if(player.d == 0){ player.d = 4; }
\r
417 if(bg->tx > 0 && bg->tx+20 <= map.width && player.tx == bg->tx + 10 &&
418 !(bg->map->data[(player.tx-2)+(map.width*(player.ty-1))] == 0))//!(player.tx-1 == TRIGGX && player.ty == TRIGGY)) //collision detection!
\r
420 if(player.q<=(TILEWH/SPEED))
\r
423 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
424 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
425 mapScrollLeft(bg, SPEED);
\r
426 mapScrollLeft(spri, SPEED);
\r
427 //mapScrollLeft(mask, SPEED);
\r
428 modexShowPage(spri->page);
\r
430 } else { player.q = 1; player.d = 0; player.tx--; }
\r
432 else if(player.tx > 1 && !(bg->map->data[(player.tx-2)+(map.width*(player.ty-1))] == 0))//!(player.tx-1 == TRIGGX && player.ty == TRIGGY))
\r
434 if(player.q<=(TILEWH/SPEED))
\r
438 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
439 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
440 modexShowPage(spri->page);
\r
442 } else { player.q = 1; player.d = 0; player.tx--; }
\r
446 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
447 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
\r
448 modexShowPage(spri->page);
\r
451 player.triggerx = player.tx-1;
\r
452 player.triggery = player.ty;
\r
456 if((keyp(80) && !keyp(72) && player.d == 0) || player.d == 3)
\r
458 if(player.d == 0){ player.d = 3; }
\r
459 if(bg->ty >= 0 && bg->ty+15 < map.height && player.ty == bg->ty + 8 &&
460 !(bg->map->data[(player.tx-1)+(map.width*(player.ty))] == 0))//!(player.tx == TRIGGX && player.ty+1 == TRIGGY)) //collision detection!
\r
462 if(player.q<=(TILEWH/SPEED))
\r
465 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
466 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
467 mapScrollDown(bg, SPEED);
\r
468 mapScrollDown(spri, SPEED);
\r
469 //mapScrollDown(mask, SPEED);
\r
470 modexShowPage(spri->page);
\r
472 } else { player.q = 1; player.d = 0; player.ty++; }
\r
474 else if(player.ty < map.height && !(bg->map->data[(player.tx-1)+(map.width*(player.ty))] == 0))//!(player.tx == TRIGGX && player.ty+1 == TRIGGY))
\r
476 if(player.q<=(TILEWH/SPEED))
\r
480 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
481 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
482 modexShowPage(spri->page);
\r
484 } else { player.q = 1; player.d = 0; player.ty++; }
\r
488 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
489 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
\r
490 modexShowPage(spri->page);
\r
493 player.triggerx = player.tx;
\r
494 player.triggery = player.ty+1;
\r
498 if((keyp(72) && !keyp(80) && player.d == 0) || player.d == 1)
\r
500 if(player.d == 0){ player.d = 1; }
\r
501 if(bg->ty > 0 && bg->ty+15 <= map.height && player.ty == bg->ty + 8 &&
502 !(bg->map->data[(player.tx-1)+(map.width*(player.ty-2))] == 0))//!(player.tx == TRIGGX && player.ty-1 == TRIGGY)) //collision detection!
\r
504 if(player.q<=(TILEWH/SPEED))
\r
507 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
\r
508 animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
509 mapScrollUp(bg, SPEED);
\r
510 mapScrollUp(spri, SPEED);
\r
511 //mapScrollUp(mask, SPEED);
\r
512 modexShowPage(spri->page);
\r
514 } else { player.q = 1; player.d = 0; player.ty--; }
\r
516 else if(player.ty > 1 && !(bg->map->data[(player.tx-1)+(map.width*(player.ty-2))] == 0))//!(player.tx == TRIGGX && player.ty-1 == TRIGGY))
\r
518 if(player.q<=(TILEWH/SPEED))
\r
522 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
\r
523 modexShowPage(spri->page);
\r
524 animatePlayer(bg, spri, player.d-1, 0, player.x, player.y, persist_aniframe, player.q, &ptmp);
\r
526 } else { player.q = 1; player.d = 0; player.ty--; }
\r
530 modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
\r
531 modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
\r
532 modexShowPage(spri->page);
\r
535 player.triggerx = player.tx;
\r
536 player.triggery = player.ty-1;
\r
541 if((keyp(77) && !keyp(75) && pand == 0) || pand == 2)
\r
543 if(pand == 0){ pand = 2; }
\r
544 if(panq<=(TILEWH/SPEED))
\r
548 modexShowPage(bg->page);
549 modexShowPage(spri->page);
551 } else { panq = 1; pand = 0; }
\r
554 if((keyp(75) && !keyp(77) && pand == 0) || pand == 4)
\r
556 if(pand == 0){ pand = 4; }
\r
557 if(panq<=(TILEWH/SPEED))
\r
561 modexShowPage(bg->page);
562 modexShowPage(spri->page);
564 } else { panq = 1; pand = 0; }
\r
567 if((keyp(72) && !keyp(80) && pand == 0) || pand == 3)
\r
569 if(pand == 0){ pand = 3; }
\r
570 if(panq<=(TILEWH/SPEED))
\r
574 modexShowPage(bg->page);
575 modexShowPage(spri->page);
577 } else { panq = 1; pand = 0; }
\r
580 if((keyp(80) && !keyp(72) && pand == 0) || pand == 1)
\r
582 if(pand == 0){ pand = 1; }
\r
583 if(panq<=(TILEWH/SPEED))
\r
587 modexShowPage(bg->page);
588 modexShowPage(spri->page);
\r
590 } else { panq = 1; pand = 0; }
\r
593 //if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(0x1C))||(player.tx == 5 && player.ty == 5))
594 if(((bg->map->data[(player.triggerx-1)+(map.width*(player.triggery-1))] == 0) && keyp(0x1C))||(player.tx == 5 && player.ty == 5))
\r
597 for(i=800; i>=400; i--)
\r
603 if(player.q == (TILEWH/SPEED)+1 && player.d > 0 && (player.triggerx == 5 && player.triggery == 5)){ player.hp--; }
\r
604 //if(keyp(0x0E)) while(1){ if(xmsmalloc(24)) break; }
\r
605 if(keyp(25)){ pdump(bg); pdump(spri); }
\r
606 if(keyp(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg); pdump(spri); }
\r
608 paloffset=0; modexPalBlack(); modexPalUpdate(&ptmp, &paloffset, 0, 0);
\r
609 printf("1paloffset = %d\n", paloffset/3);
\r
610 modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
\r
611 printf("2paloffset = %d\n", paloffset/3);
\r
612 pdump(bg); pdump(spri); }
614 if(keyp(88)){if(!panswitch) panswitch++; else panswitch--; }
\r
626 if((player.q==1) && !(player.x%TILEWH==0 && player.y%TILEWH==0)) break; //incase things go out of sync!
630 /* fade back to text mode */
\r
631 /* but 1st lets save the game palette~ */
\r
632 modexPalSave(gpal);
\r
633 modexSavePalFile("data/g.pal", gpal);
\r
634 modexFadeOff(4, gpal);
\r
637 printf("Project 16 scroll.exe\n");
\r
638 printf("tx: %d\n", bg->tx);
\r
639 printf("ty: %d\n", bg->ty);
640 printf("player.x: %d", player.x); printf(" player.y: %d\n", player.y);
\r
641 //if(player.hp==0) printf("%d wwww\n", player.y+8);
\r
642 //else printf("\nplayer.y: %d\n", player.y);
\r
643 printf("player.tx: %d", player.tx); printf(" player.ty: %d\n", player.ty);
\r
644 printf("player.triggx: %d", player.triggerx); printf(" player.triggy: %d\n", player.triggery);
\r
645 printf("player.hp: %d", player.hp); printf(" player.q: %d", player.q); printf(" player.d: %d\n", player.d);
646 printf("tile data value at player trigger position: %d\n", bg->map->data[(player.triggerx-1)+(map.width*(player.triggery-1))]);
\r
647 printf("palette offset: %d\n", paloffset/3);
\r
648 printf("Total used: %zu\n", oldfreemem-GetFreeSize());
\r
649 printf("Total free: %zu\n", GetFreeSize());
\r
650 printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
\r
651 printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
\r
652 printf("Screen: %dx", screen.width); printf("%d\n", screen.height);
\r
653 printf("Screen2: %dx", screen2.width); printf("%d\n", screen2.height);
\r
659 //emmclose(emmhandle);
\r
660 switch(detectcpu())
\r
662 case 0: cpus = "8086/8088 or 186/88"; break;
\r
663 case 1: cpus = "286"; break;
\r
664 case 2: cpus = "386 or newer"; break;
\r
665 default: cpus = "internal error"; break;
\r
667 printf("detected CPU type: %s\n", cpus);
\r
668 modexFadeOn(4, dpal);
\r
673 allocMap(int w, int h) {
\r
678 result.data = malloc(sizeof(byte) * w * h);
\r
679 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
\r
680 /*if(isEMS() || checkEMS())
\r
683 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
\r
684 mm.length=sizeof(result);
\r
686 mm.sourceOff=ptr2long(&result);
\r
687 mm.destH=emmhandle;
\r
689 ist = move_emem(&mm);
\r
690 if(!ist){ dealloc_emem(emmhandle); exit(5); }
\r
691 printf("%d\n", coretotalEMS());
\r
698 initMap(map_t *map) {
\r
699 /* just a place holder to fill out an alternating pattern */
\r
703 //if(!isEMS() || !checkEMS())
\r
704 // map->tiles = malloc(sizeof(tiles_t));
\r
706 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
\r
708 /* create the tile set */
\r
709 //if(!isEMS() || !checkEMS())
\r
710 // map->tiles->data = malloc(sizeof(bitmap_t));
\r
712 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
\r
713 // map->tiles->data->width = (TILEWH/**2*/);
\r
714 // map->tiles->data->height= TILEWH;
\r
715 //if(!isEMS() || !checkEMS())
\r
716 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
\r
718 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
\r
719 // map->tiles->tileHeight = TILEWH;
\r
720 // map->tiles->tileWidth =TILEWH;
\r
721 // map->tiles->rows = 1;
\r
722 // map->tiles->cols = 1;//2;
\r
725 //for(y=0; y<map->height; y++) {
\r
726 //for(x=0; x<map->width; x++) {
\r
728 for(yy=0; yy<TILEWH; yy++) {
\r
729 for(xx=0; xx<(TILEWH); xx++) {
\r
731 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
\r
732 // printf("[%d]", map->tiles->data->data[i]);
\r
734 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
\r
735 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
\r
741 // printf("[%d]", map->data[q]);
\r
748 for(y=0; y<map->height; y++) {
\r
749 for(x=0; x<map->width; x++) {
\r
750 // map->data[i]=255;
\r
751 printf("[%d]", map->data[i]);
\r
752 //tile = tile ? 0 : 1;
\r
755 //tile = tile ? 0 : 1;
\r
761 mapScrollRight(map_view_t *mv, byte offset) {
\r
762 word x, y; /* coordinate for drawing */
\r
764 /* increment the pixel position and update the page */
\r
765 mv->page->dx += offset;
\r
767 /* check to see if this changes the tile */
\r
768 if(mv->page->dx >= mv->dxThresh ) {
\r
769 /* go forward one tile */
\r
771 /* Snap the origin forward */
\r
772 mv->page->data += 4;
\r
773 mv->page->dx = mv->map->tiles->tileWidth;
\r
776 /* draw the next column */
\r
777 x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
\r
778 mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
\r
784 mapScrollLeft(map_view_t *mv, byte offset) {
\r
785 word x, y; /* coordinate for drawing */
\r
787 /* increment the pixel position and update the page */
\r
788 mv->page->dx -= offset;
\r
790 /* check to see if this changes the tile */
\r
791 if(mv->page->dx == 0) {
\r
792 /* go backward one tile */
\r
795 /* Snap the origin backward */
\r
796 mv->page->data -= 4;
\r
797 mv->page->dx = mv->map->tiles->tileWidth;
\r
799 /* draw the next column */
\r
800 mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
\r
806 mapScrollUp(map_view_t *mv, byte offset) {
\r
807 word x, y; /* coordinate for drawing */
\r
809 /* increment the pixel position and update the page */
\r
810 mv->page->dy -= offset;
\r
812 /* check to see if this changes the tile */
\r
813 if(mv->page->dy == 0 ) {
\r
814 /* go down one tile */
\r
816 /* Snap the origin downward */
\r
817 mv->page->data -= mv->page->width*4;
\r
818 mv->page->dy = mv->map->tiles->tileHeight;
\r
821 /* draw the next row */
\r
823 mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
\r
829 mapScrollDown(map_view_t *mv, byte offset) {
\r
830 word x, y; /* coordinate for drawing */
\r
832 /* increment the pixel position and update the page */
\r
833 mv->page->dy += offset;
\r
835 /* check to see if this changes the tile */
\r
836 if(mv->page->dy >= mv->dyThresh ) {
\r
837 /* go down one tile */
\r
839 /* Snap the origin downward */
\r
840 mv->page->data += mv->page->width*4;
\r
841 mv->page->dy = mv->map->tiles->tileHeight;
\r
844 /* draw the next row */
\r
845 y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
\r
846 mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
\r
853 mapGoTo(map_view_t *mv, int tx, int ty) {
\r
857 /* set up the coordinates */
\r
860 mv->page->dx = mv->map->tiles->tileWidth;
\r
861 mv->page->dy = mv->map->tiles->tileHeight;
\r
863 /* set up the thresholds */
\r
864 mv->dxThresh = mv->map->tiles->tileWidth * 2;
\r
865 mv->dyThresh = mv->map->tiles->tileHeight * 2;
\r
867 /* draw the tiles */
\r
868 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
\r
870 i=mv->ty * mv->map->width + mv->tx;
\r
871 for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
\r
872 mapDrawRow(mv, tx-1, ty, py);
\r
873 i+=mv->map->width - tx;
\r
879 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) {
\r
886 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
\r
890 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
\r
891 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
\r
892 //mxPutTile(t->data, x, y, t->tileWidth, t->tileHeight);
\r
893 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
\r
899 mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
\r
903 /* the position within the map array */
\r
904 i=ty * mv->map->width + tx;
\r
905 for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
\r
907 /* we are in the map, so copy! */
\r
908 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
915 mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
\r
919 /* location in the map array */
\r
920 i=ty * mv->map->width + tx;
\r
922 /* We'll copy all of the columns in the screen,
\r
923 i + 1 row above and one below */
\r
924 for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
\r
926 /* we are in the map, so copy away! */
\r
927 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
\r
929 i += mv->map->width;
\r
939 void pdump(map_view_t *pee)
\r
942 int palq=(mult)*TILEWH;
\r
945 for(paly=0; paly<palq; paly+=mult){
\r
946 for(palx=0; palx<palq; palx+=mult){
\r
947 modexClearRegion(pee->page, palx+TILEWH, paly+TILEWH, mult, mult, palcol);
\r
954 animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, short scrolloffsetswitch, int x, int y, int ls, int lp, bitmap_t *bmp)
\r
956 sword dire=32*d; //direction
\r
957 sword qq; //scroll offset
\r
959 if(scrolloffsetswitch==0) qq = 0;
\r
960 else qq = ((lp)*SPEED);
\r
984 modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
985 if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
\r
986 if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
\r
987 if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
\r
988 if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
\r
989 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
\r
990 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
\r
991 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
\r
992 //turn this off if XT
\r
993 if(detectcpu() > 0) modexWaitBorder();
\r