]> 4ch.mooo.com Git - 16.git/blob - bakapee.c
917784f52966765a4f82009aa78393f73a0568a2
[16.git] / bakapee.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/bakapee.h"\r
24 \r
25 /* clrstdin() clear any leftover chars tha may be in stdin stream */\r
26 void clrstdin()\r
27 {\r
28    int ch = 0;\r
29    while( ( ch = getchar() ) != '\n' && ch != EOF );\r
30 }\r
31 \r
32 //color \82Ä\82·\82Æ\r
33 void colortest(page_t *page, bakapee_t *pee)\r
34 {\r
35         //if(pee->coor < 256)\r
36         //{\r
37                 modexcls(page, pee->coor, VGA);\r
38                 pee->coor++;\r
39         //}else pee->coor = 0;\r
40 }\r
41 \r
42 //color \82Ä\82·\82Æ\r
43 void colorz(page_t *page, bakapee_t *pee)\r
44 {\r
45         if(pee->coor <= pee->hgq)\r
46         {\r
47                 modexcls(page, pee->coor, VGA);\r
48                 pee->coor++;\r
49         }else pee->coor = pee->lgq;\r
50 }\r
51 \r
52 //slow spectrum down\r
53 void ssd(page_t *page, bakapee_t *pee, word svq)\r
54 {\r
55         if(pee->sy < page->sh+1)\r
56         {\r
57                 if(pee->sx < page->sw+1)\r
58                 {\r
59                         //mxPutPixel(sx, sy, coor);\r
60                         //printf("%d %d %d %d\n", pee->sx, pee->sy, svq, pee->coor);\r
61                         dingpp(page, pee);\r
62                         pee->sx++;\r
63                 }else pee->sx = 0;\r
64                 if(pee->sx == page->sw)\r
65                 {\r
66                         pee->sy++;\r
67                         if(svq == 7) pee->coor++;\r
68                         if(pee->sy == page->sh && svq == 8) pee->coor = rand()%256;\r
69                 }\r
70         }else pee->sy = 0;\r
71 }\r
72 \r
73 //plot pixel or plot tile\r
74 void dingpp(page_t *page, bakapee_t *pee)\r
75 {\r
76         if(pee->tile)\r
77         {\r
78                 modexClearRegion(page, pee->xx, pee->yy, TILEWH, TILEWH, pee->coor);\r
79         }\r
80         else\r
81                 modexputPixel(page, pee->xx, pee->yy, pee->coor);\r
82 }\r
83 \r
84 void dingo(page_t *page, bakapee_t *pee)\r
85 {\r
86         if(pee->tile)\r
87         {\r
88                 if(pee->xx<0) pee->xx=(page->sw-TILEWH);\r
89                 if(pee->yy<0) pee->yy=(page->sh-TILEWH);\r
90                 if(pee->xx>(page->sw-TILEWH)) pee->xx=0;\r
91                 if(pee->yy>(page->sh-TILEWH)/*+(TILEWH*BUFFMX)*/) pee->yy=0;\r
92         }\r
93                 else\r
94         {\r
95                 if(pee->xx<0) pee->xx=page->sw;\r
96                 if(pee->yy<0) pee->yy=page->sh;\r
97                 if(pee->xx>page->sw) pee->xx=0;\r
98                 if(pee->yy>page->sh) pee->yy=0;\r
99         }\r
100 }\r
101 \r
102 //assigning values from randomizer\r
103 void dingas(bakapee_t *pee)\r
104 {\r
105         if(pee->gq == pee->bonk) dingu(pee);\r
106         if(!pee->bakax)\r
107         {\r
108                 if(pee->tile)\r
109                 pee->xx-=TILEWH;\r
110                 else pee->xx--;\r
111         }\r
112         else if(pee->bakax>1)\r
113         {\r
114                 if(pee->tile)\r
115                 pee->xx+=TILEWH;\r
116                 else pee->xx++;\r
117         }\r
118         if(!pee->bakay)\r
119         {\r
120                 if(pee->tile)\r
121                 pee->yy-=TILEWH;\r
122                 else pee->yy--;\r
123         }\r
124         else if(pee->bakay>1)\r
125         {\r
126                 if(pee->tile)\r
127                 pee->yy+=TILEWH;\r
128                 else pee->yy++;\r
129         }\r
130 }\r
131 \r
132 void dingaso(bakapee_t *pee)\r
133 {\r
134         if(pee->gq == pee->bonk) dingu(pee);\r
135         if(!pee->bakax)\r
136         {\r
137                 if(pee->tile)\r
138                 pee->xx-=TILEWH;\r
139                 else pee->xx--;\r
140         }\r
141         else\r
142         {\r
143                 if(pee->tile)\r
144                 pee->xx+=TILEWH;\r
145                 else pee->xx++;\r
146         }\r
147         if(!pee->bakay)\r
148         {\r
149                 if(pee->tile)\r
150                 pee->yy-=TILEWH;\r
151                 else pee->yy--;\r
152         }\r
153         else\r
154         {\r
155                 if(pee->tile)\r
156                 pee->yy+=TILEWH;\r
157                 else pee->yy++;\r
158         }\r
159 }\r
160 \r
161 void dingu(bakapee_t *pee)\r
162 {\r
163         if(pee->coor < pee->hgq && pee->coor < pee->lgq) pee->coor = pee->lgq;\r
164         if(pee->coor < pee->hgq)\r
165         {\r
166                 pee->coor++;\r
167         }else{\r
168                 pee->coor = pee->lgq;\r
169         }\r
170 }\r
171 \r
172 //randomizer\r
173 void dingq(bakapee_t *pee)\r
174 {\r
175         if(pee->gq<pee->bonk)\r
176         {\r
177                 pee->gq++;\r
178         }\r
179         else\r
180         {\r
181                 dingu(pee);\r
182                 pee->gq = 0;\r
183         }\r
184         pee->bakax = rand()%3; pee->bakay = rand()%3;\r
185 }\r
186 \r
187 void dingqo(bakapee_t *pee)\r
188 {\r
189         if(pee->gq<pee->bonk)\r
190         {\r
191                 pee->gq++;\r
192                 pee->bakax = rand()%3; pee->bakay = rand()%3;\r
193         }\r
194         else\r
195         {\r
196                 dingu(pee);\r
197                 pee->gq = 0;\r
198         }\r
199         //either one will do wwww --4\r
200         pee->bakax = rand()&0x1; pee->bakay = rand()&0x1;\r
201         //pee->bakax = rand()%2; pee->bakay = rand()%2;\r
202 }\r
203 \r
204 /*-----------ding-------------*/\r
205 void ding(page_t *page, bakapee_t *pee, word q)\r
206 {\r
207         word tx=0,ty=0;//d3y,\r
208 \r
209 //++++  if(q <= 4 && q!=2 && gq == pee->bonk-1) coor = rand()%pee->hgq;\r
210         switch(q)\r
211         {\r
212                 case 1:/*\r
213                         dingq(pee);\r
214                         if(pee->xx==page->sw){pee->bakax=0;}\r
215                         if(pee->xx==0){pee->bakax=1;}\r
216                         if(pee->yy==page->sh){pee->bakay=0;}\r
217                         if(pee->yy==0){pee->bakay=1;}*/\r
218                         dingqo(pee);\r
219                         dingaso(pee);\r
220                         dingo(page, pee);\r
221                         dingpp(page, pee);      //plot the pixel/tile\r
222                         if(pee->tile)\r
223                         modexClearRegion(page, (rand()*TILEWH)%page->width, (rand()*TILEWH)%(page->height), TILEWH, TILEWH, 0);\r
224                         else\r
225                         modexputPixel(page, rand()%page->width, rand()%page->height, 0);\r
226                 break;\r
227                 case 2:\r
228                         dingq(pee);\r
229                         dingas(pee);\r
230                         dingo(page, pee);\r
231                         dingpp(page, pee);      //plot the pixel/tile\r
232                         if(pee->tile)\r
233                         modexClearRegion(page, (rand()*TILEWH)%page->width, (rand()*TILEWH)%(page->height), TILEWH, TILEWH, 0);\r
234                         else\r
235                         modexputPixel(page, rand()%page->width, rand()%page->height, 0);\r
236                 break;\r
237                 case 3:\r
238                         /*dingq(pee);\r
239                         if(pee->xx!=page->sw||pee->yy!=page->sh)\r
240                         {\r
241                                 if(pee->xx==0){pee->bakax=1;pee->bakay=-1;d3y=1;}\r
242                                 if(pee->yy==0){pee->bakax=1;pee->bakay=0;d3y=1;}\r
243                                 if(pee->xx==page->sw){pee->bakax=-1;pee->bakay=-1;d3y=1;}\r
244                                 if(pee->yy==page->sh){pee->bakax=1;pee->bakay=0;d3y=1;}\r
245                         }else if(pee->xx==page->sw&&pee->yy==page->sh) pee->xx=pee->yy=0;\r
246                         if(d3y)\r
247                         {\r
248                                 if(pee->bakay<0)\r
249                                 {\r
250                                         pee->yy--;\r
251                                         d3y--;\r
252                                 }else\r
253                                 if(pee->bakay>0)\r
254                                 {\r
255                                         pee->yy++;\r
256                                         d3y--;\r
257                                 }\r
258                         }\r
259                         if(pee->bakax<0)\r
260                         {\r
261                                 pee->xx--;\r
262                         }else\r
263                         if(pee->bakax>0)\r
264                         {\r
265                                 pee->xx++;\r
266                         }\r
267                         dingpp(page, pee);      //plot the pixel/tile*/\r
268                         dingqo(pee);\r
269                         dingaso(pee);\r
270                         dingo(page, pee);\r
271                         dingpp(page, pee);      //plot the pixel/tile\r
272                 break;\r
273                 case 4:\r
274                         dingq(pee);\r
275                         dingas(pee);\r
276                         dingo(page, pee);\r
277                         dingpp(page, pee);      //plot the pixel/tile\r
278                 break;\r
279                 case 5:\r
280                         colortest(page, pee);\r
281                 break;\r
282                 case 6:\r
283                         pee->coor = rand()%256;\r
284                         modexcls(page, pee->coor, VGA);\r
285                 break;\r
286                 case 7:\r
287                         if(pee->coor <= pee->hgq)\r
288                         {\r
289                                 ssd(page, pee, q);\r
290                                 pee->coor++;\r
291                         }else pee->coor = pee->lgq;\r
292                 break;\r
293                 case 8:\r
294                         colorz(page, pee);\r
295                         modexprint(page, page->sw/2, page->sh/2, 1, 47, 0, "bakapi");\r
296                 break;\r
297                 case 9:\r
298                         if(pee->coor <= pee->hgq)\r
299                         {\r
300                                 ssd(page, pee, q);\r
301                                 pee->coor++;\r
302                         }else pee->coor = pee->lgq;\r
303                 break;\r
304                 case 10:\r
305                         ssd(page, pee, q); /*printf("%d\n", pee->coor);*/\r
306                 break;\r
307                 case 11:\r
308                         colorz(page, pee); delay(100);\r
309                 break;\r
310 \r
311                 case 16:        //interesting effects\r
312                         dingq(pee);\r
313                         if(!pee->bakax){ pee->xx--;}\r
314                         else if(pee->bakax>0){ pee->xx++; }\r
315                         if(!pee->bakay){ pee->yy--;}\r
316                         else if(pee->bakay>0){ pee->yy++; }\r
317                         dingas(pee);\r
318                         tx+=pee->xx+TILEWH+4;\r
319                         ty+=pee->yy+TILEWH+4;\r
320                         modexClearRegion(page, tx, ty, 4, 4, pee->coor);\r
321                         if(pee->tile)\r
322                         modexClearRegion(page, (rand()*4)%page->width, (rand()*4)%(page->height), 4, 4, 0);\r
323                         else\r
324                         modexputPixel(page, rand()%page->width, rand()%(page->height), 0);\r
325                         //printf("%d %d %d %d %d %d\n", pee->xx, pee->yy, tx, ty, TILEWH);\r
326                 break;\r
327                 default:\r
328                 break;\r
329         }\r
330         //pee->coor++;\r
331 }\r