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