main.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <cstdlib>
  2. #include <SDL/SDL.h>
  3. #undef main
  4. #include "LaunchCircle.h"
  5. int main ( int argc, char** argv )
  6. {
  7. // [1] Initialisation des SDL
  8. if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 )
  9. {
  10. printf( "Unable to init SDL: %s\n", SDL_GetError() );
  11. return 1;
  12. }
  13. // make sure SDL cleans up before exit
  14. atexit(SDL_Quit);
  15. // create a new window
  16. SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
  17. SDL_HWSURFACE|SDL_DOUBLEBUF);
  18. if ( !screen )
  19. {
  20. printf("Unable to set 640x480 video: %s\n", SDL_GetError());
  21. return 1;
  22. }
  23. // [2] création des composants
  24. LaunchCircle cercle(200, SDL_MapRGB(screen->format,255,128,0), 360, 150);
  25. int verrou(0);
  26. bool up(false);
  27. bool down(false);
  28. // [3] program main loop
  29. bool done = false;
  30. while (!done)
  31. {
  32. // message processing loop
  33. SDL_Event event;
  34. // check for messages
  35. while(SDL_PollEvent(&event))
  36. {
  37. switch (event.type)
  38. {
  39. // exit if the window is closed
  40. case SDL_QUIT:
  41. done = true;
  42. break;
  43. // check for keypresses
  44. case SDL_KEYDOWN:
  45. {
  46. // exit if ESCAPE is pressed
  47. if (event.key.keysym.sym == SDLK_ESCAPE)
  48. done = true;
  49. if(event.key.keysym.sym == SDLK_UP)
  50. up=true;
  51. if(event.key.keysym.sym == SDLK_DOWN)
  52. down=true;
  53. break;
  54. }
  55. case SDL_KEYUP:
  56. {
  57. if(event.key.keysym.sym == SDLK_UP)
  58. up=false;
  59. if(event.key.keysym.sym == SDLK_DOWN)
  60. down=false;
  61. break;
  62. }
  63. } // end switch
  64. }//End message processing
  65. // [4] Calculs
  66. if (up)
  67. verrou++;
  68. if(down)
  69. verrou--;
  70. // [5] DRAWING STARTS HERE
  71. // clear screen
  72. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 140, 128, 128));
  73. cercle.afficher(320,240,verrou,screen);
  74. // draw bitmap
  75. // DRAWING ENDS HERE
  76. // finally, update the screen :)
  77. SDL_Flip(screen);
  78. } // end main loop
  79. // all is well ;)
  80. printf("Exited cleanly\n");
  81. return 0;
  82. }