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