]> 4ch.mooo.com Git - 16.git/blob - 16.c
modified: scroll.exe
[16.git] / 16.c
1 include "src\lib\scroll.h"
2 void main() {
3         bitmap_t ptmp; // player sprite
4         word q=1;
5         const char *cpus;
6         static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */
7         page_t screen, screen2, screen3;
8         map_t map;
9         map_view_t mv, mv2, mv3;
10         map_view_t *bg, *spri, *mask;//, *tmp;
11         byte *ptr;
12
13         /* create the map */
14         map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
15         initMap(&map);
16         mv.map = ↦
17         mv2.map = ↦
18         mv3.map = ↦
19
20         /* draw the tiles */
21         ptr = map.data;
22         /*data\\*/
23         ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
24         setkb(1);
25         modexEnter();
26         modexPalUpdate(ptmp.palette);
27         screen = modexDefaultPage();
28         screen.width += (TILEWH*2);
29         screen.height += (TILEWH*2)+QUADWH;
30         mv.page = &screen;
31         screen2 = modexNextPage(mv.page);
32         mv2.page = &screen2;
33         screen3 = screen2;
34         mv3.page = &screen3;
35
36         /* set up paging */
37         bg = &mv;
38         spri = &mv2;
39         mask = &mv3;
40
41 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen
42         mapGoTo(bg, 0, 0);
43         mapGoTo(spri, 0, 0);
44         //mapGoTo(mask, 0, 0);
45
46         //TODO: put player in starting position of spot
47         //default player position on the viewable map
48         player.tx = bg->tx + 10;
49         player.ty = bg->ty + 8;
50         player.x = player.tx*TILEWH;
51         player.y = player.ty*TILEWH;
52         player.triggerx = player.tx;
53         player.triggery = player.ty+1;
54         //TODO: erase player initial draw
55         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
56         //temp draw trigger box
57         modexClearRegion(spri->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
58         modexClearRegion(bg->page, player.triggerx*16, player.triggery*16, 16, 16, 1);
59         modexShowPage(spri->page);
60         while(!keyp(1))//!keyp(1))
61         {
62         //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
63         //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction
64         //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map
65
66         #define INC_PER_FRAME if(q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1;  
67
68         if(keyp(77) && !keyp(75))
69         {
70                 if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
71                 {
72                         for(q=1; q<=(TILEWH/SPEED); q++)
73                         {
74                                 INC_PER_FRAME;
75                                 //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
76                                 animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);
77                                 mapScrollRight(bg, SPEED, q);
78                                 mapScrollRight(spri, SPEED, q);
79                                 //mapScrollRight(mask, SPEED);
80                                 modexShowPage(spri->page);
81                         }
82                         player.tx++;
83                 }
84                 else if(player.tx < MAPX && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))
85                 {
86                         for(q=1; q<=(TILEWH/SPEED); q++)
87                         {
88                                 INC_PER_FRAME;
89                                 player.x+=SPEED;
90                                 //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
91                                 animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp);
92                                 modexShowPage(spri->page);
93                         }
94                         player.tx++;
95                 }
96                 else
97                 {
98                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
99                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
100                         modexShowPage(spri->page);
101                 }
102                 player.triggerx = player.tx+1;
103                 player.triggery = player.ty;
104         }
105
106         if(keyp(75) && !keyp(77))
107         {
108                 if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
109                 {
110                         for(q=1; q<=(TILEWH/SPEED); q++)
111                         {
112                                 INC_PER_FRAME;
113                                 //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
114                                 animatePlayer(bg, spri, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);
115                                 mapScrollLeft(bg, SPEED, q);
116                                 mapScrollLeft(spri, SPEED, q);
117                                 //mapScrollLeft(mask, SPEED);
118                                 modexShowPage(spri->page);
119                         }
120                         player.tx--;
121                 }
122                 else if(player.tx > 1 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))
123                 {
124                         for(q=1; q<=(TILEWH/SPEED); q++)
125                         {
126                                 INC_PER_FRAME;
127                                 player.x-=SPEED;
128                                 //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
129                                 animatePlayer(bg, spri, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp);
130                                 modexShowPage(spri->page);
131                         }
132                         player.tx--;
133                 }
134                 else
135                 {
136                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
137                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
138                         modexShowPage(spri->page);
139                 }
140                 player.triggerx = player.tx-1;
141                 player.triggery = player.ty;
142         }
143
144         if(keyp(80) && !keyp(72))
145         {
146                 if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
147                 {
148                         for(q=1; q<=(TILEWH/SPEED); q++)
149                         {
150                                 INC_PER_FRAME;
151                                 //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
152                                 animatePlayer(bg, spri, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);
153                                 mapScrollDown(bg, SPEED, q);
154                                 mapScrollDown(spri, SPEED, q);
155                                 //mapScrollDown(mask, SPEED);
156                                 modexShowPage(spri->page);
157                         }
158                         player.ty++;
159                 }
160                 else if(player.ty < MAPY && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))
161                 {
162                         for(q=1; q<=(TILEWH/SPEED); q++)
163                         {
164                                 INC_PER_FRAME;
165                                 player.y+=SPEED;
166                                 //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
167                                 animatePlayer(bg, spri, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp);
168                                 modexShowPage(spri->page);
169                         }
170                         player.ty++;
171                 }
172                 else
173                 {
174                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
175                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
176                         modexShowPage(spri->page);
177                 }
178                 player.triggerx = player.tx;
179                 player.triggery = player.ty+1;
180         }
181
182         if(keyp(72) && !keyp(80))
183         {
184                 if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))
185                 {
186                         for(q=1; q<=(TILEWH/SPEED); q++)
187                         {
188                                 INC_PER_FRAME;
189                                 //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
190                                 animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);
191                                 mapScrollUp(bg, SPEED, q);
192                                 mapScrollUp(spri, SPEED, q);
193                                 //mapScrollUp(mask, SPEED);
194                                 modexShowPage(spri->page);
195                         }
196                         player.ty--;
197                 }
198                 else if(player.ty > 1 && !(player.tx == TRIGGX &&  player.ty-1 == TRIGGY))
199                 {
200                         for(q=1; q<=(TILEWH/SPEED); q++)
201                         {
202                                 INC_PER_FRAME;
203                                 player.y-=SPEED;
204                                 //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
205                                 modexShowPage(spri->page);
206                                 animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp);
207                         }
208                         player.ty--;
209                 }
210                 else
211                 {
212                         modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
213                         modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
214                         modexShowPage(spri->page);
215                 }
216                 player.triggerx = player.tx;
217                 player.triggery = player.ty-1;
218         }
219         //modexClearRegion(mask->page, 66, 66, 2, 40, 0);
220
221         if((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER))
222         {
223                 short i;
224                 for(i=600; i>=400; i--)
225                 {
226                         sound(i);
227                 }
228                 nosound();
229         }
230         }
231
232         modexLeave();
233         setkb(0);
234         printf("Project 16 scroll.exe\n");
235         printf("tx: %d\n", bg->tx);
236         printf("ty: %d\n", bg->ty);
237         printf("player.x: %d\n", player.x);
238         printf("player.y: %d\n", player.y);
239         printf("player.tx: %d\n", player.tx);
240         printf("player.ty: %d\n", player.ty);
241         printf("player.triggx: %d\n", player.triggerx);
242         printf("player.triggy: %d\n", player.triggery);
243         printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");
244         printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");
245         printf("\n");
246         switch(detectcpu())
247         {
248                 case 0: cpus = "8086/8088 or 186/88"; break;
249                 case 1: cpus = "286"; break;
250                 case 2: cpus = "386 or newer"; break;
251                 default: cpus = "internal error"; break;
252         }
253         printf("detected CPU type: %s\n", cpus);
254 }