menuFire.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "menuFire.h"
  2. bool optionsFire::continuer=true;
  3. unsigned int optionsFire::difficulte=0;
  4. bool optionsFire::pleinEcran=false;
  5. SDL_Surface* optionsFire::level=0;
  6. int menuFire()
  7. {
  8. if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  9. {
  10. printf( "Unable to init SDL: %s\n", SDL_GetError() );
  11. return 1;
  12. }
  13. // Lorsque le programme ferme, la SDL se ferme automatiquement.
  14. atexit(SDL_Quit);
  15. // create a new window
  16. SDL_WM_SetIcon(SDL_LoadBMP("Images/Icone Prog D.bmp"),NULL);//Icone en haut à droite de la fenêtre.
  17. SDL_Surface* ecran = SDL_SetVideoMode(640, 480, 16,SDL_HWSURFACE|SDL_DOUBLEBUF);//Création de la fenêtre
  18. SDL_WM_SetCaption("Fire !!!",NULL);//Nom de la fenêtre
  19. if ( !ecran )
  20. {
  21. printf("Unable to set 640x480 video: %s\n", SDL_GetError());
  22. return 1;
  23. }
  24. int quit(0);
  25. SDL_ShowCursor(SDL_ENABLE);
  26. //EVENT LOOP***********************************
  27. SDL_Surface* bmp = SDL_LoadBMP("Images/Hiver.bmp");
  28. SDL_Surface* bmpDeux = SDL_LoadBMP("Images/Collines.bmp");
  29. SDL_Surface* bmpTrois = SDL_LoadBMP("Images/Soleil.bmp");
  30. SDL_Surface* bmpSelect = bmp;//Choix par defaut
  31. int choice(0);
  32. SDL_Surface* indication = SDL_LoadBMP("Images/MenuFire.bmp");
  33. SDL_SetColorKey(indication,SDL_SRCCOLORKEY,SDL_MapRGB(indication->format,255,255,255));
  34. if (!bmp)//Recherche d'erreurs
  35. {
  36. printf("Unable to load bitmap: %s\n", SDL_GetError());
  37. return 1;
  38. }
  39. // Coordonnées des surfaces
  40. SDL_Rect position; SDL_Rect positionIndication;
  41. position.x = 0; positionIndication.x = 160;
  42. position.y = 0; positionIndication.y = 120;
  43. bool done = false;
  44. while (!done)
  45. {
  46. // message processing loop
  47. SDL_Event event;
  48. SDL_WaitEvent(&event);
  49. // check for messages
  50. switch (event.type)
  51. {
  52. // exit if the window is closed
  53. case SDL_QUIT:
  54. optionsFire::continuer=false;
  55. done = true;
  56. quit = 2;//Signifie que le joueur quitte pour de bon.
  57. break;
  58. // check for keypresses
  59. case SDL_KEYDOWN:
  60. switch(event.key.keysym.sym)
  61. {
  62. case SDLK_ESCAPE://Touche Echape
  63. done = true;
  64. break;
  65. case SDLK_LEFT://Petit ecran
  66. optionsFire::pleinEcran=false;
  67. break;
  68. case SDLK_RIGHT://Plein ecran
  69. optionsFire::pleinEcran=true;
  70. break;
  71. case SDLK_UP://Monte le niveau de difficulté
  72. if (choice<2)
  73. {
  74. choice++;
  75. }
  76. break;
  77. case SDLK_DOWN://Baisse le niveau de difficulte
  78. if (choice>0)
  79. {
  80. choice--;
  81. }
  82. break;
  83. }
  84. break;
  85. } // end switch
  86. // CALCULING STARTS HERE
  87. switch(choice)
  88. {
  89. case 0:
  90. bmpSelect=bmp;
  91. break;
  92. case 1:
  93. bmpSelect=bmpDeux;
  94. break;
  95. case 2:
  96. bmpSelect=bmpTrois;
  97. break;
  98. }
  99. // DRAWING STARTS HERE
  100. // clear screen
  101. SDL_FillRect(ecran, 0, SDL_MapRGB(ecran->format, 0, 0, 0));
  102. // draw bitmap
  103. SDL_BlitSurface(bmpSelect, 0, ecran, &position);
  104. SDL_BlitSurface(indication, 0, ecran, &positionIndication);
  105. // DRAWING ENDS HERE
  106. // finally, update the screen :)
  107. SDL_Flip(ecran);
  108. } // end main loop
  109. //Attribution des options
  110. optionsFire::level=bmpSelect;
  111. optionsFire::difficulte=choice;
  112. // free loaded bitmap
  113. if (!(bmpSelect==bmp))
  114. {
  115. SDL_FreeSurface(bmp);
  116. }
  117. else if(!(bmpSelect==bmpDeux))
  118. {
  119. SDL_FreeSurface(bmpDeux);
  120. }
  121. else if (!(bmpSelect==bmpTrois))
  122. {
  123. SDL_FreeSurface(bmpTrois);
  124. }
  125. SDL_FreeSurface(indication);
  126. //END EVENT LOOP*******************************
  127. // all is well ;)
  128. printf("Exited cleanly\n");
  129. return quit;
  130. }