ritle.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <SDL2/SDL.h>
  2. #include <SDL2/SDL_image.h>
  3. #include "Menu.h"
  4. #include "MenuMain.h"
  5. #include "MenuExtra.h"
  6. //Screen
  7. const int WIDTH = 640;
  8. const int HEIGHT = 480;
  9. int main( int argc, char* args[])
  10. {
  11. //Rendering window
  12. SDL_Window* window = NULL;
  13. SDL_Surface* screen = NULL;
  14. //Initialize SDL
  15. if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) return -1;
  16. //Create window
  17. window = SDL_CreateWindow( "Ritle", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN );
  18. if (window == NULL) return -1;
  19. //Initialize PNG
  20. if ( !(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) ) return -1;
  21. //Create screen
  22. screen = SDL_GetWindowSurface( window );
  23. //Menu
  24. //Background background = new Background;
  25. Menu* menu = new MenuMain;
  26. menu->initialize();
  27. //Main loop
  28. bool running = true;
  29. SDL_Event e;
  30. while (running)
  31. {
  32. //Input
  33. while (SDL_PollEvent(&e) != 0)
  34. {
  35. if (e.type == SDL_QUIT) running = false; else
  36. if (e.type == SDL_KEYDOWN)
  37. {
  38. switch (e.key.keysym.sym)
  39. {
  40. case SDLK_UP:
  41. running = false;
  42. break;
  43. case SDLK_RIGHT:
  44. menu = new MenuExtra;
  45. menu->initialize();
  46. break;
  47. }
  48. }
  49. }
  50. //Update
  51. menu->update();
  52. //Draw
  53. SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 254 ,158, 112));
  54. menu->draw(screen);
  55. SDL_UpdateWindowSurface(window);
  56. }
  57. //Close game
  58. for (int i = 0; i < 36; i++)
  59. {
  60. // SDL_FreeSurface(image[i]);
  61. // image[i] = NULL;
  62. }
  63. //Destroy window
  64. SDL_DestroyWindow( window );
  65. window = NULL;
  66. //Quit SDL
  67. SDL_Quit();
  68. return 0;
  69. }