1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "src/lib/scroll16.h"
27 void walk(map_view_t *pip, player_t *player, word pn)
29 #define INC_PER_FRAME if(player[pn].q&1) player[pn].persist_aniframe++; if(player[pn].persist_aniframe>4) player[pn].persist_aniframe = 1;
30 //printf("player[%d].d=%d\n", pn, player[pn].d);
35 //printf("pip[0].page->tilesw=%d ", pip[0].page->tilesw); printf("pip[0].page->tw=%d\n", pip[0].page->tw);
36 if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->tw < pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
37 !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY)) //collision detection!
39 if(player[pn].q<=player[pn].spt)
42 animatePlayer(pip, player, pn, 1);
43 mapScrollRight(pip, player, 0, pn);
44 mapScrollRight(pip, player, 1, pn);
45 ScrollRight(pip, player, 2, pn);
46 ScrollRight(pip, player, 3, pn);
47 if(!pageflipflop) modexShowPage(pip[1].page);
49 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
51 else if(player[pn].tx < pip[0].map->width && !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY))
53 if(player[pn].q<=player[pn].spt)
56 player[pn].x+=(player[pn].speed);
57 animatePlayer(pip, player, pn, 0);
58 if(!pageflipflop) modexShowPage(pip[1].page);
60 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
64 modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x-4, player[pn].y-TILEWH, player[pn].x-4, player[pn].y-TILEWH, 24, 32);
66 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 24, 32, PLAYERBMPDATA);
68 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 14);
70 if(!pageflipflop) modexShowPage(pip[1].page);
73 player[pn].triggerx = player[pn].tx+1;
74 player[pn].triggery = player[pn].ty;
79 if(pip[0].tx > 0 && pip[0].tx+pip[0].page->tw <= pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
80 !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY)) //collision detection!
82 if(player[pn].q<=player[pn].spt)
85 animatePlayer(pip, player, pn, 1);
86 mapScrollLeft(pip, player, 0, pn);
87 mapScrollLeft(pip, player, 1, pn);
88 ScrollLeft(pip, player, 2, pn);
89 ScrollLeft(pip, player, 3, pn);
90 if(!pageflipflop) modexShowPage(pip[1].page);
92 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
94 else if(player[pn].tx > 1 && !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY))
96 if(player[pn].q<=player[pn].spt)
99 player[pn].x-=(player[pn].speed);
100 animatePlayer(pip, player, pn, 0);
101 if(!pageflipflop) modexShowPage(pip[1].page);
103 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
107 modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x-4, player[pn].y-TILEWH, player[pn].x-4, player[pn].y-TILEWH, 24, 32);
109 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 96, 24, 32, PLAYERBMPDATA);
111 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 10);
113 if(!pageflipflop) modexShowPage(pip[1].page);
116 player[pn].triggerx = player[pn].tx-1;
117 player[pn].triggery = player[pn].ty;
122 if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->th < pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
123 !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY)) //collision detection!
125 if(player[pn].q<=player[pn].spt)
128 animatePlayer(pip, player, pn, 1);
129 mapScrollDown(pip, player, 0, pn);
130 mapScrollDown(pip, player, 1, pn);
131 ScrollDown(pip, player, 2, pn);
132 ScrollDown(pip, player, 3, pn);
133 if(!pageflipflop) modexShowPage(pip[1].page);
135 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
137 else if(player[pn].ty < pip[0].map->height && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY))
139 if(player[pn].q<=player[pn].spt)
142 player[pn].y+=(player[pn].speed);
143 animatePlayer(pip, player, pn, 0);
144 if(!pageflipflop) modexShowPage(pip[1].page);
146 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
150 modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x-4, player[pn].y-TILEWH, player[pn].x-4, player[pn].y-TILEWH, 24, 32);
152 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 64, 24, 32, PLAYERBMPDATA);
154 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 9);
156 if(!pageflipflop) modexShowPage(pip[1].page);
159 player[pn].triggerx = player[pn].tx;
160 player[pn].triggery = player[pn].ty+1;
165 if(pip[0].ty > 0 && pip[0].ty+pip[0].page->th <= pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
166 !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty-1 == TRIGGY)) //collision detection!
168 if(player[pn].q<=player[pn].spt)
171 animatePlayer(pip, player, pn, 1);
172 mapScrollUp(pip, player, 0, pn);
173 mapScrollUp(pip, player, 1, pn);
174 ScrollUp(pip, player, 2, pn);
175 ScrollUp(pip, player, 3, pn);
176 if(!pageflipflop) modexShowPage(pip[1].page);
178 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
180 else if(player[pn].ty > 1 && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty-1 == TRIGGY))
182 if(player[pn].q<=player[pn].spt)
185 player[pn].y-=(player[pn].speed);
186 animatePlayer(pip, player, 0, pn);
187 if(!pageflipflop) modexShowPage(pip[1].page);
189 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
193 modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x-4, player[pn].y-TILEWH, player[pn].x-4, player[pn].y-TILEWH, 24, 32);
195 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 0, 24, 32, PLAYERBMPDATA);
197 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 12);
199 if(!pageflipflop) modexShowPage(pip[1].page);
202 player[pn].triggerx = player[pn].tx;
203 player[pn].triggery = player[pn].ty-1;
209 void panpagemanual(map_view_t *pip, player_t *player, word pn)
215 if(pip[pip[0].pan->pn].tx >= -1 && pip[pip[0].pan->pn].tx+pip[pip[0].pan->pn].page->tw < pip[pip[0].pan->pn].page->tilesw+1)
217 if(player[pn].q<=player[pn].spt)
219 pip[pip[0].pan->pn].page->dx+=4;
220 modexShowPage(pip[pip[0].pan->pn].page);
222 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
228 if(pip[pip[0].pan->pn].tx > -1 && pip[pip[0].pan->pn].tx+pip[pip[0].pan->pn].page->tilesw <= pip[pip[0].pan->pn].page->tilesw+1)
230 if(player[pn].q<=player[pn].spt)
232 pip[pip[0].pan->pn].page->dx-=4;
233 modexShowPage(pip[pip[0].pan->pn].page);
235 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
241 if(pip[pip[0].pan->pn].ty >= -1 && pip[pip[0].pan->pn].ty+pip[pip[0].pan->pn].page->tilesh < pip[pip[0].pan->pn].page->tilesh+1)
243 if(player[pn].q<=player[pn].spt)
245 pip[pip[0].pan->pn].page->dy+=4;
246 modexShowPage(pip[pip[0].pan->pn].page);
248 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
254 if(pip[pip[0].pan->pn].ty > -1 && pip[pip[0].pan->pn].ty+pip[pip[0].pan->pn].page->tilesh <= pip[pip[0].pan->pn].page->tilesh+1)
256 if(player[pn].q<=player[pn].spt)
258 pip[pip[0].pan->pn].page->dy-=4;
259 modexShowPage(pip[pip[0].pan->pn].page);
261 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
265 //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
269 allocMap(int w, int h) {
274 result.data = malloc(sizeof(byte) * w * h);
275 //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
276 if(isEMS() || checkEMS())
279 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
280 mm.length=sizeof(result);
282 mm.sourceOff=ptr2long(&result);
285 ist = move_emem(&mm);
286 if(!ist){ dealloc_emem(emmhandle); exit(5); }
287 printf("%d\n", coretotalEMS());
294 initMap(map_t *map) {
295 // just a place holder to fill out an alternating pattern
299 //if(!isEMS() || !checkEMS())
300 // map->tiles = malloc(sizeof(tiles_t));
302 // map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
304 //create the tile set
305 //if(!isEMS() || !checkEMS())
306 // map->tiles->data = malloc(sizeof(bitmap_t));
308 // map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
309 // map->tiles->data->width = (TILEWH);
310 // map->tiles->data->height= TILEWH;
311 //if(!isEMS() || !checkEMS())
312 // map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
314 // map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
315 // map->tiles->tileHeight = TILEWH;
316 // map->tiles->tileWidth =TILEWH;
317 // map->tiles->rows = 1;
318 // map->tiles->cols = 1;//2;
321 //for(y=0; y<map->height; y++) {
322 //for(x=0; x<map->width; x++) {
324 for(yy=0; yy<TILEWH; yy++) {
325 for(xx=0; xx<(TILEWH); xx++) {
327 map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
328 // printf("[%d]", map->tiles->data->data[i]);
330 //map->tiles->data->data[i] = map->data[q];//0;//0x34;
331 //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
337 // printf("[%d]", map->data[q]);
344 for(y=0; y<map->height; y++) {
345 for(x=0; x<map->width; x++) {
347 printf("[%d]", map->data[i]);
348 //tile = tile ? 0 : 1;
351 //tile = tile ? 0 : 1;
355 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
357 word x, y; /* coordinate for drawing */
359 /* increment the pixel position and update the page */
360 mv[id].page->dx += player[plid].speed;
362 /* check to see if this changes the tile */
363 if(mv[id].page->dx >= mv[id].dxThresh )
365 /* go forward one tile */
367 /* Snap the origin forward */
368 mv[id].page->data += 4;
369 mv[id].page->dx = mv[id].map->tiles->tileWidth;
372 /* draw the next column */
373 x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
376 mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
378 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
383 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
385 word x, y; /* coordinate for drawing */
387 /* decrement the pixel position and update the page */
388 mv[id].page->dx -= player[plid].speed;
390 /* check to see if this changes the tile */
391 if(mv[id].page->dx == 0)
393 /* go backward one tile */
396 /* Snap the origin backward */
397 mv[id].page->data -= 4;
398 mv[id].page->dx = mv[id].map->tiles->tileWidth;
401 /* draw the next column */
405 mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
407 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
412 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
414 word x, y; /* coordinate for drawing */
416 /* decrement the pixel position and update the page */
417 mv[id].page->dy -= player[plid].speed;
419 /* check to see if this changes the tile */
420 if(mv[id].page->dy == 0 )
422 /* go down one tile */
424 /* Snap the origin downward */
425 mv[id].page->data -= mv[id].page->width*4;
426 mv[id].page->dy = mv[id].map->tiles->tileHeight;
429 /* draw the next row */
433 mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
435 modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight);
439 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
441 word x, y; /* coordinate for drawing */
443 /* increment the pixel position and update the page */
444 mv[id].page->dy += player[plid].speed;
446 /* check to see if this changes the tile */
447 if(mv[id].page->dy >= mv[id].dyThresh )
449 /* go down one tile */
451 /* Snap the origin downward */
452 mv[id].page->data += mv[id].page->width*4;
453 mv[id].page->dy = mv[id].map->tiles->tileHeight;
456 /* draw the next row */
457 y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
460 mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
462 modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight);
467 //TODO finish this wwww
468 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
470 /* increment the pixel position and update the page */
471 mv[0].video->page[id].dx += player[plid].speed;
473 /* check to see if this changes the tile */
474 if(mv[0].video->page[id].dx >= mv[id].dxThresh )
476 /* Snap the origin forward */
477 mv[0].video->page[id].data += 4;
478 mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
483 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
485 /* decrement the pixel position and update the page */
486 mv[0].video->page[id].dx -= player[plid].speed;
488 /* check to see if this changes the tile */
489 if(mv[0].video->page[id].dx == 0)
491 /* Snap the origin backward */
492 mv[0].video->page[id].data -= 4;
493 mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
497 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
499 /* decrement the pixel position and update the page */
500 mv[0].video->page[id].dy -= player[plid].speed;
502 /* check to see if this changes the tile */
503 if(mv[0].video->page[id].dy == 0)
505 /* Snap the origin backward */
506 mv[0].video->page[id].data -= 4;
507 mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
511 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
513 /* increment the pixel position and update the page */
514 mv[0].video->page[id].dy += player[plid].speed;
516 /* check to see if this changes the tile */
517 if(mv[0].video->page[id].dy >= mv[id].dxThresh )
519 /* Snap the origin forward */
520 mv[0].video->page[id].data += 4;
521 mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
523 // modexClearRegion(&(mv[0].video->page[id]), 0, 0,
524 // mv[0].video->page[id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 1, 1, 1, 1, 1, 1, 1, \
540 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
541 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
542 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
543 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
544 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
545 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, \
546 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
547 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 2, 3, 4 };*/
548 //check for failed to load map
549 if((map->width == map->height == 0) && (q>0))
551 //initiate a null map!
552 map->width=MAPW;///2;
553 map->height=MAPH;///2;
554 // map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
556 map->tiles = malloc(sizeof(tiles_t));
557 //fix this to be far~
558 // bp = bitmapLoadPcx("data/ed.pcx");
559 // map->tiles->data = &bp;
560 map->tiles->debug_data = map->data;
561 map->tiles->tileHeight = 16;
562 map->tiles->tileWidth = 16;
563 map->tiles->rows = 1;
564 map->tiles->cols = 1;
565 map->tiles->debug_text = true;
567 else map->tiles->debug_text = false;
571 void mapGoTo(map_view_t *mv, int tx, int ty)
576 /* set up the coordinates */
579 mv->page->dx = mv->map->tiles->tileWidth;
580 mv->page->dy = mv->map->tiles->tileHeight;
582 /* set up the thresholds */
583 mv->dxThresh = mv->map->tiles->tileWidth * 2;
584 mv->dyThresh = mv->map->tiles->tileHeight * 2;
587 modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
589 i=mv->ty * mv->map->width + mv->tx;
590 for(ty=mv->ty-1; py < mv->page->sh+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
591 mapDrawWRow(mv, tx-1, ty, py);
592 i+=mv->map->width - tx;
598 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
608 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
612 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
613 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
614 ////0000printf("i=%d\n", i);
615 switch(t->debug_text)
619 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
620 //cannot print number value du to it being slow as bakapee
622 PBUFBFUN (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
623 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
624 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
625 //modexDrawBmpRegion (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
629 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i]+1));
630 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
631 /*for(texty=0; texty<2; texty++)
633 for(textx=0; textx<2; textx++)
635 // modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
643 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
647 poopoffset%=p[0].speed;
648 //printf("y: %d\n", poopoffset);
649 /* the position within the map array */
650 i=ty * mv->map->width + tx;
651 for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
653 /* we are in the map, so copy! */
654 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
660 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
664 poopoffset%=p[0].speed;
665 //printf("x: %d\n", poopoffset);
666 /* location in the map array */
667 i=ty * mv->map->width + tx;
669 /* We'll copy all of the columns in the screen,
670 i + 1 row above and one below */
671 for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
673 /* we are in the map, so copy away! */
674 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
680 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
685 /* the position within the map array */
686 i=ty * mv->map->width + tx;
687 for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
689 /* we are in the map, so copy! */
690 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
696 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
701 /* location in the map array */
702 i=ty * mv->map->width + tx;
704 /* We'll copy all of the columns in the screen,
705 i + 1 row above and one below */
706 for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
708 /* we are in the map, so copy away! */
709 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
720 unsigned char shinku_fps_indicator_page = 0;
721 boolean pageflipflop=0;
725 void shinku(global_game_variables_t *gv)
727 word x = (0) + gv->video.page[shinku_fps_indicator_page].dx; // follow the screen
728 word y = (0) + gv->video.page[shinku_fps_indicator_page].dy; // follow the screen
735 //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
736 /* block copy to visible RAM from offscreen */
737 // vga_setup_wm1_block_copy();
738 // modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x+w, 0, w, h);
739 // o = *(gv->video.page[2].data); // source offscreen
740 // o2 = *(gv->video.page[shinku_fps_indicator_page].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
741 // for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);
742 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
743 // vga_restore_rm0wm0();
744 if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
746 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
747 //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45);
748 modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y, type, col, bgcol, gv->pee);
750 /* block copy to visible RAM from offscreen */
751 // vga_setup_wm1_block_copy();
752 // o = *(gv->video.page[shinku_fps_indicator_page].data); // source offscreen
753 // o2 = *(gv->video.page[2].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
754 // for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);
755 // modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x, 0, w, h);
756 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
757 // vga_restore_rm0wm0();
758 }else //copy dat sheet
761 switch(gv->kurokku.fpscap)
764 modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
765 gv->kurokku.frames_per_second=1;
768 //turn this off if XT
770 //vga_wait_for_vsync();
771 gv->kurokku.frames_per_second=60;
775 modexCopyPageRegion(&(gv->video.page[gv->video.p]), &(gv->video.page[!gv->video.p]), 0, 0, 0, 0, gv->video.page[gv->video.p].width, gv->video.page[!gv->video.p].height);
776 modexShowPage(&(gv->video.page[gv->video.p]));
779 gv->video.p=!gv->video.p;
782 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
784 sword x = player[pn].x;
785 sword y = player[pn].y;
787 word dire=32; //direction
789 word dire=8; //direction
791 sword qq; //scroll offset
792 word ls = player[pn].persist_aniframe;
794 if(scrollswitch==0) qq = 0;
795 else qq = ((player[pn].q)*(player[pn].speed));
798 switch (player[pn].d)
807 dire*=(player[pn].d-2);
814 dire*=(player[pn].d-2);
819 dire*=(player[pn].d+2);
825 // #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32, PLAYERBMPDATA);
826 // #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
827 // #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 24, 32, PLAYERBMPDATA);
828 // #define FRAME4 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
829 #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32, PLAYERBMPDATA);
830 #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
831 #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 24, 32, PLAYERBMPDATA);
832 #define FRAME4 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
834 #define FRAME1 modexClearRegion(pip[1].page, x, y, 24, 32, 2+dire);
835 #define FRAME2 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
836 #define FRAME3 modexClearRegion(pip[1].page, x, y, 24, 32, dire);
837 #define FRAME4 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
840 modexCopyPageRegion(pip[pip->video->p].page,
841 pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 40);
842 else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
843 //modexCopyPageRegion(pip[2].page, pip[1].page, 16, 16, 16, 16, (14*8)+4, 8+4);
844 if(2>ls && ls>=1) { FRAME1 }else
845 if(3>ls && ls>=2) { FRAME2 }else
846 if(4>ls && ls>=3) { FRAME3 }else
847 if(5>ls && ls>=4) { FRAME4 }
848 //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
849 //modexClearRegion(top->page, 66, 66, 2, 40, 0);
850 //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);