]> 4ch.mooo.com Git - 16.git/blob - src/xcroll.c
e72af2ff57843ff44f993a0c46b8a9011c830c9c
[16.git] / src / xcroll.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/lib/scroll16.h"\r
24 #include "src/lib/16_timer.h"\r
25 #include "src/lib/16_dbg.h"\r
26 \r
27 //#define FADE\r
28 \r
29 //#define NOMAPLOAD\r
30 //#define OLDPLAYERSPRITESTUFF\r
31 #define XC_CTRLTYPE ctrl_Keyboard//ctrl_Joystick1//ctrl_Mouse\r
32 #ifdef __DEBUG__\r
33 #define SCROLLEXEDEBUG\r
34 #endif\r
35 \r
36 //static map_t map;\r
37 #ifdef OLDPLAYERSPRITESTUFF\r
38 #include "src/lib/bitmapl.h"\r
39 static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */\r
40 #define INC_PER_FRAME if(gvar->player[pn].enti.q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;\r
41 \r
42 void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp);\r
43 void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);\r
44 boolean ZCL_ScreenMidPosChk(map_view_t *map_v, nibble dir, int tx, int ty);\r
45 boolean ZCL_CollCheck(map_view_t *map_v, nibble dir, int tx, int ty);\r
46 boolean ZCL_mapEdgeChk(map_view_t *map_v, nibble dir, int tx, int ty, boolean pansw, boolean noscrollsw);\r
47 void oldwalk(global_game_variables_t *gvar, word pn, bitmap_t *pbmp);\r
48 void animatePlayer(global_game_variables_t *gvar, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp);\r
49 #endif\r
50 float t;\r
51 \r
52 //debugswitches\r
53 boolean panswitch=0,baka=0;\r
54 //extern boolean pageflipflop=1;\r
55 extern boolean pagenorendermap; //default: 0\r
56 unsigned int i;\r
57 \r
58 #ifdef FADE\r
59 //static word paloffset=0;\r
60 #endif\r
61 byte *ptr;\r
62 //memptr pal;\r
63 boolean spriteswitch=0;\r
64 \r
65 #define FILENAME_1      "data/spri/chikyuu.vrs"\r
66 #define FILENAME_1P     "data/spri/chikyuu.pal"\r
67 #define FILENAME_2      "data/spri/me.vrs"\r
68 #define FILENAME_2P     "data/spri/me.pal"\r
69 //#define FILENAME_3    "data/spri/chistnd.vrl"\r
70 \r
71 void main(int argc, char *argv[])\r
72 {\r
73 #ifdef OLDPLAYERSPRITESTUFF\r
74         bitmap_t ptmp; // player sprite\r
75 #endif\r
76         static global_game_variables_t gvar;\r
77         struct glob_game_vars *ggvv;\r
78 \r
79         char bakapee[64] = FILENAME_1;\r
80         char bakapeep[64] = FILENAME_1P;\r
81 //      char bakapee3[64] = FILENAME_3;\r
82 #ifdef __DEBUG__\r
83         dbg_nointest=0;\r
84         dbg_joymousedelta=0;\r
85 #endif\r
86 \r
87         Startup16(&gvar);\r
88 \r
89         ggvv=&gvar;\r
90 \r
91         if (argc >= 2) {\r
92                 if(argv[1]){ strcpy(bakapee, argv[1]);\r
93                 if(argv[2]) strcpy(bakapeep, argv[2]); }\r
94         }\r
95 \r
96         // OK, this one takes hellova time and needs to be done in farmalloc or MM_...\r
97         //IN CA i think you use CAL_SetupGrFile but i do think we should work together on this part --sparky4\r
98         //----gvar.player[0].enti.spri.spritesheet = malloc(sizeof(struct vrs_container));\r
99 \r
100         // create the map\r
101                 #ifdef SCROLLEXEDEBUG\r
102         //strcpy(gvar.handle.datadumpfilename, "mmdump1.16w");  MM_DumpData (&gvar);\r
103         //strcpy(gvar.handle.heapdumpfilename, "heap1.16w");            HC_heapdump(&gvar);\r
104         //fprintf(stderr, "testing map load~    ");\r
105                 #endif\r
106 #ifndef NOMAPLOAD\r
107         CA_loadmap("data/test.map", &gvar.map, &gvar);\r
108         chkmap(&gvar.map, 0);\r
109 #else\r
110         chkmap(&gvar.map, 1);\r
111 #endif\r
112         //initMap(&gvar.map);\r
113                 #ifdef SCROLLEXEDEBUG\r
114         printf("chkmap ok\n");\r
115 //      fprintf(stderr, "yay map loaded~~\n");\r
116         //strcpy(gvar.handle.datadumpfilename, "mmdump2.16w");  MM_DumpData (&gvar);\r
117         //strcpy(gvar.handle.heapdumpfilename, "heap2.16w");            HC_heapdump(&gvar);\r
118                 #endif\r
119 \r
120         // data\r
121 #ifdef OLDPLAYERSPRITESTUFF\r
122         ptmp = bitmapLoadPcx("data/chikyuu.pcx"); // load sprite\r
123         modexPalUpdate(ptmp.palette);\r
124 #else\r
125                 #ifdef SCROLLEXEDEBUG\r
126         fprintf(stderr, "VRS_LoadVRS~   ");\r
127         //strcpy(gvar.handle.datadumpfilename, "mmdump3.16w");  MM_DumpData (&gvar);\r
128         //strcpy(gvar.handle.heapdumpfilename, "heap3.16w");            HC_heapdump(&gvar);\r
129                 #endif\r
130         VRS_LoadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
131                 #ifdef SCROLLEXEDEBUG\r
132         printf("VRS load OK~\n");\r
133         //strcpy(gvar.handle.datadumpfilename, "mmdump4.16w");  MM_DumpData (&gvar);\r
134         //strcpy(gvar.handle.heapdumpfilename, "heap4.16w");            HC_heapdump(&gvar);\r
135                 #endif\r
136 #endif\r
137 \r
138         // input!\r
139         IN_Default(0, &gvar.player[0],XC_CTRLTYPE, &gvar);\r
140         IN_SetControlType(&gvar.player[0],XC_CTRLTYPE);\r
141 \r
142         // save the palette\r
143 #ifdef FADE\r
144         modexPalSave(&gvar.video.dpal);\r
145         modexFadeOff(4, &gvar.video.dpal);\r
146         modexPalBlack();\r
147 #endif\r
148 \r
149         //--VGAmodeX(1/*bakapee*/, 1, &gvar);\r
150         VL_Startup(&gvar);\r
151 \r
152         /* load color palette */\r
153         /*ptmp.offset=(paloffset/3);\r
154         modexPalUpdate(&ptmp, &paloffset, 0, 0);\r
155         //modexClearRegion(bg->page, 0, 0, 320, 240, 255);\r
156         //printf("      %d\n", sizeof(ptmp.data));\r
157         //printf("1:    %d\n", paloffset);\r
158         map.tiles->data->offset=(paloffset/3);\r
159         modexPalUpdate(map.tiles->data, &paloffset, 0, 0);*/\r
160         VL_LoadPalFile(bakapeep, &gvar.video.palette, &gvar);\r
161         //VL_LoadPalFile("data/default.pal", &gvar.video.palette);\r
162 \r
163 #ifdef FADE\r
164         modexPalSave(&gvar.video.palette);\r
165         modexSavePalFile("data/g.pal", &gvar.video.palette);\r
166         modexPalBlack();        //so player will not see loadings~\r
167 #endif\r
168 \r
169         // setup camera and screen~\r
170         modexHiganbanaPageSetup(&gvar);\r
171         ZC_MVSetup(&gvar.mv, &gvar.map, &gvar);\r
172 \r
173 #ifdef FADE\r
174         modexFadeOn(4, &gvar.video.palette);\r
175 #endif\r
176 \r
177 //0000  IN_StartAck (&gvar);    MM_ShowMemory(&gvar);   while (!IN_CheckAck (&gvar)){}\r
178 #ifdef FADE\r
179         modexPalBlack();        //so player will not see loadings~\r
180 #endif\r
181 \r
182         // set up paging\r
183         //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
184         mapGoTo(&gvar.mv, 0, 0);\r
185 \r
186         ZC_PlayerXYpos(0, 0, &gvar.player[0], &gvar.mv, 1);\r
187         EN_initPlayer(&gvar.player[0], &gvar.video);\r
188 #ifdef SPRITE\r
189 #ifndef OLDPLAYERSPRITESTUFF\r
190         //print_anim_ids(gvar.player[0].enti.spri);\r
191         if (gvar.video.sprifilei == -1)\r
192         {\r
193 #ifdef FADE\r
194                 modexFadeOff(4, &gvar.video.palette);\r
195 #endif\r
196                 Quit (&gvar, "Wrong ID for sprite");\r
197 #ifdef FADE\r
198                 modexFadeOn(4, &gvar.video.dpal);\r
199 #endif\r
200         }\r
201 #endif\r
202 #endif\r
203 \r
204 //      while(!gvar.in.inst->Keyboard[sc_Escape) && !gvar.in.inst->Keyboard[sc_Space) && !gvar.in.inst->Keyboard[sc_Enter]){ FUNCTIONKEYSHOWMV }\r
205         gvar.video.page[0].tlx=gvar.mv[0].tx*TILEWH;\r
206         gvar.video.page[0].tly=gvar.mv[0].ty*TILEWH;\r
207 \r
208 #ifdef OLDWALKSHOWPAGESTUFF\r
209         VL_ShowPage(&(gvar.video.page[gvar.video.sp]), gvar.kurokku.fpscap, 0);\r
210 #endif\r
211 \r
212         shinku(&gvar);\r
213 //modexpdump(gvar.mv[0].page);\r
214 #ifdef FADE\r
215         modexFadeOn(4, &gvar.video.palette);\r
216 #endif\r
217         while(!gvar.in.inst->Keyboard[sc_Escape] && gvar.player[0].enti.hp>0)\r
218         {\r
219                 gvar.video.page[0].tlx=gvar.mv[0].tx*TILEWH;\r
220                 gvar.video.page[0].tly=gvar.mv[0].ty*TILEWH;\r
221                 shinku(&gvar);\r
222                 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square\r
223                 //to stop scrolling and have the gvar.player position data move to the edge of the screen with respect to the direction\r
224                 //when gvar.player[0].tx or gvar.player[0].ty == 0 or gvar.player[0].tx == 20 or gvar.player[0].ty == 15 then stop because that is edge of map and you do not want to walk of the map\r
225 \r
226                 //gvar.player movement\r
227                 IN_ReadControl(&gvar.player[0], &gvar);\r
228                 if(!panswitch){\r
229                         //ZC_walk2(gvar.player[0].ent, mv);\r
230                         //ZC_walk(&gvar.mv, &gvar.player, 0);\r
231 #ifdef OLDPLAYERSPRITESTUFF\r
232                         oldwalk(&gvar, 0, &ptmp);\r
233 #else\r
234                         ZC_walk(&gvar, 0);\r
235 #endif\r
236                 }else{\r
237                         TAIL_PANKEYFUNZC;\r
238                         //printf("      gvar.player[0].enti.q: %d", gvar.player[0].enti.q);     printf("        gvar.player[0].d: %d\n", gvar.player[0].d);\r
239                 }\r
240 \r
241                 //the scripting stuff....\r
242                 //if(((gvar.player[0].enti.triggerx == TRIGGX && gvar.player[0].enti.triggery == TRIGGY) && gvar.in.inst->Keyboard[0x1C))||(gvar.player[0].enti.tx == 5 && gvar.player[0].enti.ty == 5))\r
243                 if(((gvar.mv[0].map->layerdata[0].data[(gvar.player[0].enti.triggerx-1)+(gvar.map.width*(gvar.player[0].enti.triggery-1))] == 0) && gvar.in.inst->Keyboard[0x1C])||(gvar.player[0].enti.tx == 5 && gvar.player[0].enti.ty == 5))\r
244                 {\r
245                         short i;\r
246                         for(i=800; i>=400; i--)\r
247                         {\r
248                                 sound(i);\r
249                         }\r
250                         nosound();\r
251                 }\r
252                 if(gvar.player[0].enti.q == (TILEWH/(gvar.player[0].enti.spt))+1 && gvar.player[0].info.dir != 2 && (gvar.player[0].enti.triggerx == 5 && gvar.player[0].enti.triggery == 5)){ gvar.player[0].enti.hp--; }\r
253                 //debugging binds!\r
254 //              if(gvar.in.inst->Keyboard[24]){ VL_modexPalScramble(&gvar.video.palette); /*paloffset=0;*/ VL_LoadPalFileCore(&gvar.video.palette, &gvar); modexpdump(gvar.mv[0].page); IN_UserInput(1, &gvar); } //o\r
255                 if(gvar.in.inst->Keyboard[sc_O]){ VL_LoadPalFileCore(&gvar.video.palette, &gvar); modexpdump(gvar.video.sp, &gvar); IN_UserInput(1, &gvar); } //o\r
256                 if(gvar.in.inst->Keyboard[22]){ VL_modexPalScramble(&gvar.video.palette); VL_LoadPalFileCore(&gvar.video.palette, &gvar); } //u\r
257 \r
258                 TAIL_FUNCTIONKEYFUNCTIONS\r
259                 TAIL_FUNCTIONKEYDRAWJUNK\r
260                 if(gvar.in.inst->Keyboard[sc_L]){ modexClearRegion(&gvar.video.page[0], gvar.player[0].enti.x, gvar.player[0].enti.y, 16, 16, 1); }\r
261 \r
262 //===============================================================================\r
263 #if 0\r
264                 if(gvar.in.inst->Keyboard[sc_BackSlash]){\r
265                         VRS_ReadVRL(bakapee3, &gvar.player[0].enti, &gvar);\r
266                         DrawVRL(\r
267                                 gvar.player[0].enti.x,\r
268                                 gvar.player[0].enti.y,\r
269                                 gvar.player[0].enti.spri.sprite_vrl_cont.vrl_header,\r
270                                 gvar.player[0].enti.spri.sprite_vrl_cont.line_offsets,\r
271                                 gvar.player[0].enti.spri.sprite_vrl_cont.buffer + sizeof(struct vrl1_vgax_header),\r
272                                 gvar.player[0].enti.spri.sprite_vrl_cont.data_size\r
273                         );      while (!IN_CheckAck (&gvar)){}\r
274                         VRS_ReadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
275                 IN_UserInput(1, &gvar); }\r
276 #endif\r
277 //===============================================================================\r
278 \r
279 #ifdef OLDPLAYERSPRITESTUFF\r
280                 if(gvar.in.inst->Keyboard[sc_J])// || gvar.in.inst->Keyboard[sc_K])\r
281                 {\r
282 //                      sprintf(global_temp_status_text2, "%Fp", &ptmp.data);\r
283 //                      modexprint(&(gvar.video.page[0]), gvar.video.page[0].sw/2, gvar.video.page[0].sh/2, 1, 1, 3/*ccolor*/, 8, gvar.video.VL_Started, global_temp_status_text2);\r
284                         modexDrawSprite(&gvar.video.page[0], 16, 16, &ptmp);\r
285                 }\r
286                 if(gvar.in.inst->Keyboard[sc_K])\r
287                 {\r
288                         _fmemset(ptmp.data, 4, (ptmp.width)*ptmp.height);\r
289                 }\r
290 #else\r
291                 if(gvar.in.inst->Keyboard[sc_J])// || gvar.in.inst->Keyboard[sc_K])\r
292                 {\r
293                         if(spriteswitch)//gvar.in.inst->Keyboard[sc_J])\r
294                         {\r
295                                 strcpy(bakapee, FILENAME_1);\r
296                                 strcpy(bakapeep, FILENAME_1P);\r
297                                 gvar.player[0].enti.overdraww=0;\r
298                         }\r
299                         else//if(gvar.in.inst->Keyboard[sc_K])\r
300                         {\r
301                                 strcpy(bakapee, FILENAME_2);\r
302                                 strcpy(bakapeep, FILENAME_2P);\r
303                                 gvar.player[0].enti.overdraww=2;\r
304                         }\r
305                         spriteswitch=!spriteswitch;\r
306 \r
307                         //read_vrs(&gvar, bakapee, gvar.player[0].enti.spri->spritesheet);\r
308                         VRS_ReadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
309                         VL_LoadPalFile(bakapeep, &gvar.video.palette, &gvar);\r
310                         ZC_animatePlayer(&gvar.mv, &gvar.player, 0);\r
311                         IN_UserInput(1, &gvar);\r
312                 }//JK\r
313 #endif\r
314 //#ifdef FADE\r
315 //              if(gvar.in.inst->Keyboard[10]){ modexPalOverscan(rand()%56); modexPalUpdate(gvar.video.dpal); IN_UserInput(1, &gvar); }\r
316 //#endif\r
317                 if(gvar.in.inst->Keyboard[sc_R]){ VL_modexPalOverscan(&gvar.video.palette, rand()%32); } //r\r
318                 if(gvar.in.inst->Keyboard[sc_F]){ VL_SetPalette(&gamepal, &gvar.video); } //f\r
319 \r
320 \r
321                 //if((gvar.player[0].enti.q==1) && !(gvar.player[0].enti.x%TILEWH==0 && gvar.player[0].enti.y%TILEWH==0)) Quit (&gvar, "PLAYER OFF THE RAILS!");//break;        //incase things go out of sync!\r
322                 ZC_GirdChk(&gvar, &gvar.player[0]);\r
323         }\r
324 \r
325         /* fade back to text mode */\r
326         /* but 1st lets save the game palette~ */\r
327 #ifdef FADE\r
328         modexPalSave(&gvar.video.palette);\r
329         modexSavePalFile("data/g.pal", &gvar.video.palette);\r
330         modexFadeOff(4, &gvar.video.palette);\r
331 #endif\r
332                 #ifdef SCROLLEXEDEBUG\r
333         MM_DumpData (&gvar);\r
334         HC_heapdump (&gvar);\r
335                 #endif\r
336         Shutdown16(&gvar);\r
337         printf("\nProject 16 xcroll.exe. This is just a test file!\n");\r
338         printf("version %s\n", VERSION);\r
339         SCROLLEXITMESG;\r
340         WCPU_cpufpumesg();\r
341 #ifdef FADE\r
342         modexFadeOn(4, gvar.video.dpal);\r
343 #endif\r
344 }\r
345 \r
346 \r
347 \r
348 \r
349 \r
350 \r
351 \r
352 \r
353 \r
354 \r
355 \r
356 #ifdef OLDPLAYERSPRITESTUFF\r
357 void\r
358 modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {\r
359     /* draw the whole sprite */\r
360     modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
361 //      sprintf(global_temp_status_text2, "%Fp", &bmp->data);\r
362 //      modexprint(page, page->sw/2, (page->sh/2)+8, 1, 1, 3/*ccolor*/, 8, gvar->video.VL_Started, global_temp_status_text2);\r
363 }\r
364 \r
365 void\r
366 modexDrawSpriteRegion(page_t *page, int x, int y,\r
367                       int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
368     word poffset = (word)page->data + y*(page->width/4) + x/4;\r
369     byte *data = bmp->data;\r
370     word bmpOffset = (word) data + ry * bmp->width + rx;\r
371     word width = rw;\r
372     word height = rh;\r
373     byte plane = 1 << ((byte) x & 0x03);\r
374     word scanCount = width/4 + (width%4 ? 1 :0);\r
375     word nextPageRow = page->width/4 - scanCount;\r
376     word nextBmpRow = (word) bmp->width - width;\r
377     word rowCounter=0;\r
378     byte planeCounter = 4;\r
379 \r
380 //      sprintf(global_temp_status_text2, "%Fp", bmp->data);\r
381 //      modexprint(page, page->sw/2, (page->sh/2)+8, 1, 1, 3/*ccolor*/, 8, ggvv->video.VL_Started, global_temp_status_text2);\r
382 //      sprintf(global_temp_status_text2, "%Fp", data);\r
383 //      modexprint(page, page->sw/2, (page->sh/2)+16, 1, 1, 3/*ccolor*/, 8, ggvv->video.VL_Started, global_temp_status_text2);\r
384 \r
385     __asm {\r
386                 MOV AX, SCREEN_SEG      ; go to the VGA memory\r
387                 MOV ES, AX\r
388 \r
389                 MOV DX, SC_INDEX        ; point at the map mask register\r
390                 MOV AL, SC_MAPMASK      ;\r
391                 OUT DX, AL              ;\r
392 \r
393         PLANE_LOOP:\r
394                 MOV DX, SC_DATA         ; select the current plane\r
395                 MOV AL, plane           ;\r
396                 OUT DX, AL              ;\r
397 \r
398                 ;-- begin plane painting\r
399                 MOV AX, height          ; start the row counter\r
400                 MOV rowCounter, AX      ;\r
401                 MOV DI, poffset         ; go to the first pixel\r
402                 MOV SI, bmpOffset       ; go to the bmp pixel\r
403         ROW_LOOP:\r
404                 MOV CX, width           ; count the columns\r
405         SCAN_LOOP:\r
406                 LODSB\r
407                 DEC SI\r
408                 CMP AL, 0\r
409                 JNE DRAW_PIXEL          ; draw non-zero pixels\r
410 \r
411                 INC DI                  ; skip the transparent pixel\r
412                 ADD SI, 1\r
413                 JMP NEXT_PIXEL\r
414         DRAW_PIXEL:\r
415                 MOVSB                   ; copy the pixel\r
416         NEXT_PIXEL:\r
417                 SUB CX, 3               ; we skip the next 3\r
418                 ADD SI, 3               ; skip the bmp pixels\r
419                 LOOP SCAN_LOOP          ; finish the scan\r
420 \r
421                 MOV AX, nextPageRow\r
422                 ADD DI, AX              ; go to the next row on screen\r
423                 MOV AX, nextBmpRow\r
424                 ADD SI, AX              ; go to the next row on bmp\r
425 \r
426                 DEC rowCounter\r
427                 JNZ ROW_LOOP            ; do all the rows\r
428                 ;-- end plane painting\r
429 \r
430                 MOV AL, plane           ; advance to the next plane\r
431                 SHL AL, 1               ;\r
432                 AND AL, 0x0f            ; mask the plane properly\r
433                 MOV plane, AL           ; store the plane\r
434 \r
435                 INC bmpOffset           ; start bmp at the right spot\r
436 \r
437                 DEC planeCounter\r
438                 JNZ PLANE_LOOP          ; do all 4 planes\r
439     }\r
440 }\r
441 \r
442 void oldwalk(global_game_variables_t *gvar, word pn, bitmap_t *pbmp)\r
443 {\r
444         switch(gvar->player[pn].enti.d)\r
445         {\r
446                 //no direction\r
447                 case 2:\r
448                         //0000gvar->mv[0].video->startclk = (*clockw);\r
449                 break;\r
450                 //right movement\r
451                 case 3:\r
452                         if(ZCL_ScreenMidPosChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty) &&\r
453                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx+1 == TRIGGX && gvar->player[pn].enti.ty == TRIGGY))   //collision detection!\r
454                         {\r
455                                 gvar->player[pn].walktype=2;\r
456                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
457                                 {\r
458                                         INC_PER_FRAME;\r
459                                         animatePlayer(gvar, 1, 1, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
460                                         ZC_mapScroll(gvar->mv, gvar->player, pn);\r
461                                         gvar->player[pn].enti.q++;\r
462                                         //0000gvar->mv[0].video->clk = ((*clockw)-gvar->mv[0].video->startclk)/18.2;\r
463                                         modexShowPage(&gvar->video.page[0]);\r
464                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.tx++; }\r
465                         }\r
466                         else if(ZCL_mapEdgeChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty, 0, 1) &&\r
467                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx+1 == TRIGGX && gvar->player[pn].enti.ty == TRIGGY))\r
468                         {\r
469                                 gvar->player[pn].walktype=1;\r
470                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
471                                 {\r
472                                         INC_PER_FRAME;\r
473                                         gvar->player[pn].enti.x+=(gvar->player[pn].enti.spt);\r
474                                         animatePlayer(gvar, 1, 0, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
475                                         gvar->player[pn].enti.q++;\r
476                                         modexShowPage(&gvar->video.page[0]);\r
477                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.tx++; }\r
478                         }\r
479                         else\r
480                         {\r
481                                 gvar->player[pn].walktype=0;\r
482                                 //ZC_animatePlayer(gvar->mv, gvar->player, pn);\r
483                                 modexShowPage(&gvar->video.page[0]);\r
484                                 gvar->player[pn].enti.d = 2;\r
485                         }\r
486                         gvar->player[pn].enti.triggerx = gvar->player[pn].enti.tx+1;\r
487                         gvar->player[pn].enti.triggery = gvar->player[pn].enti.ty;\r
488                 break;\r
489                 //left movement\r
490                 case 1:\r
491                         if(ZCL_ScreenMidPosChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty) &&\r
492                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx-1 == TRIGGX && gvar->player[pn].enti.ty == TRIGGY))   //collision detection!\r
493                         {\r
494                                 gvar->player[pn].walktype=2;\r
495                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
496                                 {\r
497                                         INC_PER_FRAME;\r
498                                         animatePlayer(gvar, 1, 1, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
499                                         ZC_mapScroll(gvar->mv, gvar->player, pn);\r
500                                         gvar->player[pn].enti.q++;\r
501                                         //0000gvar->mv[0].video->clk = ((*clockw)-gvar->mv[0].video->startclk)/18.2;\r
502                                         modexShowPage(&gvar->video.page[0]);\r
503                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.tx--; }\r
504                         }\r
505                         else if(ZCL_mapEdgeChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty, 0, 1) &&\r
506                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx-1 == TRIGGX && gvar->player[pn].enti.ty == TRIGGY))\r
507                         {\r
508                                 gvar->player[pn].walktype=1;\r
509                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
510                                 {\r
511                                         INC_PER_FRAME;\r
512                                         gvar->player[pn].enti.x-=(gvar->player[pn].enti.spt);\r
513                                         animatePlayer(gvar, 1, 0, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
514                                         gvar->player[pn].enti.q++;\r
515                                         modexShowPage(&gvar->video.page[0]);\r
516                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.tx--; }\r
517                         }\r
518                         else\r
519                         {\r
520                                 gvar->player[pn].walktype=0;\r
521                                 //ZC_animatePlayer(gvar->mv, gvar->player, pn);\r
522                                 modexShowPage(&gvar->video.page[0]);\r
523                                 gvar->player[pn].enti.d = 2;\r
524                         }\r
525                         gvar->player[pn].enti.triggerx = gvar->player[pn].enti.tx-1;\r
526                         gvar->player[pn].enti.triggery = gvar->player[pn].enti.ty;\r
527                 break;\r
528                 //down movement\r
529                 case 4:\r
530                         if(ZCL_ScreenMidPosChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty) &&\r
531                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx == TRIGGX && gvar->player[pn].enti.ty+1 == TRIGGY))   //collision detection!\r
532                         {\r
533                                 gvar->player[pn].walktype=2;\r
534                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
535                                 {\r
536                                         INC_PER_FRAME;\r
537                                         animatePlayer(gvar, 1, 1, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
538                                         ZC_mapScroll(gvar->mv, gvar->player, pn);\r
539                                         gvar->player[pn].enti.q++;\r
540                                         //0000gvar->mv[0].video->clk = ((*clockw)-gvar->mv[0].video->startclk)/18.2;\r
541                                         modexShowPage(&gvar->video.page[0]);\r
542                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.ty++; }\r
543                         }\r
544                         else if(ZCL_mapEdgeChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty, 0, 1) &&\r
545                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx == TRIGGX && gvar->player[pn].enti.ty+1 == TRIGGY))\r
546                         {\r
547                                 gvar->player[pn].walktype=1;\r
548                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
549                                 {\r
550                                         INC_PER_FRAME;\r
551                                         gvar->player[pn].enti.y+=(gvar->player[pn].enti.spt);\r
552                                         animatePlayer(gvar, 1, 0, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
553                                         gvar->player[pn].enti.q++;\r
554                                         modexShowPage(&gvar->video.page[0]);\r
555                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.ty++; }\r
556                         }\r
557                         else\r
558                         {\r
559                                 gvar->player[pn].walktype=0;\r
560                                 //ZC_animatePlayer(gvar->mv, gvar->player, pn);\r
561                                 modexShowPage(&gvar->video.page[0]);\r
562                                 gvar->player[pn].enti.d = 2;\r
563                         }\r
564                         gvar->player[pn].enti.triggerx = gvar->player[pn].enti.tx;\r
565                         gvar->player[pn].enti.triggery = gvar->player[pn].enti.ty+1;\r
566                 break;\r
567                 //up movement\r
568                 case 0:\r
569                         if(ZCL_ScreenMidPosChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty) &&\r
570                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx == TRIGGX && gvar->player[pn].enti.ty-1 == TRIGGY))   //collision detection!\r
571                         {\r
572                                 gvar->player[pn].walktype=2;\r
573                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
574                                 {\r
575                                         INC_PER_FRAME;\r
576                                         animatePlayer(gvar, 1, 1, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
577                                         ZC_mapScroll(gvar->mv, gvar->player, pn);\r
578                                         gvar->player[pn].enti.q++;\r
579                                         //0000gvar->mv[0].video->clk = ((*clockw)-gvar->mv[0].video->startclk)/18.2;\r
580                                         modexShowPage(&gvar->video.page[0]);\r
581                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.ty--; }\r
582                         }\r
583                         else if(ZCL_mapEdgeChk(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty, 0, 1) &&\r
584                         ZCL_CollCheck(gvar->mv, gvar->player[pn].enti.d, gvar->player[pn].enti.tx, gvar->player[pn].enti.ty))//!(gvar->player[pn].enti.tx == TRIGGX &&  gvar->player[pn].enti.ty-1 == TRIGGY))\r
585                         {\r
586                                 gvar->player[pn].walktype=1;\r
587                                 if(gvar->player[pn].enti.q<=gvar->player[pn].enti.spt)\r
588                                 {\r
589                                         INC_PER_FRAME;\r
590                                         gvar->player[pn].enti.y-=(gvar->player[pn].enti.spt);\r
591                                         animatePlayer(gvar, 1, 0, gvar->player[pn].enti.x, gvar->player[pn].enti.y, persist_aniframe, gvar->player[pn].enti.q, pbmp);\r
592                                         gvar->player[pn].enti.q++;\r
593                                         modexShowPage(&gvar->video.page[0]);\r
594                                 } else { gvar->player[pn].enti.q = 1; gvar->player[pn].enti.d = 2; gvar->player[pn].enti.ty--; }\r
595                         }\r
596                         else\r
597                         {\r
598                                 gvar->player[pn].walktype=0;\r
599                                 //ZC_animatePlayer(gvar->mv, gvar->player, pn);\r
600                                 modexShowPage(&gvar->video.page[0]);\r
601                                 gvar->player[pn].enti.d = 2;\r
602                         }\r
603                         gvar->player[pn].enti.triggerx = gvar->player[pn].enti.tx;\r
604                         gvar->player[pn].enti.triggery = gvar->player[pn].enti.ty-1;\r
605                 break;\r
606         }\r
607 }\r
608 \r
609 void animatePlayer(global_game_variables_t *gvar, /*map_view_t *top, */short d1, short d2, int x, int y, int ls, int lp, bitmap_t *bmp)\r
610 {\r
611         short dire=32*d1; //direction\r
612         short qq; //scroll offset\r
613 \r
614         if(d2==0) qq = 0;\r
615         else qq = ((lp)*gvar->player[0].enti.spt);\r
616         switch (d1)\r
617         {\r
618                 case 0:\r
619                         //up\r
620                         x=x-4;\r
621                         y=y-qq-TILEWH;\r
622                 break;\r
623                 case 1:\r
624                         // right\r
625                         x=x+qq-4;\r
626                         y=y-TILEWH;\r
627                 break;\r
628                 case 2:\r
629                         //down\r
630                         x=x-4;\r
631                         y=y+qq-TILEWH;\r
632                 break;\r
633                 case 3:\r
634                         //left\r
635                         x=x-qq-4;\r
636                         y=y-TILEWH;\r
637                 break;\r
638         }\r
639         modexCopyPageRegion(gvar->mv[0].page, gvar->mv[1].page, x-4, y-4, x-4, y-4, 28, 40);\r
640         if(2>ls && ls>=1) { modexDrawSpriteRegion(gvar->mv[0].page, x, y, 48, dire, 24, 32, bmp); }else\r
641         if(3>ls && ls>=2) { modexDrawSpriteRegion(gvar->mv[0].page, x, y, 24, dire, 24, 32, bmp); }else\r
642         if(4>ls && ls>=3) { modexDrawSpriteRegion(gvar->mv[0].page, x, y, 0, dire, 24, 32, bmp); }else\r
643         if(5>ls && ls>=4) { modexDrawSpriteRegion(gvar->mv[0].page, x, y, 24, dire, 24, 32, bmp); }\r
644         //TODO: mask copy //modexCopyPageRegion(gvar->mv[0].page, gvar->mv[0].page, x-4, y-4, x-4, y-4, 28, 40);\r
645         //modexClearRegion(top->page, 66, 66, 2, 40, 0);\r
646         //modexCopyPageRegion(gvar->mv[0].page, top->page, 66, 66, 66, 66, 2, 40);\r
647         //turn this off if XT\r
648         //if(detectcpu() > 0) modexWaitBorder();\r
649         switch(gvar->kurokku.fpscap)\r
650         {\r
651                 case 0: //turn this off if XT\r
652                         //modexprint(&(gv->video.page[0]), x, y+8, type, 1, col, bgcol, "sanic!");\r
653                         gvar->kurokku.frames_per_second=1;\r
654                 break;\r
655                 case 1:\r
656                         modexWaitBorder();\r
657                         gvar->kurokku.frames_per_second=FPSVALUE;\r
658                 break;\r
659         }\r
660         PM_NextFrame(gvar);\r
661 }\r
662 #endif\r