]> 4ch.mooo.com Git - 16.git/blob - src/zcroll.c
wwww
[16.git] / src / zcroll.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2016 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/wcpu/wcpu.h"\r
26 #include "src/lib/16render.h"\r
27 #include "src/lib/16_dbg.h"\r
28 \r
29 #define MODEXZ\r
30 \r
31 //bitmap_t p;\r
32 static map_t map;\r
33 map_view_t mv[4];\r
34 float t;\r
35 sword bakapee;\r
36 pan_t pan;\r
37 //debugswitches\r
38 boolean panswitch=0,baka=0;\r
39 //extern boolean pageflipflop=1;\r
40 unsigned int i;\r
41 const char *cpus;\r
42 //static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */\r
43 \r
44 //map_view_db_t pgid[4];\r
45 word pg;\r
46 #ifdef FADE\r
47 static word paloffset=0;\r
48 byte *dpal;\r
49 #endif\r
50 byte *gpal;\r
51 byte *ptr;\r
52 memptr pal;\r
53 \r
54 void main(int argc, char *argv[])\r
55 {\r
56         static global_game_variables_t gvar;\r
57         static player_t player[MaxPlayers];\r
58         if(argv[1]) bakapee = atoi(argv[1]);\r
59         else bakapee = 1;\r
60 \r
61         player[0].data = _fmalloc(72*128); //TODO use exmm\r
62         *player[0].data = bitmapLoadPcx("data/chikyuu.pcx", &gvar); // load sprite\r
63 \r
64         Startup16(&gvar);\r
65 \r
66         pan.pn=0;\r
67 \r
68         // OK, this one takes hellova time and needs to be done in farmalloc or MM_...\r
69         //IN CA i think you use CAL_SetupGrFile but i do think we should work together on this part --sparky4\r
70         player[0].ent = malloc(sizeof(entity_t));\r
71         player[0].ent->spri = malloc(sizeof(struct sprite));\r
72         player[0].ent->spri->spritesheet = malloc(sizeof(struct vrs_container));\r
73 \r
74         // create the map\r
75         fprintf(stderr, "testing map load~      ");\r
76         loadmap("data/test.map", &map);\r
77         chkmap(&map, 0);\r
78         printf("chkmap ok       ");\r
79         fprintf(stderr, "yay map loaded~~\n");\r
80 \r
81         // data\r
82         read_vrs(&gvar, "data/spri/chikyuu.vrs", player[0].ent->spri->spritesheet);\r
83 //      player[0].data = malloc(72*128); //TODO use exmm\r
84 //      *player[0].data = bitmapLoadPcx("data/chikyuu.pcx", &gvar); // load sprite\r
85 \r
86         //      input!\r
87         IN_Default(0, &player,ctrl_Keyboard1);\r
88 \r
89         // save the palette\r
90 #ifdef FADE\r
91         dpal = modexNewPal();\r
92         modexPalSave(dpal);\r
93         modexFadeOff(4, dpal);\r
94 #endif\r
95         textInit();\r
96         VGAmodeX(bakapee, 1, &gvar);\r
97 #ifdef MODEXZ\r
98 #ifdef FADE\r
99         modexPalBlack();        //reset the palette~\r
100 #endif\r
101         CA_LoadFile("data/spri/chikyuu.pal", &pal, &gvar);\r
102         modexPalUpdate1(pal);\r
103 #ifdef FADE\r
104         gpal = modexNewPal();\r
105         modexPalSave(gpal);\r
106         modexSavePalFile("data/g.pal", gpal);\r
107         modexPalBlack();        //so player will not see loadings~\r
108 #endif\r
109 \r
110         // setup camera and screen~\r
111         modexHiganbanaPageSetup(&gvar.video);\r
112         for(i=0;i<gvar.video.num_of_pages;i++)\r
113         {\r
114                 mv[i].page = &gvar.video.page[i];\r
115                 mv[i].map = &map;\r
116                 mv[i].video = &gvar.video;\r
117                 mv[i].pan       = &pan;\r
118         }\r
119         player[0].ent->spri->x = player[0].ent->spri->y = 20;\r
120 \r
121         // set up paging\r
122         //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
123         mapGoTo(mv, 0, 0);\r
124 #endif\r
125 \r
126         //TODO: put player in starting position of spot\r
127         //default player position on the viewable map\r
128         player[0].tx = mv[0].tx + mv[0].page->tilemidposscreenx;\r
129         player[0].ty = mv[0].ty + mv[0].page->tilemidposscreeny;\r
130         IN_initplayer(&player, 0);\r
131 \r
132         i = set_anim_by_id(player[0].ent->spri, 11);\r
133         print_anim_ids(player[0].ent->spri);\r
134         if (i == -1)\r
135         {\r
136 #ifdef FADE\r
137                 modexFadeOff(4, gpal);\r
138 #endif\r
139                 Quit(&gvar, "Wrong");\r
140 #ifdef FADE\r
141                 modexFadeOn(4, dpal);\r
142 #endif\r
143         exit(-4);\r
144         }\r
145         //++++animate_spri(&(player[0].ent->spri));\r
146 \r
147         modexShowPage(mv[0].page);//!(gvar.video.p)\r
148         shinku_fps_indicator_page = 0; // we're on page 1 now, shinku(). follow along please or it will not be visible.\r
149 #ifdef FADE\r
150         modexFadeOn(4, gpal);\r
151 #endif\r
152         modexDrawSprite(mv[0].page, 16, 16, (player[0].data));\r
153         /*strcpy(global_temp_status_text, "press enter for the loop of zcroll\nescape to quit");\r
154         modexprint(&gvar.video.page[0], 144, 72, 1, 7, 0, global_temp_status_text);\r
155         while(!IN_KeyDown(sc_Enter)){ if(IN_KeyDown(sc_Escape)) goto quit; } IN_UserInput(1,1);*///wwww\r
156         while(!IN_KeyDown(sc_Escape))// && player[0].hp>0)\r
157         {\r
158                 shinku(&gvar);\r
159                 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square\r
160                 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction\r
161                 //when player[0].tx or player[0].ty == 0 or player[0].tx == 20 or player[0].ty == 15 then stop because that is edge of map and you do not want to walk of the map\r
162 \r
163                 //player movement\r
164                 IN_ReadControl(0, &player);\r
165                 if(!panswitch){\r
166                         //ZC_walk(player[0].ent, mv);\r
167                         walk(mv, &player, 0);\r
168                 }\r
169 \r
170                 //the scripting stuff....\r
171 /*              if(((mv[0].map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))] == 0) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))\r
172                 {\r
173                         short i;\r
174                         for(i=800; i>=400; i--)\r
175                         {\r
176                                 sound(i);\r
177                         }\r
178                         nosound();\r
179                 }\r
180                 if(player[0].q == (TILEWH/(player[0].speed))+1 && player[0].info.dir != 2 && (player[0].triggerx == 5 && player[0].triggery == 5)){ player[0].hp--; }\r
181 */              //debugging binds!\r
182                 if(IN_KeyDown(2)){ modexShowPage(mv[0].page); pan.pn=0; }\r
183                 if(IN_KeyDown(25)){ modexpdump(mv[0].page);\r
184                          IN_UserInput(1,1);\r
185                 }       //p\r
186 #ifdef FADE\r
187                 if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; modexpdump(mv[0].page); IN_UserInput(1,1); } //p\r
188                 if(IN_KeyDown(22)){\r
189                         printf("2paloffset      =       %d\n", paloffset/3);\r
190                         IN_UserInput(1,1);\r
191                 }\r
192 #endif\r
193 \r
194                 //pan switch\r
195                 if(IN_KeyDown(88)){panswitch=!panswitch; IN_UserInput(1,1);}    //f12\r
196                 if(IN_KeyDown(87))      //f11\r
197                 {\r
198                         pageflipflop=!pageflipflop;\r
199                         IN_UserInput(1,1);\r
200                 }\r
201                 if(IN_KeyDown(68))      //f10\r
202                 {\r
203                         gvar.kurokku.fpscap=!gvar.kurokku.fpscap;\r
204                         IN_UserInput(1,1);\r
205                 }\r
206                 if(IN_KeyDown(67))      //f9\r
207                 {\r
208                         modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 2);\r
209                 }\r
210                 if(IN_KeyDown(66))      //f8\r
211                 {\r
212 //                      modexDrawSprite(mv[0].page, 16, 16, &p);\r
213                         modexDrawSprite(mv[0].page, 32+72, 16, (player[0].data));\r
214                 }\r
215                 //TODO fmemtest into page\r
216                 /*if(IN_KeyDown(4+1))   //4\r
217                 {\r
218                         pg=1;\r
219                         SELECT_ALL_PLANES();\r
220                         _fmemset(((mv[pg].page->data+4)+(16*(mv[pg].page->width/4))), 15, 4);\r
221                 }*/\r
222 \r
223                 //9\r
224 #ifdef FADE\r
225                 if(IN_KeyDown(10)){ modexPalOverscan(rand()%56); modexPalUpdate1(dpal); IN_UserInput(1,1); }\r
226                 //if(IN_KeyDown(11)){ modexPalOverscan(15); }\r
227 #endif\r
228                 if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break;        //incase things go out of sync!\r
229                 player[0].hp = 0;\r
230         }\r
231 \r
232         /* fade back to text mode */\r
233         /* but 1st lets save the game palette~ */\r
234 #ifdef FADE\r
235         modexPalSave(gpal);\r
236         modexSavePalFile("data/g.pal", gpal);\r
237         modexFadeOff(4, gpal);\r
238 #endif\r
239         VGAmodeX(0, 1, &gvar);\r
240         Shutdown16(&gvar);\r
241         printf("\nProject 16 zcroll.exe. This is just a test file!\n");\r
242         printf("version %s\n", VERSION);\r
243         SCROLLEXITMESG;\r
244         switch(detectcpu())\r
245         {\r
246                 case 0: cpus = "8086/8088 or 186/88"; break;\r
247                 case 1: cpus = "286"; break;\r
248                 case 2: cpus = "386 or newer"; break;\r
249                 default: cpus = "internal error"; break;\r
250         }\r
251         printf("detected CPU type: %s\n", cpus);\r
252 #ifdef FADE\r
253         modexFadeOn(4, dpal);\r
254 #endif\r
255 }\r