]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
deaeb1fe60e39864872e79152089320f3868fbff
[16.git] / src / lib / scroll16.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
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                         if(pip[0].tx >= 0 && pip[0].tx+20 < pip[0].map->width && player[pn].tx == pip[0].tx + 10 &&
35                         !(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!
36                         {
37                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
38                                 {
39                                         INC_PER_FRAME;
40                                         animatePlayer(pip, player, pn, 1);
41                                         mapScrollRight(pip, player, 0, pn);
42                                         mapScrollRight(pip, player, 1, pn);
43                                         modexShowPage(pip[1].page);
44                                         player[pn].q++;
45                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
46                         }
47                         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))
48                         {
49                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
50                                 {
51                                         INC_PER_FRAME;
52                                         player[pn].x+=(player[pn].speed);
53                                         animatePlayer(pip, player, pn, 0);
54                                         modexShowPage(pip[1].page);
55                                         player[pn].q++;
56                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
57                         }
58                         else
59                         {
60                                 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);
61 #ifdef SPRITE
62                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 24, 32, &player[pn].data);
63 #else
64                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 14);
65 #endif
66                                 modexShowPage(pip[1].page);
67                                 player[pn].d = 2;
68                         }
69                         player[pn].triggerx = player[pn].tx+1;
70                         player[pn].triggery = player[pn].ty;
71                 break;
72
73                 //left movement
74                 case 1:
75                         if(pip[0].tx > 0 && pip[0].tx+20 <= pip[0].map->width && player[pn].tx == pip[0].tx + 10 &&
76                         !(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!
77                         {
78                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
79                                 {
80                                         INC_PER_FRAME;
81                                         animatePlayer(pip, player, pn, 1);
82                                         mapScrollLeft(pip, player, 0, pn);
83                                         mapScrollLeft(pip, player, 1, pn);
84                                         modexShowPage(pip[1].page);
85                                         player[pn].q++;
86                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
87                         }
88                         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))
89                         {
90                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
91                                 {
92                                         INC_PER_FRAME;
93                                         player[pn].x-=(player[pn].speed);
94                                         animatePlayer(pip, player, pn, 0);
95                                         modexShowPage(pip[1].page);
96                                         player[pn].q++;
97                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
98                         }
99                         else
100                         {
101                                 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);
102 #ifdef SPRITE
103                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 96, 24, 32, &player[pn].data);
104 #else
105                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 10);
106 #endif
107                                 modexShowPage(pip[1].page);
108                                 player[pn].d = 2;
109                         }
110                         player[pn].triggerx = player[pn].tx-1;
111                         player[pn].triggery = player[pn].ty;
112                 break;
113
114                 //down movement
115                 case 4:
116                         if(pip[0].ty >= 0 && pip[0].ty+15 < pip[0].map->height && player[pn].ty == pip[0].ty + 8 &&
117                         !(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!
118                         {
119                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
120                                 {
121                                         INC_PER_FRAME;
122                                         animatePlayer(pip, player, pn, 1);
123                                         mapScrollDown(pip, player, 0, pn);
124                                         mapScrollDown(pip, player, 1, pn);
125                                         modexShowPage(pip[1].page);
126                                         player[pn].q++;
127                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
128                         }
129                         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))
130                         {
131                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
132                                 {
133                                         INC_PER_FRAME;
134                                         player[pn].y+=(player[pn].speed);
135                                         animatePlayer(pip, player, pn, 0);
136                                         modexShowPage(pip[1].page);
137                                         player[pn].q++;
138                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
139                         }
140                         else
141                         {
142                                 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);
143 #ifdef SPRITE
144                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 64, 24, 32, &player[pn].data);
145 #else
146                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 9);
147 #endif
148                                 modexShowPage(pip[1].page);
149                                 player[pn].d = 2;
150                         }
151                         player[pn].triggerx = player[pn].tx;
152                         player[pn].triggery = player[pn].ty+1;
153                 break;
154
155                 //up movement
156                 case 0:
157                         if(pip[0].ty > 0 && pip[0].ty+15 <= pip[0].map->height && player[pn].ty == pip[0].ty + 8 &&
158                         !(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!
159                         {
160                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
161                                 {
162                                         INC_PER_FRAME;
163                                         animatePlayer(pip, player, pn, 1);
164                                         mapScrollUp(pip, player, 0, pn);
165                                         mapScrollUp(pip, player, 1, pn);
166                                         modexShowPage(pip[1].page);
167                                         player[pn].q++;
168                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
169                         }
170                         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))
171                         {
172                                 if(player[pn].q<=(TILEWH/(player[pn].speed)))
173                                 {
174                                         INC_PER_FRAME;
175                                         player[pn].y-=(player[pn].speed);
176                                         animatePlayer(pip, player, 0, pn);
177                                         modexShowPage(pip[1].page);
178                                         player[pn].q++;
179                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
180                         }
181                         else
182                         {
183                                 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);
184 #ifdef SPRITE
185                                 modexDrawSpriteRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 0, 24, 32, &player[pn].data);
186 #else
187                                 modexClearRegion(pip[1].page, player[pn].x-4, player[pn].y-TILEWH, 24, 32, 12);
188 #endif
189                                 modexShowPage(pip[1].page);
190                                 player[pn].d = 2;
191                         }
192                         player[pn].triggerx = player[pn].tx;
193                         player[pn].triggery = player[pn].ty-1;
194                 break;
195         }
196 }
197
198 /*map_t
199 allocMap(int w, int h) {
200         map_t result;
201
202         result.width =w;
203         result.height=h;
204         result.data = malloc(sizeof(byte) * w * h);
205         //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
206         if(isEMS() || checkEMS())
207         {
208                 XMOVE mm;
209                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
210                 mm.length=sizeof(result);
211                 mm.sourceH=0;
212                 mm.sourceOff=ptr2long(&result);
213                 mm.destH=emmhandle;
214                 mm.destOff=0;
215                 ist = move_emem(&mm);
216                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
217                 printf("%d\n", coretotalEMS());
218         }
219
220         return result;
221 }*/
222
223 /*void
224 initMap(map_t *map) {
225         // just a place holder to fill out an alternating pattern
226         int x, y, xx, yy;
227         int i, q;
228 //      int tile = 1;
229         //if(!isEMS() || !checkEMS())
230 //              map->tiles = malloc(sizeof(tiles_t));
231         //else
232         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
233
234          //create the tile set
235         //if(!isEMS() || !checkEMS())
236 //              map->tiles->data = malloc(sizeof(bitmap_t));
237         //else
238         //      map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
239 //      map->tiles->data->width = (TILEWH);
240 //      map->tiles->data->height= TILEWH;
241         //if(!isEMS() || !checkEMS())
242 //              map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
243         //else
244         //      map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
245 //      map->tiles->tileHeight = TILEWH;
246 //      map->tiles->tileWidth =TILEWH;
247 //      map->tiles->rows = 1;
248 //      map->tiles->cols = 1;//2;
249
250         q=0;
251         //for(y=0; y<map->height; y++) {
252         //for(x=0; x<map->width; x++) {
253         i=0;
254         for(yy=0; yy<TILEWH; yy++) {
255         for(xx=0; xx<(TILEWH); xx++) {
256                 //if(x<TILEWH){
257                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
258 //                printf("[%d]", map->tiles->data->data[i]);
259                 //}else{
260                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
261                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
262                 //}
263                 i++;
264         }
265 //      printf("\n");
266         }
267 //      printf("[%d]", map->data[q]);
268         q++;
269 //      }
270         //printf("\n\n");
271 //      }
272
273         i=0;
274         for(y=0; y<map->height; y++) {
275                 for(x=0; x<map->width; x++) {
276 //                      map->data[i]=255;
277                         printf("[%d]", map->data[i]);
278                         //tile = tile ? 0 : 1;
279                         i++;
280                 }
281                 //tile = tile ? 0 : 1;
282         }
283 }*/
284
285 void mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
286 {
287         word x, y;  /* coordinate for drawing */
288
289         /* increment the pixel position and update the page */
290         mv[id].page->dx += player[plid].speed;
291
292         /* check to see if this changes the tile */
293         if(mv[id].page->dx >= mv[id].dxThresh )
294         {
295         /* go forward one tile */
296         mv[id].tx++;
297         /* Snap the origin forward */
298         mv[id].page->data += 4;
299         mv[id].page->dx = mv[id].map->tiles->tileWidth;
300         }
301
302         /* draw the next column */
303         x= SCREEN_WIDTH + mv[id].map->tiles->tileWidth;
304         if(player[plid].q%4)
305                 if(id==0)
306                         mapDrawCol(&mv[0], mv[0].tx + 20 , mv[0].ty-1, x, player, mv->page->dx);
307                 else
308                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*17);
309         //}
310 }
311
312
313 void mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
314 {
315         word x, y;  /* coordinate for drawing */
316
317         /* increment the pixel position and update the page */
318         mv[id].page->dx -= player[plid].speed;
319
320         /* check to see if this changes the tile */
321         if(mv[id].page->dx == 0)
322         {
323         /* go backward one tile */
324         mv[id].tx--;
325
326         /* Snap the origin backward */
327         mv[id].page->data -= 4;
328         mv[id].page->dx = mv[id].map->tiles->tileWidth;
329         }
330
331         /* draw the next column */
332         x= 0;
333         if(player[plid].q%4)
334                 if(id==0)
335                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
336                 else
337                         modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*17);
338         //}
339 }
340
341
342 void mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
343 {
344         word x, y;  /* coordinate for drawing */
345
346         /* increment the pixel position and update the page */
347         mv[id].page->dy -= player[plid].speed;
348
349         /* check to see if this changes the tile */
350         if(mv[id].page->dy == 0 )
351         {
352         /* go down one tile */
353         mv[id].ty--;
354         /* Snap the origin downward */
355         mv[id].page->data -= mv[id].page->width*4;
356         mv[id].page->dy = mv[id].map->tiles->tileHeight;
357         }
358
359         /* draw the next row */
360         y= 0;
361         if(player[plid].q%3)
362                 if(id==0)
363                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
364                 else
365                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*22, mv[id].map->tiles->tileHeight);
366         //}
367 }
368
369 void mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
370 {
371         word x, y;  /* coordinate for drawing */
372
373         /* increment the pixel position and update the page */
374         mv[id].page->dy += player[plid].speed;
375
376         /* check to see if this changes the tile */
377         if(mv[id].page->dy >= mv[id].dyThresh )
378         {
379         /* go down one tile */
380         mv[id].ty++;
381         /* Snap the origin downward */
382         mv[id].page->data += mv[id].page->width*4;
383         mv[id].page->dy = mv[id].map->tiles->tileHeight;
384         }
385
386         /* draw the next row */
387         y= SCREEN_HEIGHT + mv[id].map->tiles->tileHeight;
388         if(player[plid].q%3)
389                 if(id==0)
390                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+15, y, player, mv->page->dy);
391                 else
392                         modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*22, mv[id].map->tiles->tileHeight);
393         //}
394 }
395
396 sword chkmap(map_t *map, word q)
397 {
398 //      bitmap_t bp;
399         static byte x[(MAPW*MAPH)+1] = {
400 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
401 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
402 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
403 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
404 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
405 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
406 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
407 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
408 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
409 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
410 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
411 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
412 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
413 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
414 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60
415         };
416 /*{
417 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4,
418 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 5, 6, 7, 8,
419 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4,
420 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 5, 6, 7, 8,
421 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4,
422 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 5, 6, 7, 8,
423 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4,
424 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 5, 6, 7, 8,
425 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4,
426 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 5, 6, 7, 8,
427 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4,
428 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 5, 6, 7, 8,
429 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4,
430 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 5, 6, 7, 8,
431 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4,
432 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 5, 6, 7, 8,
433 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4,
434 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 5, 6, 7, 8,
435 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4
436         };*/
437 // 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, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 };
438 /*1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      1,      1,      1,      1,      1,      1,      \
439 5,      6,      7,      8,      0,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
440 9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
441 13,     14,     15,     16,     0,      1,      1,      1,      5,      8,      1,      11,     11,     1,      1,      1,      1,      1,      1,      1,      \
442 0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      \
443 1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
444 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
445 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
446 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
447 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
448 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
449 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
450 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
451 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
452 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      3,      3,      3,      1,      2,      3,      4 };*/
453         //check for failed to load map
454         if((map->width == map->height == 0) || (q>0))
455         {
456                 //initiate a null map!
457                 map->width=MAPW;///2;
458                 map->height=MAPH;///2;
459 //              map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
460                 map->data = &x;
461                 map->tiles = malloc(sizeof(tiles_t));
462                 //fix this to be far~
463 //              bp = bitmapLoadPcx("data/ed.pcx");
464 //              map->tiles->data = &bp;
465                 map->tiles->debug_data = map->data;
466                 map->tiles->tileHeight = 16;
467                 map->tiles->tileWidth = 16;
468                 map->tiles->rows = 1;
469                 map->tiles->cols = 1;
470                 map->tiles->debug_text = true;
471         }
472         return 0;
473 }
474
475 void mapGoTo(map_view_t *mv, int tx, int ty)
476 {
477         int px, py;
478         unsigned int i;
479
480         /* set up the coordinates */
481         mv->tx = tx;
482         mv->ty = ty;
483         mv->page->dx = mv->map->tiles->tileWidth;
484         mv->page->dy = mv->map->tiles->tileHeight;
485
486         /* set up the thresholds */
487         mv->dxThresh = mv->map->tiles->tileWidth * 2;
488         mv->dyThresh = mv->map->tiles->tileHeight * 2;
489
490         /* draw the tiles */
491         modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
492         py=0;
493         i=mv->ty * mv->map->width + mv->tx;
494         for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {
495                 mapDrawWRow(mv, tx-1, ty, py);
496         i+=mv->map->width - tx;
497         }
498 }
499
500
501 void
502 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
503 {
504         word rx;
505         word ry;
506         word textx=0;
507         word texty=0;
508         //if(i==0) i=2;
509         if(i==0)
510         {
511                 //wwww
512                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
513         }
514         else
515         {
516                 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
517                 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
518 ////0000printf("i=%d\n", i);
519                 switch(t->debug_text)
520                 {
521                         case 0:
522                                 modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
523                         break;
524                         case 1:
525                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i])+1);
526                                 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
527                                 /*for(texty=0; texty<2; texty++)
528                                 {
529                                         for(textx=0; textx<2; textx++)
530                                         {*/
531 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
532 /*                                      }
533                                 }*/
534                         break;
535                 }
536         }
537 }
538
539 void mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
540 {
541         word x;
542         int i;
543         poopoffset%=p[0].speed;
544 //printf("y: %d\n", poopoffset);
545         /* the position within the map array */
546         i=ty * mv->map->width + tx;
547         for(x=poopoffset; x<(SCREEN_WIDTH+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
548         if(i>=0) {
549                 /* we are in the map, so copy! */
550                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
551         }
552         i++; /* next! */
553         }
554 }
555
556 void mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
557 {
558         int y;
559         int i;
560         poopoffset%=p[0].speed;
561 //printf("x: %d\n", poopoffset);
562         /* location in the map array */
563         i=ty * mv->map->width + tx;
564
565         /* We'll copy all of the columns in the screen,
566            i + 1 row above and one below */
567         for(y=poopoffset; y<(SCREEN_HEIGHT+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
568         if(i>=0) {
569                 /* we are in the map, so copy away! */
570                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
571         }
572         i += mv->map->width;
573         }
574 }
575
576 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
577 {
578         word x;
579         int i;
580
581         /* the position within the map array */
582         i=ty * mv->map->width + tx;
583         for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
584         if(i>=0) {
585                 /* we are in the map, so copy! */
586                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
587         }
588         i++; /* next! */
589         }
590 }
591
592 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
593 {
594         int y;
595         int i;
596
597         /* location in the map array */
598         i=ty * mv->map->width + tx;
599
600         /* We'll copy all of the columns in the screen,
601            i + 1 row above and one below */
602         for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
603         if(i>=0) {
604                 /* we are in the map, so copy away! */
605                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
606         }
607         i += mv->map->width;
608         }
609 }
610
611 void qclean()
612 {
613         modexLeave();
614         //setkb(0);
615 }
616
617 //sync!
618 void shinku(page_t *page, global_game_variables_t *gv)
619 {
620         byte *pee;
621         word x = (16);
622         word y = (8+16);
623         word col = 15;
624         word bgcol = 0;
625         word type = 1;
626         //if(elapsed_timer(gv) >= (1.0 / gv->frames_per_second))
627         //{
628         //      pee = malloc(sizeof(double));
629         //      sprintf(pee, "%f", ((*gv->clock) /18.2));
630 //++++          modexprint(page, x, y, type, col, bgcol, pee);
631                 //sprintf(pee, "%f", /*gv->tiku/*/time_in_seconds(gv));
632                 //modexprint(page, x, y+8, type, col, bgcol, pee);
633         //}
634 }
635
636 void animatePlayer(map_view_t *pip, player_t *player, word playnum, sword scrollswitch)
637 {
638         sword x = player[playnum].x;
639         sword y = player[playnum].y;
640 #ifdef SPRITE
641         word dire=32; //direction
642 #else
643         word dire=8; //direction
644 #endif
645         sword qq; //scroll offset
646         word ls = player[playnum].persist_aniframe;
647
648         if(scrollswitch==0) qq = 0;
649         else qq = ((player[playnum].q)*(player[playnum].speed));
650         x-=4;
651         y-=TILEWH;
652         switch (player[playnum].d)
653         {
654                 case 0:
655                         //up
656                         dire*=player[playnum].d;
657                         y-=qq;
658                 break;
659                 case 3:
660                         // right
661                         dire*=(player[playnum].d-2);
662                         x+=qq;
663                 break;
664                 case 2:
665                 break;
666                 case 4:
667                         //down
668                         dire*=(player[playnum].d-2);
669                         y+=qq;
670                 break;
671                 case 1:
672                         //left
673                         dire*=(player[playnum].d+2);
674                         x-=qq;
675                 break;
676         }
677
678 #ifdef SPRITE
679 #ifdef BMPTYPE
680 #define FRAME1 oldDrawBmp(VGA, x, y, &player[playnum].data, 1);
681 #define FRAME2 oldDrawBmp(VGA, x, y, &player[playnum].data, 1);
682 #define FRAME3 oldDrawBmp(VGA, x, y, &player[playnum].data, 1);
683 #define FRAME4 oldDrawBmp(VGA, x, y, &player[playnum].data, 1);
684 #else
685 #define FRAME1 modexDrawSpriteRegion(pip[1].page, x, y, 48, dire, 24, 32, &player[playnum].data);
686 #define FRAME2 modexDrawSpriteRegion(pip[1].page, x, y, 24, dire, 24, 32, &player[playnum].data)
687 #define FRAME3 modexDrawSpriteRegion(pip[1].page, x, y, 0, dire, 24, 32, &player[playnum].data);
688 #define FRAME4 modexDrawSpriteRegion(pip[1].page, x, y, 24, dire, 24, 32, &player[playnum].data);
689 #endif
690 #else
691 #define FRAME1 modexClearRegion(pip[1].page, x, y, 24, 32, 2+dire);
692 #define FRAME2 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
693 #define FRAME3 modexClearRegion(pip[1].page, x, y, 24, 32, dire);
694 #define FRAME4 modexClearRegion(pip[1].page, x, y, 24, 32, 1+dire);
695 #endif
696         modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
697         if(2>ls && ls>=1) { FRAME1 }else
698         if(3>ls && ls>=2) { FRAME2 }else
699         if(4>ls && ls>=3) { FRAME3 }else
700         if(5>ls && ls>=4) { FRAME4 }
701         //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
702         //modexClearRegion(top->page, 66, 66, 2, 40, 0);
703         //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);
704         //turn this off if XT
705         //XTif(detectcpu() > 0)
706         modexWaitBorder();
707 }