main.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <iostream>
  2. #include <SDL/SDL.h>
  3. #include "FeuFolet.h"
  4. #define RAYON 160
  5. int main ( int argc, char** argv )
  6. {
  7. /// [1] Démarrage
  8. // [1.1] Démarrages SDL
  9. if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
  10. {
  11. std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
  12. return 1;
  13. }
  14. // [1.2] Préparation de fermeture
  15. atexit(SDL_Quit);
  16. // [1.3] Para-fenêtre
  17. SDL_WM_SetCaption("Application SDL: Algorythme du Feu Follet", 0);
  18. /// [2] Préparation des composants
  19. // [2.1] Préparation de la fenêtre
  20. SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32,
  21. SDL_HWSURFACE|SDL_DOUBLEBUF);
  22. if ( !screen )
  23. {
  24. std::cout << "Unable to set 640x480 video: " << SDL_GetError() << std::endl;
  25. return 1;
  26. }
  27. // [2.2] Préparation
  28. SDL_Surface* fond = SDL_LoadBMP("soleil.bmp");
  29. SDL_Surface* follet = createFeuFolet(RAYON, SDL_MapRGB(screen->format, 0, 0, 255));
  30. SDL_Rect pos;
  31. pos.x=pos.y=0;
  32. short opacite (0);
  33. /// [3] Boucle principale
  34. SDL_EnableKeyRepeat(10,10);
  35. bool done = false;
  36. while (!done)
  37. {
  38. // [3.1] Gestion évènements
  39. SDL_Event event;
  40. while (SDL_PollEvent(&event))
  41. {
  42. switch (event.type)
  43. {
  44. case SDL_QUIT:
  45. done = true;
  46. break;
  47. case SDL_KEYDOWN:
  48. if (event.key.keysym.sym == SDLK_ESCAPE)
  49. done = true;
  50. else if (event.key.keysym.sym == SDLK_UP)
  51. opacite++;
  52. else if (event.key.keysym.sym == SDLK_DOWN)
  53. opacite--;
  54. break;
  55. case SDL_MOUSEMOTION:
  56. pos.x = event.motion.x-RAYON;
  57. pos.y = event.motion.y-RAYON;
  58. break;
  59. } // end switch event type
  60. } // end of message processing
  61. // [3.2] Calculs
  62. // [3.3] Dessin des composants
  63. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 128, 128));
  64. SDL_BlitSurface(fond, 0, screen, 0);
  65. SDL_BlitSurface(follet, 0, screen, &pos);
  66. //blitFeuFollet(screen, xFeu, yFeu, RAYON, SDL_MapRGB(screen->format,0,0,255),opacite);
  67. SDL_Flip(screen);
  68. } //fin bcl principale
  69. ///[4] Destruction des composants
  70. SDL_FreeSurface(fond);
  71. SDL_FreeSurface(follet);
  72. std::cout << "Aucune erreur détectée." << std::endl;
  73. return 0;
  74. }