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 #include "Global.h"
9 #include "unixutils.h"
10
11 bool hideMenu;
12
13
14 SDL_Surface *Menu_SURFACE[7],*ARROW_SURFACE,*LevelListBack;
15 SDL_Rect Menu_RECT[6];
16 int choice,frame_count,Levellistcount,levelchoice=0;
17 char** LevelList,**LevelNameList;
18 float arrow_speed;
19 bool levelMenu=0;
20
initMenu()21 void initMenu()
22 {
23
24 LevelListBack = LoadIMG(DATADIR "gfx/menu/levellistback.png");
25 Menu_SURFACE[6] = LoadIMG(DATADIR "gfx/menu/mario.png");
26
27 Menu_SURFACE[0] = LoadIMG(DATADIR "gfx/menu/levellist.png");
28 Menu_SURFACE[1] = LoadIMG(DATADIR "gfx/menu/newgame.png");
29 Menu_SURFACE[2] = LoadIMG(DATADIR "gfx/menu/load.png");
30 if(!show_blood)
31 Menu_SURFACE[3] = LoadIMG(DATADIR "gfx/menu/bloodn.png");
32 else
33 Menu_SURFACE[3] = LoadIMG(DATADIR "gfx/menu/bloody.png");
34 if(nosound==0)
35 Menu_SURFACE[4] = LoadIMG(DATADIR "gfx/menu/soundn.png");
36 else
37 if(nosound==1)
38 Menu_SURFACE[4] = LoadIMG(DATADIR "gfx/menu/soundy.png");
39 if(nosound==2)
40 Menu_SURFACE[4] = LoadIMG(DATADIR "gfx/menu/allsoundy.png");
41 Menu_SURFACE[5] = LoadIMG(DATADIR "gfx/menu/exit.png");
42 ARROW_SURFACE = LoadIMG(DATADIR "gfx/menu/arrow.png");
43
44 PLAYER = new cPlayer(SDLK_a,SDLK_d,SDLK_w,SDLK_s,SDLK_q,SDLK_e,12);
45 gameStarted = 0;
46 choice = 100;
47 arrow_speed = 0;
48 for(int i=0;i<7;i++)
49 {
50 Menu_RECT[i].x = 200;
51 }
52
53 Menu_RECT[1].y = 80 ;
54 Menu_RECT[0].y = 80 + 60 ;
55 Menu_RECT[2].y = 80 + 60 + 60 ;
56 Menu_RECT[3].y = 80 + 60 + 60 + 60;
57 Menu_RECT[4].y = 80 + 60 + 60 + 60 + 60;
58 Menu_RECT[5].y = 80 + 60 + 60 + 60 + 60 + 60;
59
60 frame_count = -100;
61 PLAYER->incincible = 1;
62
63
64 /// Load Level List!
65 loadlevellist();
66
67 }
loadlevellist()68 void loadlevellist()
69 {
70 ifstream ifs;
71
72 #ifdef __unix__
73 char buf[MAX_PATH], *home_dir = get_homedir();
74 snprintf(buf, MAX_PATH, "%s/.megamario/levellist.txt",
75 home_dir? home_dir:".");
76 ifs.open(buf, ios::in);
77 if (!ifs.is_open())
78 /* attention: fall through to after #endif */
79 #endif
80 ifs.open(DATADIR "levels/levellist.txt", ios::in);
81
82 char *contents = new char[150];
83 Levellistcount=0;
84 LevelList = new char*[80];
85 LevelNameList = new char*[80];
86
87 for (; ifs.getline(contents, 150);)
88 {
89 /* strip trailing CR as on Unix ifs.getline() doesn't do that. */
90 if (contents[strlen(contents)-1] == '\r')
91 contents[strlen(contents)-1] = 0;
92 /* Level path should always start with "data/" which we
93 replace with DATADIR */
94 if (strncmp(contents, "data/", 5))
95 {
96 ifs.getline(contents, 150);
97 continue;
98 }
99 LevelList[Levellistcount] = new char[150];
100 sprintf( LevelList[Levellistcount], "%s%s", DATADIR, contents + 5);
101
102 ifs.getline(contents, 150);
103 /* strip trailing CR as on Unix ifs.getline() doesn't do that. */
104 if (contents[strlen(contents)-1] == '\r')
105 contents[strlen(contents)-1] = 0;
106 LevelNameList[Levellistcount] = new char[150];
107 strcpy(LevelNameList[Levellistcount],contents);
108
109 Levellistcount++;
110
111 }
112 ifs.close();
113 delete[](contents);
114 }
showMenu()115 void showMenu()
116 {
117 Gamepad->reset();
118 arrow_speed = 8;
119 if(!gameStarted)
120 {
121 LEVEL->loadLevel(DATADIR "levels/menulevel",0);
122 }
123 hideMenu=0;
124 choice = 0;
125 while(!hideMenu)
126 {
127 MenuEvent();
128 framerate();
129 }
130 for(int i=0;i<400;i++)
131 keys[i] = 0;
132
133
134 }
135
MenuEvent()136 void MenuEvent()
137 {
138
139 frame_count++;
140 while(SDL_PollEvent(&event))
141 {
142 switch(event.type)
143 {
144 case SDL_QUIT:
145 exitos();
146 break;
147 case SDL_KEYDOWN:
148 switch(event.key.keysym.sym)
149 {
150 case SDLK_ESCAPE:
151 {
152 if(levelMenu)
153 levelMenu = 0;
154 else if(gameStartedVirtual)
155 {
156 hideMenu = 1;
157 }
158 return;
159 }
160 break;
161
162 case SDLK_UP :
163 if(levelMenu)
164 levelchoice--;
165 if(levelchoice<0)
166 levelchoice = Levellistcount-1;
167 break;
168 case SDLK_DOWN :
169 if(levelMenu)
170 levelchoice++;
171 if(levelchoice>Levellistcount-1)
172 levelchoice = 0;
173 break;
174
175 case SDLK_l :
176 levelMenu = !levelMenu;
177 break;
178
179
180
181 case SDLK_SPACE:
182 case SDLK_RETURN:
183
184 if(levelMenu)
185 {
186 levelMenu = 0;
187
188
189 cheater = 0;
190 LEVEL->loadLevel(LevelList[levelchoice],0);
191
192 resetPlayer();
193 hideMenu = 1;
194 gameStarted = 1;
195 gameStartedVirtual = 1;
196 HUD.coins = 0;
197 HUD.score = 0;
198 HUD.lifes = 5;
199 cheater = 0;
200
201 return;
202 }
203 else
204 {
205 for(int i=0;i<6;i++)
206 {
207 if(collision(&tmp_rect,&Menu_RECT[i]))
208 {
209 if(i==0)
210 {///////LEVELLIST
211 levelMenu = !levelMenu;
212 return;
213 }
214 else if(i==1)
215 {//////NEW
216 resetPlayer();
217 instruct(DATADIR "gfx/menu/insctructions.jpg");
218 instruct(DATADIR "gfx/story/story.jpg");
219 cheater = 0;
220 LEVEL->loadLevel(DATADIR "levels/1/main",0);
221 hideMenu = 1;
222 gameStarted = 1;
223 gameStartedVirtual = 1;
224 HUD.coins = 0;
225 HUD.score = 0;
226 HUD.lifes = 5;
227 cheater = 0;
228 return;
229 }
230 else if(i==2)
231 {///////LOAD
232 cheater = 0;
233 resetPlayer();
234 LEVEL->loadGame();
235 gameStarted = 1;
236 gameStartedVirtual = 1;
237 hideMenu = 1;
238 }
239 else if(i==3)
240 {
241 show_blood = !show_blood;
242 SDL_FreeSurface(Menu_SURFACE[3]);
243 if(!show_blood)
244 Menu_SURFACE[3] = LoadIMG(DATADIR "gfx/menu/bloodn.png");
245 else
246 Menu_SURFACE[3] = LoadIMG(DATADIR "gfx/menu/bloody.png");
247 }
248 else if(i==4)
249 {///////SOUND
250 nosound++;
251 if(nosound==3)
252 nosound = 0;
253 SDL_FreeSurface(Menu_SURFACE[4]);
254 if(nosound==0)
255 {
256 Menu_SURFACE[4] = LoadIMG(DATADIR "gfx/menu/soundn.png");
257 Mix_FadeOutMusic(1);//Mix_PauseMusic();
258 }
259 else
260 if(nosound==1)
261 {
262 Menu_SURFACE[4] = LoadIMG(DATADIR "gfx/menu/soundy.png");
263 Mix_FadeOutMusic(1);// PauseMusic();
264 }
265 if(nosound==2)
266 {
267 Menu_SURFACE[4] = LoadIMG(DATADIR "gfx/menu/allsoundy.png");
268 playMusic("megagroove.mid");
269 }
270 }
271 else if(i==5)///////EXIT
272 exitos();
273 PLAYSOUND1(S_FIREBALL);
274 return;
275 }
276 }
277 PLAYSOUND1(S_CRACK);
278 }
279 break;
280 }
281 }
282 }
283
284
285 keys = SDL_GetKeyState(NULL);
286
287
288 if((keys[SDLK_UP])&&!levelMenu)
289 {
290 arrow_speed-=0.3;
291 if(arrow_speed<-6)
292 arrow_speed = -6;
293 }
294 if((keys[SDLK_DOWN])&&!levelMenu)
295 {
296 arrow_speed+=0.3;
297 if(arrow_speed>6)
298 arrow_speed = 6;
299 }
300
301 if(choice >= 390)
302 {
303 arrow_speed *= -1;
304 choice = 389;
305 }
306 else if(choice <= 70)
307 {
308 arrow_speed *= -1;
309 choice = 71;
310 }
311
312
313 if(arrow_speed>0.1)
314 arrow_speed-=0.1;
315 else if(arrow_speed<0.1)
316 arrow_speed+=0.1;
317
318
319 SDL_FillRect(screen,0,LEVEL->BGCOLOR);
320 if(gameStarted==0)
321 {
322 if(frame_count == 1)
323 keys[SDLK_a] = 1;
324 else if(frame_count == 50)
325 keys[SDLK_a] = 0;
326 else if(frame_count == 90)
327 {
328 keys[SDLK_d] = 1;
329 keys[SDLK_e] = 1;
330 }else if(frame_count == 92)
331 keys[SDLK_e] = 0;
332 else if(frame_count == 150)
333 keys[SDLK_d] = 0;
334 else if(frame_count == 220)
335 keys[SDLK_e] = 1;
336 else if(frame_count == 350)
337 {
338 keys[SDLK_q] = 1;
339 keys[SDLK_e] = 0;
340 keys[SDLK_d] = 1;
341 }else if(frame_count == 560)
342 {
343 keys[SDLK_q] = 0;
344 keys[SDLK_d] = 0;
345 }else if(frame_count == 600)
346 {
347 keys[SDLK_e] = 1;
348 keys[SDLK_d] = 1;
349 }else if(frame_count == 605)
350 {
351 keys[SDLK_e] = 0;
352 keys[SDLK_d] = 0;
353 }
354 else if(frame_count == 750)
355 keys[SDLK_d] = 1;
356 else if(frame_count == 770)
357 keys[SDLK_e] = 1;
358 else if(frame_count == 800)
359 keys[SDLK_e] = 0;
360 else if(frame_count == 850)
361 keys[SDLK_e] = 1;
362 else if(frame_count == 865)
363 keys[SDLK_e] = 0;
364 else if(frame_count == 980)
365 {
366 keys[SDLK_d] = 0;
367 keys[SDLK_a] = 1;
368 }if(frame_count == 1050)
369 {
370 keys[SDLK_d] = 1;
371 keys[SDLK_q] = 1;
372 keys[SDLK_a] = 0;
373 keys[SDLK_e] = 1;
374 }else if(frame_count == 1080)
375 keys[SDLK_e] = 0;
376 else if(frame_count == 1100)
377 keys[SDLK_e] = 1;
378 else if(frame_count == 1160)
379 {
380 keys[SDLK_q] = 1;
381 keys[SDLK_e] = 0;
382 }
383
384
385 PLAYER->update();
386 if(PLAYER->x_speed == 0&&PLAYER->y_speed == -2.33)
387 {
388 for(int i=0;i<400;i++)
389 keys[i] = 0;
390 frame_count = 2000;
391 }
392
393
394 }
395 LEVEL->drawBackground();
396 if(gameStarted==0)
397 for(int i=0;i<5;i++)
398 BONUS_DYNAMIC[i]->update();
399 LEVEL->drawLevel();
400 if(gameStarted==0)
401 {
402 for(int i=0;i<GOOMBAcount;i++)
403 GOOMBA[i]->update();
404 for(int i=0;i<TURTLEcount;i++)
405 TURTLE[i]->update();
406 for(int i=0;i<TURTLEFLYcount;i++)
407 TURTLEFLY[i]->update();
408 for(int i=0;i<SPINYcount;i++)
409 SPINY[i]->update();
410 for(int i=0;i<FIRECIRCLEcount;i++)
411 FIRECIRCLE[i]->update();
412 for(int i=0;i<CANNONcount;i++)
413 CANNON[i]->update();
414
415 CRACK->update();
416 updateKickUp();
417 PLAYER->draw();
418 FIREBALL[0]->update();
419 FIREBALL[1]->update();
420 GLIDDER->update();
421 }
422
423 if(levelMenu)
424 {
425 tmp_rect.x=130;
426 tmp_rect.y=40;
427 SDL_UpperBlit(LevelListBack,0,screen,&tmp_rect);
428
429 tmp_rect.x+=20;
430 tmp_rect.w = 360;
431 tmp_rect.h = 10;
432 tmp_rect.y = 99+levelchoice*12;
433 SDL_FillRect(screen,&tmp_rect,SDL_MapRGB(screen->format, 128, 128,0) );
434
435 for(int i=0;i<Levellistcount;i++)
436 {
437 StringColor(screen,tmp_rect.x+20,100+i*12,LevelNameList[i],532432);//532532
438 }
439 }
440 else
441 {
442 tmp_rect.x = 200;
443 tmp_rect.y = 15;
444 SDL_BlitSurface(Menu_SURFACE[6],0,screen,&tmp_rect);
445
446 tmp_rect.x=160;
447 choice += arrow_speed;
448 tmp_rect.y = choice;
449 SDL_BlitSurface(ARROW_SURFACE,0,screen,&tmp_rect);
450
451
452 for(int i=0;i<6;i++)
453 {
454 SDL_BlitSurface(Menu_SURFACE[i],0,screen,&Menu_RECT[i]);
455 }
456
457 }
458 if(!HighQualityMusic_available)
459 StringColor(screen,10,460,"High Quality Music not found!",532432);
460
461 drawGLscreen();
462 }
463
464
465
466
467
468
469
470 char *HUDTEXT=0;
471 SDL_Surface *hudSurf=0,*hudoverlay;
472 HUD_STRUCT oldHUD;
drawInGameStats()473 void drawInGameStats()
474 {
475 if(oldHUD.coins != HUD.coins||oldHUD.score != HUD.score||oldHUD.lifes != HUD.lifes)
476 {
477 if(hudSurf)
478 SDL_FreeSurface(hudSurf);
479 if(HUDTEXT)
480 delete[] (HUDTEXT);
481 HUDTEXT = new char[70];
482 sprintf(HUDTEXT,"SCORE : %d COINS : %d LIFES : %d",HUD.score,HUD.coins,HUD.lifes);
483 hudSurf = TTF_RenderText_Blended(font,HUDTEXT,HUDColorbg);
484 tmp_rect.x=1;
485 tmp_rect.y=1;
486 hudoverlay = TTF_RenderText_Blended(font,HUDTEXT,HUDColor);
487 SDL_BlitSurface(hudoverlay,0,hudSurf,&tmp_rect);
488 SDL_FreeSurface(hudoverlay);
489
490 }
491
492 tmp_rect.x=50;
493 tmp_rect.y=25;
494 if(hudSurf)
495 SDL_BlitSurface(hudSurf,0,screen,&tmp_rect);
496
497 if(cheater)
498 {
499 tmp_rect.x =0;
500 tmp_rect.y = HEIGHT-cheatscreen->h;
501 SDL_BlitSurface(cheatscreen,0,screen,&tmp_rect);
502 }
503
504
505 oldHUD.coins = HUD.coins;
506 oldHUD.score = HUD.score;
507 oldHUD.lifes = HUD.lifes;
508
509 }
510