]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
fack....
[16.git] / src / lib / scroll16.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
3  *
4  * This file is part of Project 16.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 /*
23         scroll16 library~
24 */
25 #include "src/lib/scroll16.h"
26
27 void walk(map_view_t *pip, player_t *player, word pn)
28 {
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);
31         switch(player[pn].d)
32         {
33                 //right movement
34                 case 3:
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!
38                         {
39                                 if(player[pn].q<=player[pn].spt)
40                                 {
41                                         INC_PER_FRAME;
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);
48                                         player[pn].q++;
49                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
50                         }
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))
52                         {
53                                 if(player[pn].q<=player[pn].spt)
54                                 {
55                                         INC_PER_FRAME;
56                                         player[pn].x+=(player[pn].speed);
57                                         animatePlayer(pip, player, pn, 0);
58                                         if(!pageflipflop) modexShowPage(pip[1].page);
59                                         player[pn].q++;
60                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
61                         }
62                         else
63                         {
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);
65 #ifdef SPRITE
66                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 24, 32, PLAYERBMPDATA);
67 #else
68                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 14);
69 #endif
70                                 if(!pageflipflop) modexShowPage(pip[1].page);
71                                 player[pn].d = 2;
72                         }
73                         player[pn].triggerx = player[pn].tx+1;
74                         player[pn].triggery = player[pn].ty;
75                 break;
76
77                 //left movement
78                 case 1:
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!
81                         {
82                                 if(player[pn].q<=player[pn].spt)
83                                 {
84                                         INC_PER_FRAME;
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);
91                                         player[pn].q++;
92                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
93                         }
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))
95                         {
96                                 if(player[pn].q<=player[pn].spt)
97                                 {
98                                         INC_PER_FRAME;
99                                         player[pn].x-=(player[pn].speed);
100                                         animatePlayer(pip, player, pn, 0);
101                                         if(!pageflipflop) modexShowPage(pip[1].page);
102                                         player[pn].q++;
103                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
104                         }
105                         else
106                         {
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);
108 #ifdef SPRITE
109                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 96, 24, 32, PLAYERBMPDATA);
110 #else
111                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 10);
112 #endif
113                                 if(!pageflipflop) modexShowPage(pip[1].page);
114                                 player[pn].d = 2;
115                         }
116                         player[pn].triggerx = player[pn].tx-1;
117                         player[pn].triggery = player[pn].ty;
118                 break;
119
120                 //down movement
121                 case 4:
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!
124                         {
125                                 if(player[pn].q<=player[pn].spt)
126                                 {
127                                         INC_PER_FRAME;
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);
134                                         player[pn].q++;
135                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
136                         }
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))
138                         {
139                                 if(player[pn].q<=player[pn].spt)
140                                 {
141                                         INC_PER_FRAME;
142                                         player[pn].y+=(player[pn].speed);
143                                         animatePlayer(pip, player, pn, 0);
144                                         if(!pageflipflop) modexShowPage(pip[1].page);
145                                         player[pn].q++;
146                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
147                         }
148                         else
149                         {
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);
151 #ifdef SPRITE
152                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 64, 24, 32, PLAYERBMPDATA);
153 #else
154                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 9);
155 #endif
156                                 if(!pageflipflop) modexShowPage(pip[1].page);
157                                 player[pn].d = 2;
158                         }
159                         player[pn].triggerx = player[pn].tx;
160                         player[pn].triggery = player[pn].ty+1;
161                 break;
162
163                 //up movement
164                 case 0:
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!
167                         {
168                                 if(player[pn].q<=player[pn].spt)
169                                 {
170                                         INC_PER_FRAME;
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);
177                                         player[pn].q++;
178                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
179                         }
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))
181                         {
182                                 if(player[pn].q<=player[pn].spt)
183                                 {
184                                         INC_PER_FRAME;
185                                         player[pn].y-=(player[pn].speed);
186                                         animatePlayer(pip, player, 0, pn);
187                                         if(!pageflipflop) modexShowPage(pip[1].page);
188                                         player[pn].q++;
189                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
190                         }
191                         else
192                         {
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);
194 #ifdef SPRITE
195                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 0, 24, 32, PLAYERBMPDATA);
196 #else
197                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 12);
198 #endif
199                                 if(!pageflipflop) modexShowPage(pip[1].page);
200                                 player[pn].d = 2;
201                         }
202                         player[pn].triggerx = player[pn].tx;
203                         player[pn].triggery = player[pn].ty-1;
204                 break;
205         }
206 }
207
208 //panning page
209 void panpagemanual(map_view_t *pip, player_t *player, word pn)
210 {
211         switch(player[pn].d)
212         {
213                 //right movement
214                 case 3:
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)
216                         {
217                                 if(player[pn].q<=player[pn].spt)
218                                 {
219                                         pip[pip[0].pan->pn].page->dx+=4;
220                                         modexShowPage(pip[pip[0].pan->pn].page);
221                                         player[pn].q++;
222                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
223                         }
224                 break;
225
226                 //left movement
227                 case 1:
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)
229                         {
230                                 if(player[pn].q<=player[pn].spt)
231                                 {
232                                         pip[pip[0].pan->pn].page->dx-=4;
233                                         modexShowPage(pip[pip[0].pan->pn].page);
234                                         player[pn].q++;
235                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
236                         }
237                 break;
238
239                 //down movement
240                 case 4:
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)
242                         {
243                                 if(player[pn].q<=player[pn].spt)
244                                 {
245                                         pip[pip[0].pan->pn].page->dy+=4;
246                                         modexShowPage(pip[pip[0].pan->pn].page);
247                                         player[pn].q++;
248                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
249                         }
250                 break;
251
252                 //up movement
253                 case 0:
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)
255                         {
256                                 if(player[pn].q<=player[pn].spt)
257                                 {
258                                         pip[pip[0].pan->pn].page->dy-=4;
259                                         modexShowPage(pip[pip[0].pan->pn].page);
260                                         player[pn].q++;
261                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
262                         }
263                         break;
264         }
265         //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
266 }
267
268 /*map_t
269 allocMap(int w, int h) {
270         map_t result;
271
272         result.width =w;
273         result.height=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())
277         {
278                 XMOVE mm;
279                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
280                 mm.length=sizeof(result);
281                 mm.sourceH=0;
282                 mm.sourceOff=ptr2long(&result);
283                 mm.destH=emmhandle;
284                 mm.destOff=0;
285                 ist = move_emem(&mm);
286                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
287                 printf("%d\n", coretotalEMS());
288         }
289
290         return result;
291 }*/
292
293 /*void
294 initMap(map_t *map) {
295         // just a place holder to fill out an alternating pattern
296         int x, y, xx, yy;
297         int i, q;
298 //      int tile = 1;
299         //if(!isEMS() || !checkEMS())
300 //              map->tiles = malloc(sizeof(tiles_t));
301         //else
302         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
303
304          //create the tile set
305         //if(!isEMS() || !checkEMS())
306 //              map->tiles->data = malloc(sizeof(bitmap_t));
307         //else
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);
313         //else
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;
319
320         q=0;
321         //for(y=0; y<map->height; y++) {
322         //for(x=0; x<map->width; x++) {
323         i=0;
324         for(yy=0; yy<TILEWH; yy++) {
325         for(xx=0; xx<(TILEWH); xx++) {
326                 //if(x<TILEWH){
327                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
328 //                printf("[%d]", map->tiles->data->data[i]);
329                 //}else{
330                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
331                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
332                 //}
333                 i++;
334         }
335 //      printf("\n");
336         }
337 //      printf("[%d]", map->data[q]);
338         q++;
339 //      }
340         //printf("\n\n");
341 //      }
342
343         i=0;
344         for(y=0; y<map->height; y++) {
345                 for(x=0; x<map->width; x++) {
346 //                      map->data[i]=255;
347                         printf("[%d]", map->data[i]);
348                         //tile = tile ? 0 : 1;
349                         i++;
350                 }
351                 //tile = tile ? 0 : 1;
352         }
353 }*/
354
355 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
356 {
357         word x, y;  /* coordinate for drawing */
358
359         /* increment the pixel position and update the page */
360         mv[id].page->dx += player[plid].speed;
361
362         /* check to see if this changes the tile */
363         if(mv[id].page->dx >= mv[id].dxThresh )
364         {
365         /* go forward one tile */
366         mv[id].tx++;
367         /* Snap the origin forward */
368         mv[id].page->data += 4;
369         mv[id].page->dx = mv[id].map->tiles->tileWidth;
370         }
371
372         /* draw the next column */
373         x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
374         if(player[plid].q%4)
375                 if(id==0)
376                         mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
377                 else
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));
379         //}
380 }
381
382
383 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
384 {
385         word x, y;  /* coordinate for drawing */
386
387         /* decrement the pixel position and update the page */
388         mv[id].page->dx -= player[plid].speed;
389
390         /* check to see if this changes the tile */
391         if(mv[id].page->dx == 0)
392         {
393         /* go backward one tile */
394         mv[id].tx--;
395
396         /* Snap the origin backward */
397         mv[id].page->data -= 4;
398         mv[id].page->dx = mv[id].map->tiles->tileWidth;
399         }
400
401         /* draw the next column */
402         x= 0;
403         if(player[plid].q%4)
404                 if(id==0)
405                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
406                 else
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));
408         //}
409 }
410
411
412 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
413 {
414         word x, y;  /* coordinate for drawing */
415
416         /* decrement the pixel position and update the page */
417         mv[id].page->dy -= player[plid].speed;
418
419         /* check to see if this changes the tile */
420         if(mv[id].page->dy == 0 )
421         {
422         /* go down one tile */
423         mv[id].ty--;
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;
427         }
428
429         /* draw the next row */
430         y= 0;
431         if(player[plid].q%3)
432                 if(id==0)
433                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
434                 else
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);
436         //}
437 }
438
439 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
440 {
441         word x, y;  /* coordinate for drawing */
442
443         /* increment the pixel position and update the page */
444         mv[id].page->dy += player[plid].speed;
445
446         /* check to see if this changes the tile */
447         if(mv[id].page->dy >= mv[id].dyThresh )
448         {
449         /* go down one tile */
450         mv[id].ty++;
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;
454         }
455
456         /* draw the next row */
457         y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
458         if(player[plid].q%3)
459                 if(id==0)
460                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
461                 else
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);
463         //}
464 }
465
466
467 //TODO finish this wwww
468 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
469 {
470         /* increment the pixel position and update the page */
471         mv[0].video->page[id].dx += player[plid].speed;
472
473         /* check to see if this changes the tile */
474         if(mv[0].video->page[id].dx >= mv[id].dxThresh )
475         {
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;
479         }
480 }
481
482
483 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
484 {
485         /* decrement the pixel position and update the page */
486         mv[0].video->page[id].dx -= player[plid].speed;
487
488         /* check to see if this changes the tile */
489         if(mv[0].video->page[id].dx == 0)
490         {
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;
494         }
495 }
496
497 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
498 {
499         /* decrement the pixel position and update the page */
500         mv[0].video->page[id].dy -= player[plid].speed;
501
502         /* check to see if this changes the tile */
503         if(mv[0].video->page[id].dy == 0)
504         {
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;
508         }
509 }
510
511 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
512 {
513         /* increment the pixel position and update the page */
514         mv[0].video->page[id].dy += player[plid].speed;
515
516         /* check to see if this changes the tile */
517         if(mv[0].video->page[id].dy >= mv[id].dxThresh )
518         {
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;
522         }
523 //      modexClearRegion(&(mv[0].video->page[id]), 0, 0,
524 //                       mv[0].video->page[id].width-1,
525 //                mv[0].video->page[id].height-1, id*2);
526 }
527
528 sword chkmap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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10 };
533 /*1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      1,      1,      1,      1,      1,      1,      \
534 5,      6,      7,      8,      0,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
535 9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
536 13,     14,     15,     16,     0,      1,      1,      1,      5,      8,      1,      11,     11,     1,      1,      1,      1,      1,      1,      1,      \
537 0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      \
538 1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
539 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      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))
550         {
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));
555                 map->data = &x;
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;
566         }
567         else map->tiles->debug_text = false;
568         return 0;
569 }
570
571 void mapGoTo(map_view_t *mv, int tx, int ty)
572 {
573         int px, py;
574         unsigned int i;
575
576         /* set up the coordinates */
577         mv->tx = tx;
578         mv->ty = ty;
579         mv->page->dx = mv->map->tiles->tileWidth;
580         mv->page->dy = mv->map->tiles->tileHeight;
581
582         /* set up the thresholds */
583         mv->dxThresh = mv->map->tiles->tileWidth * 2;
584         mv->dyThresh = mv->map->tiles->tileHeight * 2;
585
586         /* draw the tiles */
587         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
588         py=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;
593         }
594 }
595
596
597 void near
598 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
599 {
600         word rx;
601         word ry;
602         word textx=0;
603         word texty=0;
604         //if(i==0) i=2;
605         if(i==0)
606         {
607                 //wwww
608                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
609         }
610         else
611         {
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)
616                 {
617                         case 0:
618 #ifndef TILERENDER
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
621 #else
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));
626 #endif
627                         break;
628                         case 1:
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++)
632                                 {
633                                         for(textx=0; textx<2; textx++)
634                                         {*/
635 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
636 /*                                      }
637                                 }*/
638                         break;
639                 }
640         }
641 }
642
643 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
644 {
645         word x;
646         int i;
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++) {
652         if(i>=0) {
653                 /* we are in the map, so copy! */
654                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
655         }
656         i++; /* next! */
657         }
658 }
659
660 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
661 {
662         int y;
663         int i;
664         poopoffset%=p[0].speed;
665 //printf("x: %d\n", poopoffset);
666         /* location in the map array */
667         i=ty * mv->map->width + tx;
668
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++) {
672         if(i>=0) {
673                 /* we are in the map, so copy away! */
674                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
675         }
676         i += mv->map->width;
677         }
678 }
679
680 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
681 {
682         word x;
683         int i;
684
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++) {
688         if(i>=0) {
689                 /* we are in the map, so copy! */
690                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
691         }
692         i++; /* next! */
693         }
694 }
695
696 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
697 {
698         int y;
699         int i;
700
701         /* location in the map array */
702         i=ty * mv->map->width + tx;
703
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++) {
707         if(i>=0) {
708                 /* we are in the map, so copy away! */
709                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
710         }
711         i += mv->map->width;
712         }
713 }
714
715 /*void qclean()
716 {
717         //setkb(0);
718 }*/
719
720 unsigned char shinku_fps_indicator_page = 0;
721 boolean pageflipflop=0;
722 //gv->video.p
723
724 /*      sync    */
725 void shinku(global_game_variables_t *gv)
726 {
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
729         word w = 64;
730         word h = 8;
731         word col = 7;
732         word bgcol = 0;
733         word type = 1;
734         byte o,o2,i;
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))
745         {
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);
749                 gv->kurokku.tiku=0;
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
759         gv->kurokku.tiku++;
760
761         switch(gv->kurokku.fpscap)
762         {
763                 case 0:
764                         modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
765                         gv->kurokku.frames_per_second=1;
766                 break;
767                 case 1:
768                         //turn this off if XT
769                         modexWaitBorder();
770                         //vga_wait_for_vsync();
771                         gv->kurokku.frames_per_second=60;
772                 break;
773         }
774         if(pageflipflop){
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]));
777
778         }
779         gv->video.p=!gv->video.p;
780 }
781
782 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
783 {
784         sword x = player[pn].x;
785         sword y = player[pn].y;
786 #ifdef SPRITE
787         word dire=32; //direction
788 #else
789         word dire=8; //direction
790 #endif
791         sword qq; //scroll offset
792         word ls = player[pn].persist_aniframe;
793
794         if(scrollswitch==0) qq = 0;
795         else qq = ((player[pn].q)*(player[pn].speed));
796         x-=4;
797         y-=TILEWH;
798         switch (player[pn].d)
799         {
800                 case 0:
801                         //up
802                         dire*=player[pn].d;
803                         y-=qq;
804                 break;
805                 case 3:
806                         // right
807                         dire*=(player[pn].d-2);
808                         x+=qq;
809                 break;
810                 case 2:
811                 break;
812                 case 4:
813                         //down
814                         dire*=(player[pn].d-2);
815                         y+=qq;
816                 break;
817                 case 1:
818                         //left
819                         dire*=(player[pn].d+2);
820                         x-=qq;
821                 break;
822         }
823
824 #ifdef SPRITE
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);
833 #else
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);
838         #endif
839         if(pageflipflop)
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);
851 }