]> 4ch.mooo.com Git - 16.git/blob - src/scroll.c
tiku... i cannot make an fps system ><
[16.git] / src / scroll.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include "src/lib/scroll16.h"
24 //#include "src/lib/mapread.h"
25 #include "src/lib/wcpu/wcpu.h"
26
27 //#define FADE
28 #define MODEX   //this is for mode x initiating
29
30 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */
31
32 global_game_variables_t gvar;
33 static map_t map;
34 player_t player[MaxPlayers];
35 page_t screen, screen2, screen3;
36 map_view_t mv[3];
37 map_view_t *bg, *spri, *mask;//, *tmp;
38 planar_buf_t *p;
39 float t;
40
41 void main()
42 {
43 //      word panswitch=0, panq=1, pand=0;
44         word panpagenum=0; //for panning!
45         unsigned int i;
46         //static word paloffset=0;
47         const char *cpus;
48         //static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */
49
50         //map_view_db_t pgid[4];
51 #ifdef FADE
52         byte *dpal, *gpal;
53 #endif
54         byte *ptr;
55         byte *mappalptr;
56         byte *mesg=malloc(sizeof(dword));
57
58         player[0].persist_aniframe=0;
59         player[0].speed=4;
60         gvar.clock_start=*hwclockw;
61         //0000printf("starting timer\n");
62 //++++
63         //++++????start_timer(&gvar);
64 //++++  gvar.frames_per_second = 60;
65 //0000  printf("ok\n");
66         //extern struct inconfig inpu;
67
68 //      atexit(qclean());
69
70         /* create the map */
71         fprintf(stderr, "testing map load~\n");
72         loadmap("data/test.map", &map);
73 //0000  map.width=0;
74 //0000  map.height=0;
75         chkmap(&map, 0);
76         printf("chkmap ok\n");
77         fprintf(stderr, "yay map loaded~~\n");
78         mv[0].map = &map;
79         mv[1].map = &map;
80         mv[2].map = &map;
81
82         /* draw the tiles */
83 #ifdef MODEX
84         ptr = map.data;
85         mappalptr = map.tiles->data->palette;
86
87         /* data */
88         player[0].data = bitmapLoadPcx("data/ptmp.pcx"); // load sprite
89         //npctmp = bitmapLoadPcx("ptmp1.pcx"); // load sprite
90
91         /* create the planar buffer */
92         p = planar_buf_from_bitmap(&player[0].data);
93 //0000  printf("planar buffer ok\n");
94 #endif
95         /*      input!  */
96         IN_Startup();
97         IN_Default(0,&player,ctrl_Joystick);
98
99         /* save the palette */
100 #ifdef MODEX
101 #ifdef FADE
102         dpal = modexNewPal();
103         modexPalSave(dpal);
104         modexFadeOff(4, dpal);
105 #endif
106
107         textInit();
108         VGAmodeX(1, &gvar);
109 #ifdef FADE
110         modexPalBlack();        //reset the palette~
111 #endif
112 #endif
113 //      printf("Total used @ before palette initiation:         %zu\n", oldfreemem-GetFreeSize());
114 //++++  player[0].data.offset=(paloffset/3);
115 //++++  modexPalUpdate(&player[0].data, &paloffset, 0, 0);
116         //printf("      %d\n", sizeof(ptmp->data));
117         //printf("1:    %d\n", paloffset);
118 //++++  map.tiles->data->offset=(paloffset/3);
119         //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);
120 //      printf("\n====\n");
121 //      printf("0       paloffset=      %d\n", paloffset/3);
122 //      printf("====\n\n");
123 #ifdef MODEX
124 #ifdef FADE
125         gpal = modexNewPal();
126         modexPalSave(gpal);
127         modexSavePalFile("data/g.pal", gpal);
128         modexPalBlack();        //so player will not see loadings~
129 #endif
130 #endif
131
132         /* setup camera and screen~ */
133         screen = modexDefaultPage();
134         screen.width += (TILEWH*2);
135         screen.height += (TILEWH*2);//+QUADWH;
136         mv[0].page = &screen;
137         screen2 = modexNextPage(mv[0].page);
138         mv[1].page = &screen2;
139         screen3 = modexNextPageFlexibleSize(mv[1].page, 320, 240);      //(352*176)+1024 is the remaining amount of memory left wwww
140         //screen3 = modexNextPage0(mv2.page, 320, 192); //(352*176)+1024 is the remaining amount of memory left wwww
141         mv[2].page = &screen3;
142
143         /* set up paging */
144         bg = &mv[0];
145         spri = &mv[1];
146         mask = &mv[2];
147
148 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
149         mapGoTo(bg, 0, 0);
150         mapGoTo(spri, 0, 0);
151         //mapGoTo(mask, 0, 0);
152
153         //TODO: put player in starting position of spot
154         //default player position on the viewable map
155         player[0].tx = bg->tx + 10;
156         player[0].ty = bg->ty + 8;
157         player[0].x = player[0].tx*TILEWH;
158         player[0].y = player[0].ty*TILEWH;
159         player[0].triggerx = player[0].tx;
160         player[0].triggery = player[0].ty+1;
161 /*      player[0].info.x = player[0].tx;
162         player[0].info.xaxis = player[0].tx*TILEWH;
163         player[0].info.y = player[0].ty;
164         player[0].info.yaxis = player[0].ty*TILEWH;*/
165         player[0].q=1;
166         player[0].d=2;
167         player[0].hp=4;
168 //      player[0].persist_aniframe=0;
169         //npc
170         /*npc0.tx = bg->tx + 1;
171         npc0.ty = bg->ty + 1;
172         npc0.x = npc0.tx*TILEWH;
173         npc0.y = npc0.ty*TILEWH;
174         npc0.triggerx = npc0.tx;
175         npc0.triggery = npc0.ty+1;
176         npc0.q=1;
177         npc0.d=0;
178         modexDrawSpriteRegion(spri->page, npc0.x-4, npc0.y-TILEWH, 24, 64, 24, 32, &npctmp);*/
179 #ifdef  SPRITE
180 #ifdef BMPTYPE
181         oldDrawBmp(VGA, player[0].x-4, player[0].y-TILEWH, &player[0].data, 1);
182 #else
183         modexDrawSpriteRegion(spri->page, player[0].x-4, player[0].y-TILEWH, 24, 64, 24, 32, &player[0].data);
184 #endif
185 #else
186         modexClearRegion(mv[1].page, player[0].x-4, player[0].y-TILEWH, 24, 32, 15);
187 #endif
188
189         modexShowPage(spri->page);
190 //      printf("Total used @ before loop:                       %zu\n", oldfreemem-GetFreeSize());
191         modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);
192 #ifdef MODEX
193 #ifdef FADE
194         modexFadeOn(4, gpal);
195 #endif
196 #endif
197         while(!IN_KeyDown(sc_Escape) && player[0].hp>0)
198         {
199                 sprintf(mesg, "%lu", gvar.tiku);
200                 modexprint(mv[1].page, 16, 16, 1, 15, 0, mesg);
201                 shinku(mv[1].page, &gvar);
202                 IN_ReadControl(0,&player);
203         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
204         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
205         //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
206
207         //player movement
208         //if(!panswitch){
209                 walk(mv, player, 0);
210         /*}else{
211 //88 switch!
212         //right movement
213         if((IN_KeyDown(77) && !IN_KeyDown(75) && pand == 0) || pand == 2)
214         {
215                 if(pand == 0){ pand = 2; }
216                         if(panq<=(TILEWH/(player[0].speed)))
217                         {
218                                 switch(panpagenum)
219                                 {
220                                         case 0:
221                                                 //bg
222                                                 bg->page->dx++;
223                                                 modexShowPage(bg->page);
224                                         break;
225                                         case 1:
226                                                 //spri
227                                                 spri->page->dx++;
228                                                 modexShowPage(spri->page);
229                                         break;
230                                         case 2:
231                                                 //fg
232                                                 mask->page->dx++;
233                                                 modexShowPage(mask->page);
234                                         break;
235                                 }
236                                 panq++;
237                         } else { panq = 1; pand = 0; }
238         }
239         //left movement
240         if((IN_KeyDown(75) && !IN_KeyDown(77) && pand == 0) || pand == 4)
241         {
242                 if(pand == 0){ pand = 4; }
243                         if(panq<=(TILEWH/(player[0].speed)))
244                         {
245                                 switch(panpagenum)
246                                 {
247                                         case 0:
248                                                 //bg
249                                                 bg->page->dx--;
250                                                 modexShowPage(bg->page);
251                                         break;
252                                         case 1:
253                                                 //spri
254                                                 spri->page->dx--;
255                                                 modexShowPage(spri->page);
256                                         break;
257                                         case 2:
258                                                 //fg
259                                                 mask->page->dx--;
260                                                 modexShowPage(mask->page);
261                                         break;
262                                 }
263                                 panq++;
264                         } else { panq = 1; pand = 0; }
265         }
266         //down movement
267         if((IN_KeyDown(72) && !IN_KeyDown(80) && pand == 0) || pand == 3)
268         {
269                 if(pand == 0){ pand = 3; }
270                         if(panq<=(TILEWH/(player[0].speed)))
271                         {
272                                 switch(panpagenum)
273                                 {
274                                         case 0:
275                                                 //bg
276                                                 bg->page->dy--;
277                                                 modexShowPage(bg->page);
278                                         break;
279                                         case 1:
280                                                 //spri
281                                                 spri->page->dy--;
282                                                 modexShowPage(spri->page);
283                                         break;
284                                         case 2:
285                                                 //fg
286                                                 mask->page->dy--;
287                                                 modexShowPage(mask->page);
288                                         break;
289                                 }
290                                 panq++;
291                         } else { panq = 1; pand = 0; }
292         }
293         //up movement
294         if((IN_KeyDown(80) && !IN_KeyDown(72) && pand == 0) || pand == 1)
295         {
296                 if(pand == 0){ pand = 1; }
297                         if(panq<=(TILEWH/(player[0].speed)))
298                         {
299                                 switch(panpagenum)
300                                 {
301                                         case 0:
302                                                 //bg
303                                                 bg->page->dy++;
304                                                 modexShowPage(bg->page);
305                                         break;
306                                         case 1:
307                                                 //spri
308                                                 spri->page->dy++;
309                                                 modexShowPage(spri->page);
310                                         break;
311                                         case 2:
312                                                 //fg
313                                                 mask->page->dy++;
314                                                 modexShowPage(mask->page);
315                                         break;
316                                 }
317                                 panq++;
318                         } else { panq = 1; pand = 0; }
319         }
320 }*/
321
322
323         //the scripting stuf....
324
325         //if(((player[0].triggerx == TRIGGX && player[0].triggery == TRIGGY) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
326         if(((bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))] == 0) && IN_KeyDown(0x1C))||(player[0].tx == 5 && player[0].ty == 5))
327         {
328                 short i;
329                 for(i=800; i>=400; i--)
330                 {
331                         sound(i);
332                 }
333                 nosound();
334         }
335         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--; }
336         //debugging binds!
337         //if(IN_KeyDown(0x0E)) while(1){ if(xmsmalloc(24)) break; }
338         if(IN_KeyDown(2)){ modexShowPage(bg->page); panpagenum=0; }
339         if(IN_KeyDown(3)){ modexShowPage(spri->page); panpagenum=1; }
340         if(IN_KeyDown(4)){ modexShowPage(mask->page); panpagenum=2; }
341         if(IN_KeyDown(25)){ pdump(bg->page); pdump(spri->page); }       //p
342 #ifdef MODEX
343 #ifdef FADE
344         if(IN_KeyDown(24)){ modexPalUpdate0(gpal); paloffset=0; pdump(bg->page); pdump(spri->page); }
345         if(IN_KeyDown(22)){
346         paloffset=0; modexPalBlack(); modexPalUpdate(&player[0].data, &paloffset, 0, 0);
347         printf("1paloffset      =       %d\n", paloffset/3);
348          modexPalUpdate(map.tiles->data, &paloffset, 0, 0);
349         printf("2paloffset      =       %d\n", paloffset/3);
350          pdump(bg->page); pdump(spri->page); }
351 #endif
352 #endif
353         //pan switch
354         //if(IN_KeyDown(88)){if(!panswitch) panswitch++; else panswitch--; }    //f12
355         //TSR
356         if(IN_KeyDown(87))      //f11
357         {
358                 VGAmodeX(0, &gvar);
359                 IN_Shutdown();
360                 __asm
361                 {
362                         mov ah,31h
363                         int 21h
364                 }
365         }
366
367         if((player[0].q==1) && !(player[0].x%TILEWH==0 && player[0].y%TILEWH==0)) break;        //incase things go out of sync!
368
369         gvar.tiku++;
370         }
371
372         /* fade back to text mode */
373         /* but 1st lets save the game palette~ */
374 #ifdef MODEX
375 #ifdef FADE
376         modexPalSave(gpal);
377         modexSavePalFile("data/g.pal", gpal);
378         modexFadeOff(4, gpal);
379 #endif
380         VGAmodeX(0, &gvar);
381 #endif
382         IN_Shutdown();
383         printf("Project 16 scroll.exe. This is just a test file!\n");
384         printf("version %s\n", VERSION);
385         printf("tx: %d\n", bg->tx);
386         printf("ty: %d\n", bg->ty);
387         printf("player[0].x: %d", player[0].x); printf("                player[0].y: %d\n", player[0].y);
388         //if(player[0].hp==0) printf("%d wwww\n", player[0].y+8);
389         //else printf("\nplayer[0].y: %d\n", player[0].y);
390         printf("player[0].tx: %d", player[0].tx); printf("              player[0].ty: %d\n", player[0].ty);
391         printf("player[0].triggx: %d", player[0].triggerx); printf("    player[0].triggy: %d\n", player[0].triggery);
392         printf("player[0].hp: %d", (player[0].hp));     printf("        player[0].q: %d", player[0].q); printf("        player[0].info.dir: %d", player[0].info.dir);   printf("        player[0].d: %d\n", player[0].d);
393         printf("tile data value at player trigger position: %d\n", bg->map->data[(player[0].triggerx-1)+(map.width*(player[0].triggery-1))]);
394 //      printf("palette offset: %d\n", paloffset/3);
395 //++++  printf("Total used: %zu\n", oldfreemem-GetFreeSize());
396 //++++  printf("Total free: %zu\n", GetFreeSize());
397 //not used now  printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
398 //not used now  printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
399 //      printf("Screen: %dx", screen.width);    printf("%d\n", screen.height);
400 //      printf("Screen2: %dx", screen2.width);  printf("%d\n", screen2.height);
401 //      printf("map: %dx%d\n", map.width, map.height);
402 //      printf("\n");
403 //      printf("player[0].info.x: %d", player[0].info.xaxis); printf("          player[0].info.y: %d\n", player[0].info.yaxis);
404 //      printf("player[0].info.tx: %d", player[0].info.x); printf("             player[0].info.ty: %d\n", player[0].info.y);
405         //printf("map.width=%d  map.height=%d   map.data[0]=%d\n", bg->map->width, bg->map->height, bg->map->data[0]);
406
407         switch(detectcpu())
408         {
409                 case 0: cpus = "8086/8088 or 186/88"; break;
410                 case 1: cpus = "286"; break;
411                 case 2: cpus = "386 or newer"; break;
412                 default: cpus = "internal error"; break;
413         }
414         printf("detected CPU type: %s\n", cpus);
415 #ifdef MODEX
416 #ifdef FADE
417         modexFadeOn(4, dpal);
418 #endif
419 #endif
420 }