]> 4ch.mooo.com Git - 16.git/blob - src/xcroll.c
a8c8e2eaaaf83ff9d670bca4f360a7b8866c2b80
[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 //#define NOMAPLOAD\r
29 \r
30 static map_t map;\r
31 float t;\r
32 \r
33 //debugswitches\r
34 boolean panswitch=0,baka=0;\r
35 //extern boolean pageflipflop=1;\r
36 extern boolean pagenorendermap; //default: 0\r
37 unsigned int i;\r
38 \r
39 #ifdef FADE\r
40 //static word paloffset=0;\r
41 #endif\r
42 byte *ptr;\r
43 //memptr pal;\r
44 boolean spriteswitch=0;\r
45 \r
46 #define FILENAME_1      "data/spri/chikyuu.vrs"\r
47 #define FILENAME_1P     "data/spri/chikyuu.pal"\r
48 #define FILENAME_2      "data/spri/me.vrs"\r
49 #define FILENAME_2P     "data/spri/me.pal"\r
50 //#define FILENAME_3    "data/spri/chistnd.vrl"\r
51 \r
52 void main(int argc, char *argv[])\r
53 {\r
54         static global_game_variables_t gvar;\r
55         struct glob_game_vars *ggvv;\r
56 \r
57 //      static entity_t enti;\r
58 \r
59         char bakapee[64] = FILENAME_1;\r
60         char bakapeep[64] = FILENAME_1P;\r
61 //      char bakapee3[64] = FILENAME_3;\r
62 \r
63         Startup16(&gvar);\r
64 \r
65         ggvv=&gvar;\r
66 \r
67         if (argc >= 2) {\r
68                 if(argv[1]){ strcpy(bakapee, argv[1]);\r
69                 if(argv[2]) strcpy(bakapeep, argv[2]); }\r
70         }\r
71 \r
72         // OK, this one takes hellova time and needs to be done in farmalloc or MM_...\r
73         //IN CA i think you use CAL_SetupGrFile but i do think we should work together on this part --sparky4\r
74         //----gvar.player[0].enti.spri.spritesheet = malloc(sizeof(struct vrs_container));\r
75 \r
76         // create the map\r
77 //      fprintf(stderr, "testing map load~      ");\r
78         CA_loadmap("data/test.map", &map, &gvar);\r
79 #ifndef NOMAPLOAD\r
80         chkmap(&map, 0);\r
81 //      initMap(&map);\r
82 //      printf("chkmap ok       ");\r
83 //      fprintf(stderr, "yay map loaded~~\n");\r
84 #else\r
85         chkmap(&map, 1);\r
86         //initMap(&map);\r
87 #endif\r
88         // data\r
89         VRS_LoadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
90 \r
91         // input!\r
92         IN_Default(0, &gvar.player[0],ctrl_Keyboard1, &gvar);\r
93 \r
94         // save the palette\r
95 #ifdef FADE\r
96         modexPalSave(&gvar.video.dpal);\r
97         modexFadeOff(4, &gvar.video.dpal);\r
98         modexPalBlack();\r
99 #endif\r
100 \r
101         //--VGAmodeX(1/*bakapee*/, 1, &gvar);\r
102         VL_Startup(&gvar);\r
103 \r
104         /* load color palette */\r
105         /*ptmp.offset=(paloffset/3);\r
106         modexPalUpdate(&ptmp, &paloffset, 0, 0);\r
107         //modexClearRegion(bg->page, 0, 0, 320, 240, 255);\r
108         //printf("      %d\n", sizeof(ptmp.data));\r
109         //printf("1:    %d\n", paloffset);\r
110         map.tiles->data->offset=(paloffset/3);\r
111         modexPalUpdate(map.tiles->data, &paloffset, 0, 0);*/\r
112         VL_LoadPalFile(bakapeep, &gvar.video.palette, &gvar);\r
113         //VL_LoadPalFile("data/default.pal", &gvar.video.palette);\r
114 \r
115 #ifdef FADE\r
116         modexPalSave(&gvar.video.palette);\r
117         modexSavePalFile("data/g.pal", &gvar.video.palette);\r
118         modexPalBlack();        //so player will not see loadings~\r
119 #endif\r
120 \r
121         // setup camera and screen~\r
122         modexHiganbanaPageSetup(&gvar);\r
123         ZC_MVSetup(&gvar.mv, &map, &gvar);\r
124 \r
125 #ifdef FADE\r
126         modexFadeOn(4, &gvar.video.palette);\r
127 #endif\r
128 \r
129 //0000  IN_StartAck (&gvar);    MM_ShowMemory(&gvar);   while (!IN_CheckAck (&gvar)){}\r
130 #ifdef FADE\r
131         modexPalBlack();        //so player will not see loadings~\r
132 #endif\r
133 \r
134         // set up paging\r
135         //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
136         mapGoTo(&gvar.mv, 0, 0);\r
137 \r
138         ZC_PlayerXYpos(0, 0, &gvar.player[0], &gvar.mv, 1);\r
139         EN_initPlayer(&gvar.player[0], &gvar.video);\r
140         //print_anim_ids(gvar.player[0].enti.spri);\r
141         if (gvar.video.sprifilei == -1)\r
142         {\r
143 #ifdef FADE\r
144                 modexFadeOff(4, &gvar.video.palette);\r
145 #endif\r
146                 Quit (&gvar, "Wrong ID for sprite");\r
147 #ifdef FADE\r
148                 modexFadeOn(4, &gvar.video.dpal);\r
149 #endif\r
150         }\r
151 \r
152 //      while(!gvar.in.inst->Keyboard[sc_Escape) && !gvar.in.inst->Keyboard[sc_Space) && !gvar.in.inst->Keyboard[sc_Enter]){ FUNCTIONKEYSHOWMV }\r
153         gvar.video.page[0].tlx=gvar.mv[0].tx*TILEWH;\r
154         gvar.video.page[0].tly=gvar.mv[0].ty*TILEWH;\r
155 \r
156         shinku(&gvar);\r
157 //modexpdump(gvar.mv[0].page);\r
158 #ifdef FADE\r
159         modexFadeOn(4, &gvar.video.palette);\r
160 #endif\r
161         while(!gvar.in.inst->Keyboard[sc_Escape] && gvar.player[0].enti.hp>0)\r
162         {\r
163                 gvar.video.page[0].tlx=gvar.mv[0].tx*TILEWH;\r
164                 gvar.video.page[0].tly=gvar.mv[0].ty*TILEWH;\r
165                 shinku(&gvar);\r
166                 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square\r
167                 //to stop scrolling and have the gvar.player position data move to the edge of the screen with respect to the direction\r
168                 //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
169 \r
170                 //gvar.player movement\r
171                 IN_ReadControl(&gvar.player[0], &gvar);\r
172                 if(!panswitch){\r
173                         //ZC_walk2(gvar.player[0].ent, mv);\r
174                         ZC_walk(&gvar.mv, &gvar.player, 0);\r
175                 }else{\r
176                         TAIL_PANKEYFUNZC;\r
177                         //printf("      gvar.player[0].enti.q: %d", gvar.player[0].enti.q);     printf("        gvar.player[0].d: %d\n", gvar.player[0].d);\r
178                 }\r
179 \r
180                 //the scripting stuff....\r
181                 //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
182                 if(((gvar.mv[0].map->layerdata[0].data[(gvar.player[0].enti.triggerx-1)+(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
183                 {\r
184                         short i;\r
185                         for(i=800; i>=400; i--)\r
186                         {\r
187                                 sound(i);\r
188                         }\r
189                         nosound();\r
190                 }\r
191                 if(gvar.player[0].enti.q == (TILEWH/(gvar.player[0].enti.speed))+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
192                 //debugging binds!\r
193 //              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
194                 if(gvar.in.inst->Keyboard[22]){ VL_modexPalScramble(&gvar.video.palette); VL_LoadPalFileCore(&gvar.video.palette, &gvar); } //u\r
195 \r
196                 TAIL_FUNCTIONKEYFUNCTIONS\r
197                 TAIL_FUNCTIONKEYDRAWJUNK\r
198                 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
199 \r
200 //===============================================================================\r
201 #if 0\r
202                 if(gvar.in.inst->Keyboard[sc_BackSlash]){\r
203                         VRS_ReadVRL(bakapee3, &gvar.player[0].enti, &gvar);\r
204                         DrawVRL(\r
205                                 gvar.player[0].enti.x,\r
206                                 gvar.player[0].enti.y,\r
207                                 gvar.player[0].enti.spri.sprite_vrl_cont.vrl_header,\r
208                                 gvar.player[0].enti.spri.sprite_vrl_cont.line_offsets,\r
209                                 gvar.player[0].enti.spri.sprite_vrl_cont.buffer + sizeof(struct vrl1_vgax_header),\r
210                                 gvar.player[0].enti.spri.sprite_vrl_cont.data_size\r
211                         );      while (!IN_CheckAck (&gvar)){}\r
212                         VRS_ReadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
213                 IN_UserInput(1, &gvar); }\r
214 #endif\r
215 //===============================================================================\r
216 \r
217                 if(gvar.in.inst->Keyboard[sc_J])// || gvar.in.inst->Keyboard[sc_K])\r
218                 {\r
219                         if(spriteswitch)//gvar.in.inst->Keyboard[sc_J])\r
220                         {\r
221                                 strcpy(bakapee, FILENAME_1);\r
222                                 strcpy(bakapeep, FILENAME_1P);\r
223                                 gvar.player[0].enti.overdraww=0;\r
224                         }\r
225                         else//if(gvar.in.inst->Keyboard[sc_K])\r
226                         {\r
227                                 strcpy(bakapee, FILENAME_2);\r
228                                 strcpy(bakapeep, FILENAME_2P);\r
229                                 gvar.player[0].enti.overdraww=2;\r
230                         }\r
231                         spriteswitch=!spriteswitch;\r
232 \r
233                         //read_vrs(&gvar, bakapee, gvar.player[0].enti.spri->spritesheet);\r
234                         VRS_ReadVRS(bakapee, &gvar.player[0].enti, &gvar);\r
235                         VL_LoadPalFile(bakapeep, &gvar.video.palette, &gvar);\r
236                         ZC_animatePlayer(&gvar.mv, &gvar.player, 0);\r
237                         IN_UserInput(1, &gvar);\r
238                 }//JK\r
239 //#ifdef FADE\r
240 //              if(gvar.in.inst->Keyboard[10]){ modexPalOverscan(rand()%56); modexPalUpdate(gvar.video.dpal); IN_UserInput(1, &gvar); }\r
241 //#endif\r
242                 if(gvar.in.inst->Keyboard[sc_R]){ VL_modexPalOverscan(&gvar.video.palette, rand()%32); } //r\r
243 \r
244 \r
245                 //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
246                 ZC_GirdChk(&gvar, &gvar.player[0]);\r
247         }\r
248 \r
249         /* fade back to text mode */\r
250         /* but 1st lets save the game palette~ */\r
251 #ifdef FADE\r
252         modexPalSave(&gvar.video.palette);\r
253         modexSavePalFile("data/g.pal", &gvar.video.palette);\r
254         modexFadeOff(4, &gvar.video.palette);\r
255 #endif\r
256         Shutdown16(&gvar);\r
257         printf("\nProject 16 xcroll.exe. This is just a test file!\n");\r
258         printf("version %s\n", VERSION);\r
259         SCROLLEXITMESG;\r
260         WCPU_cpufpumesg();\r
261 #ifdef FADE\r
262         modexFadeOn(4, gvar.video.dpal);\r
263 #endif\r
264 }\r