Advertisement
Guest User

Untitled

a guest
Apr 13th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. // Snooping through the files are we?
  2.  
  3. // Compile With: g++ main.cpp loadImage.h -lSDL2 -lSDL2_image -o "Butter Game"
  4.  
  5. #include <iostream>
  6. #include <SDL2/SDL.h>
  7. #include <SDL2/SDL_image.h>
  8.  
  9. #include "loadImage.h"
  10.  
  11. #define CENTER 0
  12.  
  13. SDL_Window* window;
  14. SDL_Renderer* renderer;
  15.  
  16. bool running;
  17.  
  18. bool fullscreen = false;
  19.  
  20. const char* mainMenuBackground = "Assets/Backgrounds/main_menu.png";
  21. const char* playButton = "Assets/Sprites/play_button.png";
  22. const char* wimpButton = "Assets/Sprites/wimp_button.png";
  23.  
  24. void createHDWindow()
  25. {
  26. SDL_Init(SDL_INIT_EVERYTHING);
  27. IMG_Init(IMG_INIT_PNG);
  28.  
  29. window = SDL_CreateWindow("Butter Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_SHOWN);
  30. renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
  31. }
  32.  
  33. void quit()
  34. {
  35. SDL_DestroyTexture(imageSlot1);
  36. SDL_DestroyTexture(imageSlot2);
  37. SDL_DestroyTexture(imageSlot3);
  38. SDL_DestroyTexture(imageSlot4);
  39. SDL_DestroyTexture(imageSlot5);
  40. SDL_DestroyTexture(imageSlot6);
  41. SDL_DestroyTexture(imageSlot7);
  42. SDL_DestroyTexture(imageSlot8);
  43. SDL_DestroyTexture(imageSlot9);
  44. SDL_DestroyTexture(imageSlot10);
  45.  
  46. SDL_DestroyWindow(window);
  47. SDL_DestroyRenderer(renderer);
  48.  
  49. SDL_Quit();
  50. }
  51.  
  52. void getInput()
  53. {
  54. SDL_Event event;
  55.  
  56. while(SDL_PollEvent(&event))
  57. {
  58. switch(event.type)
  59. {
  60. case SDL_KEYDOWN:
  61. switch(event.key.keysym.sym)
  62. {
  63. case SDLK_F4:
  64. if(fullscreen)
  65. {
  66. SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
  67. std::cout << "Not Fullscreen" << std::endl;
  68. fullscreen = false;
  69. }
  70. else if(!fullscreen)
  71. {
  72. SDL_SetWindowFullscreen(window, 0);
  73. std::cout << "Fullscreen" << std::endl;
  74. fullscreen = true;
  75. }
  76.  
  77. break;
  78. }
  79. break;
  80.  
  81. case SDL_QUIT:
  82. quit();
  83. break;
  84. break;
  85. }
  86. }
  87. }
  88.  
  89. void queueVisualEvents()
  90. {
  91. loadImage(mainMenuBackground, 0, 0, 1920, 1080);
  92. loadImage(playButton, 1400, 270, 340, 170);
  93. }
  94.  
  95. void renderScreen()
  96. {
  97. SDL_RenderClear(renderer);
  98.  
  99. if(imageSlot1){SDL_RenderCopy(renderer, imageSlot1, NULL, &imageRect1);}
  100. if(imageSlot2){SDL_RenderCopy(renderer, imageSlot2, NULL, &imageRect2);}
  101. if(imageSlot3){SDL_RenderCopy(renderer, imageSlot3, NULL, &imageRect3);}
  102. if(imageSlot4){SDL_RenderCopy(renderer, imageSlot4, NULL, &imageRect4);}
  103. if(imageSlot5){SDL_RenderCopy(renderer, imageSlot5, NULL, &imageRect5);}
  104. if(imageSlot6){SDL_RenderCopy(renderer, imageSlot6, NULL, &imageRect6);}
  105. if(imageSlot7){SDL_RenderCopy(renderer, imageSlot7, NULL, &imageRect7);}
  106. if(imageSlot8){SDL_RenderCopy(renderer, imageSlot8, NULL, &imageRect8);}
  107. if(imageSlot9){SDL_RenderCopy(renderer, imageSlot9, NULL, &imageRect9);}
  108. if(imageSlot10){SDL_RenderCopy(renderer, imageSlot10, NULL, &imageRect10);}
  109.  
  110. SDL_RenderPresent(renderer);
  111. }
  112.  
  113. int main()
  114. {
  115. running = true;
  116.  
  117. createHDWindow();
  118.  
  119. while(running)
  120. {
  121. getInput();
  122. queueVisualEvents();
  123. renderScreen();
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement