]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
panning updated and stuff wwww
[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         switch(player[pn].d)
31         {
32                 //right movement
33                 case 3:
34                         //printf("pip[0].page->tilesw=%d\n", pip[0].page->tilesw);
35                         if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->tilesw < pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
36                         !(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!
37                         {
38                                 if(player[pn].q<=player[pn].spt)
39                                 {
40                                         INC_PER_FRAME;
41                                         animatePlayer(pip, player, pn, 1);
42                                         mapScrollRight(pip, player, 0, pn);
43                                         mapScrollRight(pip, player, 1, pn);
44                                         ScrollRight(pip, player, 2, pn);
45                                         ScrollRight(pip, player, 3, pn);
46                                         if(!pageflipflop) modexShowPage(pip[1].page);
47                                         player[pn].q++;
48                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
49                         }
50                         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))
51                         {
52                                 if(player[pn].q<=player[pn].spt)
53                                 {
54                                         INC_PER_FRAME;
55                                         player[pn].x+=(player[pn].speed);
56                                         animatePlayer(pip, player, pn, 0);
57                                         if(!pageflipflop) modexShowPage(pip[1].page);
58                                         player[pn].q++;
59                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
60                         }
61                         else
62                         {
63                                 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);
64 #ifdef SPRITE
65                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 24, 32, PLAYERBMPDATA);
66 #else
67                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 14);
68 #endif
69                                 if(!pageflipflop) modexShowPage(pip[1].page);
70                                 player[pn].d = 2;
71                         }
72                         player[pn].triggerx = player[pn].tx+1;
73                         player[pn].triggery = player[pn].ty;
74                 break;
75
76                 //left movement
77                 case 1:
78                         if(pip[0].tx > 0 && pip[0].tx+pip[0].page->tilesw <= pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
79                         !(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!
80                         {
81                                 if(player[pn].q<=player[pn].spt)
82                                 {
83                                         INC_PER_FRAME;
84                                         animatePlayer(pip, player, pn, 1);
85                                         mapScrollLeft(pip, player, 0, pn);
86                                         mapScrollLeft(pip, player, 1, pn);
87                                         ScrollLeft(pip, player, 2, pn);
88                                         ScrollLeft(pip, player, 3, pn);
89                                         if(!pageflipflop) modexShowPage(pip[1].page);
90                                         player[pn].q++;
91                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
92                         }
93                         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))
94                         {
95                                 if(player[pn].q<=player[pn].spt)
96                                 {
97                                         INC_PER_FRAME;
98                                         player[pn].x-=(player[pn].speed);
99                                         animatePlayer(pip, player, pn, 0);
100                                         if(!pageflipflop) modexShowPage(pip[1].page);
101                                         player[pn].q++;
102                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
103                         }
104                         else
105                         {
106                                 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);
107 #ifdef SPRITE
108                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 96, 24, 32, PLAYERBMPDATA);
109 #else
110                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 10);
111 #endif
112                                 if(!pageflipflop) modexShowPage(pip[1].page);
113                                 player[pn].d = 2;
114                         }
115                         player[pn].triggerx = player[pn].tx-1;
116                         player[pn].triggery = player[pn].ty;
117                 break;
118
119                 //down movement
120                 case 4:
121                         if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->tilesh < pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
122                         !(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!
123                         {
124                                 if(player[pn].q<=player[pn].spt)
125                                 {
126                                         INC_PER_FRAME;
127                                         animatePlayer(pip, player, pn, 1);
128                                         mapScrollDown(pip, player, 0, pn);
129                                         mapScrollDown(pip, player, 1, pn);
130                                         ScrollDown(pip, player, 2, pn);
131                                         ScrollDown(pip, player, 3, pn);
132                                         if(!pageflipflop) modexShowPage(pip[1].page);
133                                         player[pn].q++;
134                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
135                         }
136                         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))
137                         {
138                                 if(player[pn].q<=player[pn].spt)
139                                 {
140                                         INC_PER_FRAME;
141                                         player[pn].y+=(player[pn].speed);
142                                         animatePlayer(pip, player, pn, 0);
143                                         if(!pageflipflop) modexShowPage(pip[1].page);
144                                         player[pn].q++;
145                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
146                         }
147                         else
148                         {
149                                 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);
150 #ifdef SPRITE
151                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 64, 24, 32, PLAYERBMPDATA);
152 #else
153                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 9);
154 #endif
155                                 if(!pageflipflop) modexShowPage(pip[1].page);
156                                 player[pn].d = 2;
157                         }
158                         player[pn].triggerx = player[pn].tx;
159                         player[pn].triggery = player[pn].ty+1;
160                 break;
161
162                 //up movement
163                 case 0:
164                         if(pip[0].ty > 0 && pip[0].ty+pip[0].page->tilesh <= pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
165                         !(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!
166                         {
167                                 if(player[pn].q<=player[pn].spt)
168                                 {
169                                         INC_PER_FRAME;
170                                         animatePlayer(pip, player, pn, 1);
171                                         mapScrollUp(pip, player, 0, pn);
172                                         mapScrollUp(pip, player, 1, pn);
173                                         ScrollUp(pip, player, 2, pn);
174                                         ScrollUp(pip, player, 3, pn);
175                                         if(!pageflipflop) modexShowPage(pip[1].page);
176                                         player[pn].q++;
177                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
178                         }
179                         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))
180                         {
181                                 if(player[pn].q<=player[pn].spt)
182                                 {
183                                         INC_PER_FRAME;
184                                         player[pn].y-=(player[pn].speed);
185                                         animatePlayer(pip, player, 0, pn);
186                                         if(!pageflipflop) modexShowPage(pip[1].page);
187                                         player[pn].q++;
188                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
189                         }
190                         else
191                         {
192                                 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);
193 #ifdef SPRITE
194                                 PBUFSFUN(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 0, 24, 32, PLAYERBMPDATA);
195 #else
196                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 12);
197 #endif
198                                 if(!pageflipflop) modexShowPage(pip[1].page);
199                                 player[pn].d = 2;
200                         }
201                         player[pn].triggerx = player[pn].tx;
202                         player[pn].triggery = player[pn].ty-1;
203                 break;
204         }
205 }
206
207 //panning page
208 void panpagemanual(map_view_t *pip, player_t *player, word pn)
209 {
210         switch(player[pn].d)
211         {
212                 //right movement
213                 case 3:
214                         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)
215                         {
216                                 if(player[pn].q<=player[pn].spt)
217                                 {
218                                         pip[pip[0].pan->pn].page->dx+=4;
219                                         modexShowPage(pip[pip[0].pan->pn].page);
220                                         player[pn].q++;
221                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
222                         }
223                 break;
224
225                 //left movement
226                 case 1:
227                         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)
228                         {
229                                 if(player[pn].q<=player[pn].spt)
230                                 {
231                                         pip[pip[0].pan->pn].page->dx-=4;
232                                         modexShowPage(pip[pip[0].pan->pn].page);
233                                         player[pn].q++;
234                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
235                         }
236                 break;
237
238                 //down movement
239                 case 4:
240                         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)
241                         {
242                                 if(player[pn].q<=player[pn].spt)
243                                 {
244                                         pip[pip[0].pan->pn].page->dy+=4;
245                                         modexShowPage(pip[pip[0].pan->pn].page);
246                                         player[pn].q++;
247                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
248                         }
249                 break;
250
251                 //up movement
252                 case 0:
253                         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)
254                         {
255                                 if(player[pn].q<=player[pn].spt)
256                                 {
257                                         pip[pip[0].pan->pn].page->dy-=4;
258                                         modexShowPage(pip[pip[0].pan->pn].page);
259                                         player[pn].q++;
260                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
261                         }
262                         break;
263         }
264         //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
265 }
266
267 /*map_t
268 allocMap(int w, int h) {
269         map_t result;
270
271         result.width =w;
272         result.height=h;
273         result.data = malloc(sizeof(byte) * w * h);
274         //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
275         if(isEMS() || checkEMS())
276         {
277                 XMOVE mm;
278                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
279                 mm.length=sizeof(result);
280                 mm.sourceH=0;
281                 mm.sourceOff=ptr2long(&result);
282                 mm.destH=emmhandle;
283                 mm.destOff=0;
284                 ist = move_emem(&mm);
285                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
286                 printf("%d\n", coretotalEMS());
287         }
288
289         return result;
290 }*/
291
292 /*void
293 initMap(map_t *map) {
294         // just a place holder to fill out an alternating pattern
295         int x, y, xx, yy;
296         int i, q;
297 //      int tile = 1;
298         //if(!isEMS() || !checkEMS())
299 //              map->tiles = malloc(sizeof(tiles_t));
300         //else
301         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
302
303          //create the tile set
304         //if(!isEMS() || !checkEMS())
305 //              map->tiles->data = malloc(sizeof(bitmap_t));
306         //else
307         //      map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
308 //      map->tiles->data->width = (TILEWH);
309 //      map->tiles->data->height= TILEWH;
310         //if(!isEMS() || !checkEMS())
311 //              map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
312         //else
313         //      map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
314 //      map->tiles->tileHeight = TILEWH;
315 //      map->tiles->tileWidth =TILEWH;
316 //      map->tiles->rows = 1;
317 //      map->tiles->cols = 1;//2;
318
319         q=0;
320         //for(y=0; y<map->height; y++) {
321         //for(x=0; x<map->width; x++) {
322         i=0;
323         for(yy=0; yy<TILEWH; yy++) {
324         for(xx=0; xx<(TILEWH); xx++) {
325                 //if(x<TILEWH){
326                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
327 //                printf("[%d]", map->tiles->data->data[i]);
328                 //}else{
329                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
330                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
331                 //}
332                 i++;
333         }
334 //      printf("\n");
335         }
336 //      printf("[%d]", map->data[q]);
337         q++;
338 //      }
339         //printf("\n\n");
340 //      }
341
342         i=0;
343         for(y=0; y<map->height; y++) {
344                 for(x=0; x<map->width; x++) {
345 //                      map->data[i]=255;
346                         printf("[%d]", map->data[i]);
347                         //tile = tile ? 0 : 1;
348                         i++;
349                 }
350                 //tile = tile ? 0 : 1;
351         }
352 }*/
353
354 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
355 {
356         word x, y;  /* coordinate for drawing */
357
358         /* increment the pixel position and update the page */
359         mv[id].page->dx += player[plid].speed;
360
361         /* check to see if this changes the tile */
362         if(mv[id].page->dx >= mv[id].dxThresh )
363         {
364         /* go forward one tile */
365         mv[id].tx++;
366         /* Snap the origin forward */
367         mv[id].page->data += 4;
368         mv[id].page->dx = mv[id].map->tiles->tileWidth;
369         }
370
371         /* draw the next column */
372         x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
373         if(player[plid].q%4)
374                 if(id==0)
375                         mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tilesw, mv[0].ty-1, x, player, mv->page->dx);
376                 else
377                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->tilesh+2));
378         //}
379 }
380
381
382 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
383 {
384         word x, y;  /* coordinate for drawing */
385
386         /* decrement the pixel position and update the page */
387         mv[id].page->dx -= player[plid].speed;
388
389         /* check to see if this changes the tile */
390         if(mv[id].page->dx == 0)
391         {
392         /* go backward one tile */
393         mv[id].tx--;
394
395         /* Snap the origin backward */
396         mv[id].page->data -= 4;
397         mv[id].page->dx = mv[id].map->tiles->tileWidth;
398         }
399
400         /* draw the next column */
401         x= 0;
402         if(player[plid].q%4)
403                 if(id==0)
404                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
405                 else
406                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->tilesh+2));
407         //}
408 }
409
410
411 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
412 {
413         word x, y;  /* coordinate for drawing */
414
415         /* decrement the pixel position and update the page */
416         mv[id].page->dy -= player[plid].speed;
417
418         /* check to see if this changes the tile */
419         if(mv[id].page->dy == 0 )
420         {
421         /* go down one tile */
422         mv[id].ty--;
423         /* Snap the origin downward */
424         mv[id].page->data -= mv[id].page->width*4;
425         mv[id].page->dy = mv[id].map->tiles->tileHeight;
426         }
427
428         /* draw the next row */
429         y= 0;
430         if(player[plid].q%3)
431                 if(id==0)
432                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
433                 else
434                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tilesw+2), mv[id].map->tiles->tileHeight);
435         //}
436 }
437
438 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
439 {
440         word x, y;  /* coordinate for drawing */
441
442         /* increment the pixel position and update the page */
443         mv[id].page->dy += player[plid].speed;
444
445         /* check to see if this changes the tile */
446         if(mv[id].page->dy >= mv[id].dyThresh )
447         {
448         /* go down one tile */
449         mv[id].ty++;
450         /* Snap the origin downward */
451         mv[id].page->data += mv[id].page->width*4;
452         mv[id].page->dy = mv[id].map->tiles->tileHeight;
453         }
454
455         /* draw the next row */
456         y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
457         if(player[plid].q%3)
458                 if(id==0)
459                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->tilesh, y, player, mv->page->dy);
460                 else
461                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tilesw+2), mv[id].map->tiles->tileHeight);
462         //}
463 }
464
465
466 //TODO finish this wwww
467 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
468 {
469         /* increment the pixel position and update the page */
470         mv[0].video->page[id].dx += player[plid].speed;
471
472         /* check to see if this changes the tile */
473         if(mv[0].video->page[id].dx >= mv[id].dxThresh )
474         {
475                 /* Snap the origin forward */
476                 mv[0].video->page[id].data += 4;
477                 mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
478         }
479 }
480
481
482 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
483 {
484         /* decrement the pixel position and update the page */
485         mv[0].video->page[id].dx -= player[plid].speed;
486
487         /* check to see if this changes the tile */
488         if(mv[0].video->page[id].dx == 0)
489         {
490                 /* Snap the origin backward */
491                 mv[0].video->page[id].data -= 4;
492                 mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
493         }
494 }
495
496 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
497 {
498         /* decrement the pixel position and update the page */
499         mv[0].video->page[id].dy -= player[plid].speed;
500
501         /* check to see if this changes the tile */
502         if(mv[0].video->page[id].dy == 0)
503         {
504                 /* Snap the origin backward */
505                 mv[0].video->page[id].data -= 4;
506                 mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
507         }
508 }
509
510 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
511 {
512         /* increment the pixel position and update the page */
513         mv[0].video->page[id].dy += player[plid].speed;
514
515         /* check to see if this changes the tile */
516         if(mv[0].video->page[id].dy >= mv[id].dxThresh )
517         {
518                 /* Snap the origin forward */
519                 mv[0].video->page[id].data += 4;
520                 mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
521         }
522 //      modexClearRegion(&(mv[0].video->page[id]), 0, 0,
523 //                       mv[0].video->page[id].width-1,
524 //                mv[0].video->page[id].height-1, id*2);
525 }
526
527 sword chkmap(map_t *map, word q)
528 {
529 //      bitm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 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 };
532 /*1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      1,      1,      1,      1,      1,      1,      \
533 5,      6,      7,      8,      0,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
534 9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
535 13,     14,     15,     16,     0,      1,      1,      1,      5,      8,      1,      11,     11,     1,      1,      1,      1,      1,      1,      1,      \
536 0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      \
537 1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
538 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      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,      3,      1,      1,      1,      \
540 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      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,      3,      1,      1,      1,      \
543 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
544 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
545 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
546 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      3,      3,      3,      1,      2,      3,      4 };*/
547         //check for failed to load map
548         if((map->width == map->height == 0) && (q>0))
549         {
550                 //initiate a null map!
551                 map->width=MAPW;///2;
552                 map->height=MAPH;///2;
553 //              map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
554                 map->data = &x;
555                 map->tiles = malloc(sizeof(tiles_t));
556                 //fix this to be far~
557 //              bp = bitmapLoadPcx("data/ed.pcx");
558 //              map->tiles->data = &bp;
559                 map->tiles->debug_data = map->data;
560                 map->tiles->tileHeight = 16;
561                 map->tiles->tileWidth = 16;
562                 map->tiles->rows = 1;
563                 map->tiles->cols = 1;
564                 map->tiles->debug_text = true;
565         }
566         else map->tiles->debug_text = false;
567         return 0;
568 }
569
570 void mapGoTo(map_view_t *mv, int tx, int ty)
571 {
572         int px, py;
573         unsigned int i;
574
575         /* set up the coordinates */
576         mv->tx = tx;
577         mv->ty = ty;
578         mv->page->dx = mv->map->tiles->tileWidth;
579         mv->page->dy = mv->map->tiles->tileHeight;
580
581         /* set up the thresholds */
582         mv->dxThresh = mv->map->tiles->tileWidth * 2;
583         mv->dyThresh = mv->map->tiles->tileHeight * 2;
584
585         /* draw the tiles */
586         modexClearRegion(mv->page, 0, 0, mv->page->width+mv->map->tiles->tileWidth, mv->page->height+mv->map->tiles->tileHeight, 0);
587         py=0;
588         i=mv->ty * mv->map->width + mv->tx;
589         for(ty=mv->ty-1; py < mv->page->sh+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
590                 mapDrawWRow(mv, tx-1, ty, py);
591         i+=mv->map->width - tx;
592         }
593 }
594
595
596 void near
597 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
598 {
599         word rx;
600         word ry;
601         word textx=0;
602         word texty=0;
603         //if(i==0) i=2;
604         if(i==0)
605         {
606                 //wwww
607                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
608         }
609         else
610         {
611                 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
612                 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
613 ////0000printf("i=%d\n", i);
614                 switch(t->debug_text)
615                 {
616                         case 0:
617 #ifndef TILERENDER
618                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
619                                 //cannot print number value du to it being slow as bakapee
620 #else
621                                 PBUFBFUN                (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
622                                 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
623                                 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
624                                 //modexDrawBmpRegion    (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
625 #endif
626                         break;
627                         case 1:
628                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i]+1));
629                                 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
630                                 /*for(texty=0; texty<2; texty++)
631                                 {
632                                         for(textx=0; textx<2; textx++)
633                                         {*/
634 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
635 /*                                      }
636                                 }*/
637                         break;
638                 }
639         }
640 }
641
642 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
643 {
644         word x;
645         int i;
646         poopoffset%=p[0].speed;
647 //printf("y: %d\n", poopoffset);
648         /* the position within the map array */
649         i=ty * mv->map->width + tx;
650         for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
651         if(i>=0) {
652                 /* we are in the map, so copy! */
653                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
654         }
655         i++; /* next! */
656         }
657 }
658
659 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
660 {
661         int y;
662         int i;
663         poopoffset%=p[0].speed;
664 //printf("x: %d\n", poopoffset);
665         /* location in the map array */
666         i=ty * mv->map->width + tx;
667
668         /* We'll copy all of the columns in the screen,
669            i + 1 row above and one below */
670         for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
671         if(i>=0) {
672                 /* we are in the map, so copy away! */
673                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
674         }
675         i += mv->map->width;
676         }
677 }
678
679 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
680 {
681         word x;
682         int i;
683
684         /* the position within the map array */
685         i=ty * mv->map->width + tx;
686         for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
687         if(i>=0) {
688                 /* we are in the map, so copy! */
689                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
690         }
691         i++; /* next! */
692         }
693 }
694
695 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
696 {
697         int y;
698         int i;
699
700         /* location in the map array */
701         i=ty * mv->map->width + tx;
702
703         /* We'll copy all of the columns in the screen,
704            i + 1 row above and one below */
705         for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
706         if(i>=0) {
707                 /* we are in the map, so copy away! */
708                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
709         }
710         i += mv->map->width;
711         }
712 }
713
714 /*void qclean()
715 {
716         //setkb(0);
717 }*/
718
719 unsigned char shinku_fps_indicator_page = 0;
720 boolean pageflipflop;
721 //gv->video.p
722
723 /*      sync    */
724 void shinku(global_game_variables_t *gv)
725 {
726         word x = (0) + gv->video.page[shinku_fps_indicator_page].dx; // follow the screen
727         word y = (0) + gv->video.page[shinku_fps_indicator_page].dy; // follow the screen
728         word w = 64;
729         word h = 8;
730         word col = 7;
731         word bgcol = 0;
732         word type = 1;
733         byte o,o2,i;
734         //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
735         /* block copy to visible RAM from offscreen */
736 //      vga_setup_wm1_block_copy();
737 //      modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x+w, 0, w, h);
738 //      o =     *(gv->video.page[2].data); // source offscreen
739 //      o2 =    *(gv->video.page[shinku_fps_indicator_page].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
740 //      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);
741         /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
742 //      vga_restore_rm0wm0();
743         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
744         {
745                 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
746                 //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45);
747                 modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y, type, col, bgcol, gv->pee);
748                 gv->kurokku.tiku=0;
749                 /* block copy to visible RAM from offscreen */
750 //              vga_setup_wm1_block_copy();
751 //              o =     *(gv->video.page[shinku_fps_indicator_page].data); // source offscreen
752 //              o2 =    *(gv->video.page[2].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
753 //              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);
754 //              modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x, 0, w, h);
755                 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
756 //              vga_restore_rm0wm0();
757         }else //copy dat sheet
758         gv->kurokku.tiku++;
759
760         switch(gv->kurokku.fpscap)
761         {
762                 case 0:
763                         modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
764                         gv->kurokku.frames_per_second=1;
765                 break;
766                 case 1:
767                         //turn this off if XT
768                         modexWaitBorder();
769                         //vga_wait_for_vsync();
770                         gv->kurokku.frames_per_second=60;
771                 break;
772         }
773         if(pageflipflop){
774                 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);
775                 modexShowPage(&(gv->video.page[gv->video.p]));
776
777         }
778         gv->video.p=!gv->video.p;
779 }
780
781 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
782 {
783         sword x = player[pn].x;
784         sword y = player[pn].y;
785 #ifdef SPRITE
786         word dire=32; //direction
787 #else
788         word dire=8; //direction
789 #endif
790         sword qq; //scroll offset
791         word ls = player[pn].persist_aniframe;
792
793         if(scrollswitch==0) qq = 0;
794         else qq = ((player[pn].q)*(player[pn].speed));
795         x-=4;
796         y-=TILEWH;
797         switch (player[pn].d)
798         {
799                 case 0:
800                         //up
801                         dire*=player[pn].d;
802                         y-=qq;
803                 break;
804                 case 3:
805                         // right
806                         dire*=(player[pn].d-2);
807                         x+=qq;
808                 break;
809                 case 2:
810                 break;
811                 case 4:
812                         //down
813                         dire*=(player[pn].d-2);
814                         y+=qq;
815                 break;
816                 case 1:
817                         //left
818                         dire*=(player[pn].d+2);
819                         x-=qq;
820                 break;
821         }
822
823 #ifdef SPRITE
824 // #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32, PLAYERBMPDATA);
825 // #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
826 // #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 24, 32,  PLAYERBMPDATA);
827 // #define FRAME4 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32, PLAYERBMPDATA);
828 #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32,    PLAYERBMPDATA);
829 #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32,    PLAYERBMPDATA);
830 #define FRAME3 PBUFSFUN(pip[1].page, x, y, 0, dire, 24, 32,     PLAYERBMPDATA);
831 #define FRAME4 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32,    PLAYERBMPDATA);
832 #else
833 #define FRAME1 modexClearRegion(pip[1].page, x, y, 24, 32, 2+dire);
834 #define FRAME2 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
835 #define FRAME3 modexClearRegion(pip[1].page, x, y, 24, 32, dire);
836 #define FRAME4 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
837         #endif
838         if(pageflipflop)
839         modexCopyPageRegion(pip[pip->video->p].page,
840  pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 40);
841         else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
842         //modexCopyPageRegion(pip[2].page, pip[1].page, 16, 16, 16, 16, (14*8)+4, 8+4);
843         if(2>ls && ls>=1) { FRAME1 }else
844         if(3>ls && ls>=2) { FRAME2 }else
845         if(4>ls && ls>=3) { FRAME3 }else
846         if(5>ls && ls>=4) { FRAME4 }
847         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
848         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
849         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
850 }