]> 4ch.mooo.com Git - 16.git/blob - src/zcroll.c
hmmm layers in map_t ....
[16.git] / src / zcroll.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/16render.h"\r
26 #include "src/lib/16_dbg.h"\r
27 \r
28 #define FADE\r
29 \r
30 static map_t map;\r
31 map_view_t mv[4];\r
32 float t;\r
33 \r
34 //debugswitches\r
35 boolean panswitch=0,baka=0;\r
36 //extern boolean pageflipflop=1;\r
37 extern boolean pagenorendermap; //default: 0\r
38 unsigned int i;\r
39 \r
40 #ifdef FADE\r
41 //static word paloffset=0;\r
42 byte *dpal;\r
43 #endif\r
44 byte *gpal;\r
45 byte *ptr;\r
46 memptr pal;\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         bakapee1=malloc(64);\r
65         bakapee1p=malloc(64);\r
66 \r
67         if (argc < 2) {\r
68                 //fprintf(stderr,"drawvrl <VRL file> <palette file>\n palette file optional\n");\r
69                 bakapee1 =              FILENAME_1;\r
70                 bakapee1p =     FILENAME_1P;\r
71 \r
72         }else{\r
73                 if(argv[1]) bakapee1 = argv[1];\r
74                 if(argv[2]) bakapee1p = argv[2];\r
75         }\r
76 \r
77         // OK, this one takes hellova time and needs to be done in farmalloc or MM_...\r
78         //IN CA i think you use CAL_SetupGrFile but i do think we should work together on this part --sparky4\r
79         //player[0].ent = malloc(sizeof(entity_t));\r
80         player[0].enti.spri = malloc(sizeof(struct sprite));\r
81         player[0].enti.spri->spritesheet = malloc(sizeof(struct vrs_container));\r
82 \r
83         // create the map\r
84 //      fprintf(stderr, "testing map load~      ");\r
85         CA_loadmap("data/test.map", &map, &gvar);\r
86         chkmap(&map, 0);\r
87 //      initMap(&map);\r
88 //      printf("chkmap ok       ");\r
89 //      fprintf(stderr, "yay map loaded~~\n");\r
90 \r
91         // data\r
92         VRS_LoadVRS(bakapee1, &player[0].enti, &gvar);\r
93 \r
94         // input!\r
95         IN_Default(0, &player,ctrl_Keyboard1);\r
96 \r
97         // save the palette\r
98 #ifdef FADE\r
99         dpal = modexNewPal();\r
100         modexPalSave(dpal);\r
101         modexFadeOff(4, dpal);\r
102 #endif\r
103 \r
104         VGAmodeX(1/*bakapee*/, 1, &gvar);\r
105 \r
106         /* load color palette */\r
107         /*ptmp.offset=(paloffset/3);\r
108         modexPalUpdate(&ptmp, &paloffset, 0, 0);\r
109         //modexClearRegion(bg->page, 0, 0, 320, 240, 255);\r
110         //printf("      %d\n", sizeof(ptmp.data));\r
111         //printf("1:    %d\n", paloffset);\r
112         map.tiles->data->offset=(paloffset/3);\r
113         modexPalUpdate(map.tiles->data, &paloffset, 0, 0);*/\r
114         VL_LoadPalFile(bakapee1p, &gvar.video.palette);\r
115         VL_LoadPalFile("data/default.pal", &gvar.video.palette);\r
116 \r
117 #ifdef FADE\r
118         gpal = modexNewPal();\r
119         modexPalSave(gpal);\r
120         modexSavePalFile("data/g.pal", gpal);\r
121         modexPalBlack();        //so player will not see loadings~\r
122 #endif\r
123 \r
124         // setup camera and screen~\r
125         modexHiganbanaPageSetup(&gvar.video);\r
126         ZC_MVSetup(&mv, &map, &gvar);\r
127 \r
128         // set up paging\r
129         //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
130         mapGoTo(&mv, 0, 0);\r
131 \r
132         ZC_playerXYpos(0, 0, &player, &mv, 0, 1);\r
133         EN_initplayer(&player, 0, &gvar.video);\r
134         //print_anim_ids(player[0].enti.spri);\r
135         if (gvar.video.sprifilei == -1)\r
136         {\r
137 #ifdef FADE\r
138                 modexFadeOff(4, gpal);\r
139 #endif\r
140                 Quit(&gvar, "Wrong ID for sprite");\r
141 #ifdef FADE\r
142                 modexFadeOn(4, dpal);\r
143 #endif\r
144         }\r
145 \r
146 //      while(!IN_KeyDown(sc_Escape) && !IN_KeyDown(sc_Space) && !IN_KeyDown(sc_Enter)){ FUNCTIONKEYSHOWMV }\r
147         gvar.video.page[0].tlx=mv[0].tx*TILEWH;\r
148         gvar.video.page[0].tly=mv[0].ty*TILEWH;\r
149         shinku(&gvar);\r
150 #ifdef FADE\r
151         modexFadeOn(4, gpal);\r
152 #endif\r
153         while(!IN_KeyDown(sc_Escape) && player[0].enti.hp>0)\r
154         {\r
155                 gvar.video.page[0].tlx=mv[0].tx*TILEWH;\r
156                 gvar.video.page[0].tly=mv[0].ty*TILEWH;\r
157                 shinku(&gvar);\r
158                 //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square\r
159                 //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction\r
160                 //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
161 \r
162                 //player movement\r
163                 IN_ReadControl(0, &player);\r
164                 if(!panswitch){\r
165                         //ZC_walk2(player[0].ent, mv);\r
166                         ZC_walk(&mv, &player, 0);\r
167                 }else{\r
168                         PANKEYFUNZC;\r
169                         //printf("      player[0].enti.q: %d", player[0].enti.q);       printf("        player[0].d: %d\n", player[0].d);\r
170                 }\r
171 \r
172                 //the scripting stuff....\r
173                 //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
174                 if(((mv[0].map->MAPDATAPTR[(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
175                 {\r
176                         short i;\r
177                         for(i=800; i>=400; i--)\r
178                         {\r
179                                 sound(i);\r
180                         }\r
181                         nosound();\r
182                 }\r
183                 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
184                 //debugging binds!\r
185 \r
186                 if(IN_KeyDown(24)){ modexPalUpdate0(&gvar.video.palette); /*paloffset=0;*/ modexpdump(mv[0].page); IN_UserInput(1,1); } //o\r
187                 if(IN_KeyDown(22)){ modexPalUpdate0(&gvar.video.palette); } //u\r
188 \r
189                 FUNCTIONKEYFUNCTIONS\r
190                 FUNCTIONKEYDRAWJUNK\r
191                 if(IN_KeyDown(sc_L)){ modexClearRegion(&gvar.video.page[0], player[0].enti.x, player[0].enti.y, 16, 16, 1); }\r
192                 if(IN_KeyDown(sc_J) || IN_KeyDown(sc_K))\r
193                 {\r
194                         if(IN_KeyDown(sc_J))\r
195                         {\r
196                                 bakapee1=FILENAME_1;\r
197                                 bakapee1p=FILENAME_1P;\r
198                                 player[0].enti.overdraww=0;\r
199                         }\r
200                         if(IN_KeyDown(sc_K))\r
201                         {\r
202                                 bakapee1=FILENAME_2;\r
203                                 bakapee1p=FILENAME_2P;\r
204                                 player[0].enti.overdraww=2;\r
205                         }\r
206                         //read_vrs(&gvar, bakapee1, player[0].enti.spri->spritesheet);\r
207                         VRS_ReadVRS(bakapee1, &player[0].enti, &gvar);\r
208                         VL_LoadPalFile(bakapee1p, &gvar.video.palette);\r
209                 }//JK\r
210 #ifdef FADE\r
211                 if(IN_KeyDown(10)){ modexPalOverscan(rand()%56); modexPalUpdate(dpal); IN_UserInput(1,1); }\r
212 #endif\r
213                 if(IN_KeyDown(sc_R)){ modexPalOverscan(rand()%56); } //r\r
214 \r
215                 if((player[0].enti.q==1) && !(player[0].enti.x%TILEWH==0 && player[0].enti.y%TILEWH==0)) Quit(&gvar, "PLAYER OFF THE RAILS!");//break;  //incase things go out of sync!\r
216         }\r
217 \r
218         /* fade back to text mode */\r
219         /* but 1st lets save the game palette~ */\r
220 #ifdef FADE\r
221         modexPalSave(gpal);\r
222         modexSavePalFile("data/g.pal", gpal);\r
223         modexFadeOff(4, gpal);\r
224 #endif\r
225         Shutdown16(&gvar);\r
226         printf("\nProject 16 zcroll.exe. This is just a test file!\n");\r
227         printf("version %s\n", VERSION);\r
228         SCROLLEXITMESG;\r
229         WCPU_cpufpumesg();\r
230 #ifdef FADE\r
231         modexFadeOn(4, dpal);\r
232 #endif\r
233 }\r