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