1 /********************************************************************
2 Mega Mario SRC
3 created: 2005/09/18
4 created: 18:9:2005 10:13
5 author: Jens Wellmann (c)
6 *********************************************************************/
7
8
9 #include "Global.h"
10
cBonus()11 cBonus::cBonus()
12 {
13
14 SURFACE[0]= LoadIMG(DATADIR "gfx/bonus/pilz.png");
15 SURFACE[1]= LoadIMG(DATADIR "gfx/bonus/blume.png");
16 SURFACE[2]= LoadIMG(DATADIR "gfx/bonus/stern.png");
17 SURFACE[3]= LoadIMG(DATADIR "gfx/bonus/life.png");
18
19 online = 0;
20 }
init(int _x,int _y,int _type)21 void cBonus::init(int _x,int _y,int _type)
22 {
23 x = _x*40;
24 y = _y*40-5;
25
26 type = _type;
27
28 x_speed = (rand()%2) ? -1.5f:1.5f;
29
30 if(type==1)
31 x_speed = 0;
32 online =1;
33 counter = 0;
34 y_speed = 0;
35 PLAYSOUND1(S_OUTPUT);
36 }
37
update()38 void cBonus::update()
39 {
40 if(!online)
41 return;
42
43 rect.x = (int)x - cam_x;
44 rect.y = (int)y - cam_y;
45
46 if(counter<35)
47 {
48 counter++;
49 y--;
50 }
51 else
52 {
53 down_touch = LEVEL->posValid(x+10,y+40) + LEVEL->posValid(x+30,y+40);
54 left_touch = LEVEL->posValid(x,y+35);
55 right_touch = LEVEL->posValid(x+40,y+35);
56 up_touch = LEVEL->posValid(x+20,y-5);
57
58 if((right_touch+left_touch))
59 x_speed *= -1;
60
61 if(y_speed>=0)
62 {
63 if(!down_touch)
64 {
65 y += y_speed;
66 if(y_speed<2)
67 y_speed+=0.05;
68 }
69 else{ y_speed = 0;}
70 }else
71 y_speed+=0.1;
72
73 x += x_speed;
74 if(y_speed<0&&up_touch);
75 else y += y_speed;
76
77 if(collision(&rect,&PLAYER->rect))
78 {
79 if(type==0)
80 PLAYER->changeStat(1);
81 else if(type==1)
82 {
83 if(PLAYER->stat==2)
84 {
85 SCORE->init(x,y,1000);
86 PLAYSOUND1(S_KICK);
87 }
88 else
89 PLAYER->changeStat(2);
90 }
91 else if(type==2)
92 {
93 PLAYER->STARPOWER += 500;
94 if(nosound==2)
95 playMusic("star.mid");
96 }
97 else if(type==3)
98 {
99 PLAYSOUND1(S_1UP);
100 HUD.lifes++;
101 SCORE->init(x,y,0);
102 }
103 online = 0;
104 return;
105 }
106 }
107
108 SDL_UpperBlit(SURFACE[type],0,screen,&rect);
109
110
111 }
112
113
114
cCrack()115 cCrack::cCrack()
116 {
117 SURFACE[0] = LoadIMG(DATADIR "gfx/bonus/cracked.png");
118 SURFACE[1] = LoadIMG(DATADIR "gfx/bonus/cracked2.png");
119 CRACKcount = 0;
120 for(int i=0;i<50;i++)
121 {
122 CRACK[i].x =0;
123 CRACK[i].y =0;
124 CRACK[i].x_speed =0;
125 CRACK[i].y_speed =0;
126 }
127 }
init(int _x,int _y,int grey)128 void cCrack::init(int _x,int _y,int grey)
129 {
130 if(CRACKcount>42)
131 CRACKcount = 0;
132 HUD.score += 50;
133 //CRACKcount++;
134 int i;
135 for(i=CRACKcount;i<CRACKcount+10;i++)
136 {
137 CRACK[i].x = _x*40;
138 CRACK[i].y = _y*40;
139 CRACK[i].x_speed = (rand()%2) ? rand()%3+2 : -(rand()%3+2);
140 CRACK[i].y_speed = -rand()%-5-4;
141 CRACK[i].grey = grey;
142 }
143 CRACKcount = i;
144 PLAYSOUND2(S_CRACK);
145 }
update()146 void cCrack::update()
147 {
148 for(int i=0;i<50;i++)
149 {
150 if(CRACK[i].y>0&&CRACK[i].y<4000)
151 {
152 CRACK[i].x += CRACK[i].x_speed;
153 CRACK[i].y += CRACK[i].y_speed;
154 //CRACK[i].x_speed = (rand()%2) ? rand()%4+2 : rand()%-4+2;
155 CRACK[i].y_speed += 0.2;
156 rect.x = CRACK[i].x-cam_x;
157 rect.y = CRACK[i].y-cam_y;
158 SDL_UpperBlit(SURFACE[CRACK[i].grey],0,screen,&rect);
159 }
160 }
161 }
162
163
164 int kick_count = 200;
165 int kick_realy,kick_realx;
166 int kick_x,kick_y;
167 int kick_texture;
kickUp(int BOXx,int BOXy)168 void kickUp(int BOXx,int BOXy)
169 {
170 if(kick_count<16)
171 return;
172 kick_count = 0;;
173 kick_realy = 0;
174 kick_realx = 0;
175 kick_x = 0;
176 kick_y = 0;
177 kick_texture = 0;
178
179 kick_x = BOXx;
180 kick_y = BOXy;
181 kick_texture = LEVEL->BONUS[BOXx][BOXy];
182 LEVEL->BONUS[BOXx][BOXy] = 8;
183 kick_realx = kick_x * 40;
184 kick_realy = kick_y * 40;
185
186 for(int i=0;i<5;i++)
187 if(((BONUS_DYNAMIC[i]->rect.x+cam_x)/40==kick_x&&(BONUS_DYNAMIC[i]->rect.y+5+cam_y)/40==kick_y-1) || ((BONUS_DYNAMIC[i]->rect.x+40+cam_x)/40==kick_x&&(BONUS_DYNAMIC[i]->rect.y+cam_y)/40==kick_y-1))
188 {
189 BONUS_DYNAMIC[i]->y_speed = -3;
190 BONUS_DYNAMIC[i]->x_speed *= -1;
191 }
192 for(int i=0;i<GOOMBAcount;i++)
193 {
194 if(((GOOMBA[i]->x)/40==kick_x&&(GOOMBA[i]->y+10)/40==kick_y-1) || ((GOOMBA[i]->x+40)/40==kick_x&&(GOOMBA[i]->y+10)/40==kick_y-1))
195 GOOMBA[i]->die();
196 }
197 for(int i=0;i<TURTLEcount;i++)
198 {
199 if(((TURTLE[i]->x)/40==kick_x&&(TURTLE[i]->y)/40==kick_y-2) || ((TURTLE[i]->x+40)/40==kick_x&&(TURTLE[i]->y)/40==kick_y-2))
200 TURTLE[i]->die();
201 }
202 for(int i=0;i<SPINYcount;i++)
203 {
204 if(((SPINY[i]->x)/40==kick_x&&(SPINY[i]->y+10)/40==kick_y-1) || ((SPINY[i]->x+40)/40==kick_x&&(SPINY[i]->y+10)/40==kick_y-1))
205 SPINY[i]->die();
206 }
207 if(!kick_texture)
208 kick_count = 500;
209 }
210
211 #define KICKSPEED 16
updateKickUp()212 void updateKickUp()
213 {
214 if(kick_count<KICKSPEED)
215 {
216 kick_count++;
217 if(kick_count<KICKSPEED/2)
218 kick_realy-=2;
219 else
220 kick_realy+=2;
221
222 tmp_rect.x = kick_realx - cam_x;
223 tmp_rect.y = kick_realy - cam_y;
224 SDL_UpperBlit(LEVEL->Bonus_Textures[kick_texture],0,screen,&tmp_rect);
225 if(kick_count == KICKSPEED)
226 LEVEL->BONUS[kick_x][kick_y] = kick_texture;
227 }
228 }
229
230
231
cGlidder()232 cGlidder::cGlidder()
233 {
234 SURFACE[0] = LoadIMG(DATADIR "gfx/effects/glid_0.png");
235 SURFACE[1] = LoadIMG(DATADIR "gfx/effects/glid_1.png");
236 SURFACE[2] = LoadIMG(DATADIR "gfx/effects/glid_2.png");
237 SURFACE[3] = LoadIMG(DATADIR "gfx/effects/glid_3.png");
238 GLIDcount = 0;
239 for(int i=0;i<50;i++)
240 {
241 GLID[i].x =0;
242 GLID[i].y =0;
243 GLID[i].x_speed =0;
244 GLID[i].y_speed =0;
245 GLID[i].count = 0;
246 }
247 }
init(int _x,int _y,int _speed_x,int _speed_y)248 void cGlidder::init(int _x,int _y,int _speed_x,int _speed_y)
249 {
250 if(GLIDcount>40)
251 GLIDcount = 0;
252 int n;
253 for( n=GLIDcount;n<GLIDcount+10;n++)
254 {
255 GLID[n].x = _x*40 + rand()%40;
256 GLID[n].y = _y*40 + rand()%40;
257 GLID[n].x_speed = _speed_x;
258 GLID[n].y_speed = _speed_y;
259 GLID[n].count = ((float)(rand()%25))/10.0f;
260 }
261 GLIDcount = n;
262 }
update()263 void cGlidder::update()
264 {
265 for(int i=0;i<50;i++)
266 {
267 if(GLID[i].y>0&&GLID[i].count<6)
268 {
269 GLID[i].x += GLID[i].x_speed += (rand()%2) ? rand()%3-1 : 0;
270 GLID[i].y += GLID[i].y_speed += (rand()%2) ? rand()%3-1 : 0;
271 rect.x = GLID[i].x-cam_x;
272 rect.y = GLID[i].y-cam_y;
273 SDL_UpperBlit(SURFACE[(int)(GLID[i].count)%4],0,screen,&rect);
274 GLID[i].count+=0.1;
275 }
276 }
277 }
278
cScore()279 cScore::cScore()
280 {
281 for(int i=0;i<20;i++)
282 {
283 SCORE_S[i].text = new char[2];
284 strcpy(SCORE_S[i].text," ");
285 }
286 SCOREcount = 0;
287 }
288
init(int _x,int _y,int _score)289 void cScore::init(int _x,int _y,int _score)
290 {
291 HUD.score += _score;
292
293 if(SCOREcount>=20)
294 SCOREcount = 0;
295
296 SCORE_S[SCOREcount].x = _x;
297 SCORE_S[SCOREcount].y = _y+20;
298 SCORE_S[SCOREcount].count = 0;
299
300 delete[](SCORE_S[SCOREcount].text);
301 SCORE_S[SCOREcount].text = new char[6];
302 if(_score==0)
303 sprintf(SCORE_S[SCOREcount].text,"1-UP");
304 else
305 sprintf(SCORE_S[SCOREcount].text,"%d",_score);
306 SCOREcount++;
307 }
update()308 void cScore::update()
309 {
310 for(int i=0;i<20;i++)
311 {
312 if(SCORE_S[i].x>0&&SCORE_S[i].count<50)
313 {
314 SCORE_S[i].y--;
315 // StringColor(screen,SCORE_S[i].x-cam_x,SCORE_S[i].y-cam_y,SCORE_S[i].text,1440);
316 StringColor(screen,SCORE_S[i].x-cam_x-1,SCORE_S[i].y-cam_y-1,SCORE_S[i].text,-10);
317 SCORE_S[i].count++;
318 }
319 }
320 }
321