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