Advertisement
Guest User

Untitled

a guest
Apr 14th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. // Snooping through the files now are we?
  2.  
  3. // Compile With: g++ main.cpp loadImage.h playSound.h -lSDL2 -lSDL2_image -lSDL2_mixer -o "Butter Game"
  4.  
  5. #include <SDL2/SDL.h>
  6. #include <SDL2/SDL_image.h>
  7.  
  8. SDL_Texture* imageSlot1;
  9. SDL_Texture* imageSlot2;
  10. SDL_Texture* imageSlot3;
  11. SDL_Texture* imageSlot4;
  12. SDL_Texture* imageSlot5;
  13. SDL_Texture* imageSlot6;
  14. SDL_Texture* imageSlot7;
  15. SDL_Texture* imageSlot8;
  16. SDL_Texture* imageSlot9;
  17. SDL_Texture* imageSlot10;
  18.  
  19. SDL_Rect imageRect1;
  20. SDL_Rect imageRect2;
  21. SDL_Rect imageRect3;
  22. SDL_Rect imageRect4;
  23. SDL_Rect imageRect5;
  24. SDL_Rect imageRect6;
  25. SDL_Rect imageRect7;
  26. SDL_Rect imageRect8;
  27. SDL_Rect imageRect9;
  28. SDL_Rect imageRect10;
  29.  
  30. int imageIndex = 1;
  31.  
  32. extern SDL_Renderer* renderer;
  33. extern void deleteButtons();
  34.  
  35. void loadImage(const char* path, int posX, int posY, int sizeX, int sizeY)
  36. {
  37. switch(imageIndex)
  38. {
  39. case 1:
  40. imageRect1.x = posX;
  41. imageRect1.y = posY;
  42. imageRect1.w = sizeX;
  43. imageRect1.h = sizeY;
  44.  
  45. SDL_Surface* surface1;
  46.  
  47. surface1 = IMG_Load(path);
  48.  
  49. imageSlot1 = SDL_CreateTextureFromSurface(renderer, surface1);
  50.  
  51. SDL_FreeSurface(surface1);
  52.  
  53. imageIndex++;
  54.  
  55. break;
  56. case 2:
  57. imageRect2.x = posX;
  58. imageRect2.y = posY;
  59. imageRect2.w = sizeX;
  60. imageRect2.h = sizeY;
  61.  
  62. SDL_Surface* surface2;
  63.  
  64. surface2 = IMG_Load(path);
  65.  
  66. imageSlot2 = SDL_CreateTextureFromSurface(renderer, surface2);
  67.  
  68. SDL_FreeSurface(surface2);
  69.  
  70. imageIndex++;
  71.  
  72. break;
  73. case 3:
  74. imageRect3.x = posX;
  75. imageRect3.y = posY;
  76. imageRect3.w = sizeX;
  77. imageRect3.h = sizeY;
  78.  
  79. SDL_Surface* surface3;
  80.  
  81. surface3 = IMG_Load(path);
  82.  
  83. imageSlot3 = SDL_CreateTextureFromSurface(renderer, surface3);
  84.  
  85. SDL_FreeSurface(surface3);
  86.  
  87. imageIndex++;
  88.  
  89. break;
  90. case 4:
  91. imageRect4.x = posX;
  92. imageRect4.y = posY;
  93. imageRect4.w = sizeX;
  94. imageRect4.h = sizeY;
  95.  
  96. SDL_Surface* surface4;
  97.  
  98. surface4 = IMG_Load(path);
  99.  
  100. imageSlot4 = SDL_CreateTextureFromSurface(renderer, surface4);
  101.  
  102. SDL_FreeSurface(surface4);
  103.  
  104. imageIndex++;
  105.  
  106. break;
  107. case 5:
  108. imageRect5.x = posX;
  109. imageRect5.y = posY;
  110. imageRect5.w = sizeX;
  111. imageRect5.h = sizeY;
  112.  
  113. SDL_Surface* surface5;
  114.  
  115. surface5 = IMG_Load(path);
  116.  
  117. imageSlot5 = SDL_CreateTextureFromSurface(renderer, surface5);
  118.  
  119. SDL_FreeSurface(surface5);
  120.  
  121. imageIndex++;
  122.  
  123. break;
  124. case 6:
  125. imageRect6.x = posX;
  126. imageRect6.y = posY;
  127. imageRect6.w = sizeX;
  128. imageRect6.h = sizeY;
  129.  
  130. SDL_Surface* surface6;
  131.  
  132. surface6 = IMG_Load(path);
  133.  
  134. imageSlot6 = SDL_CreateTextureFromSurface(renderer, surface6);
  135.  
  136. SDL_FreeSurface(surface6);
  137.  
  138. imageIndex++;
  139.  
  140. break;
  141. case 7:
  142. imageRect7.x = posX;
  143. imageRect7.y = posY;
  144. imageRect7.w = sizeX;
  145. imageRect7.h = sizeY;
  146.  
  147. SDL_Surface* surface7;
  148.  
  149. surface7 = IMG_Load(path);
  150.  
  151. imageSlot7 = SDL_CreateTextureFromSurface(renderer, surface7);
  152.  
  153. SDL_FreeSurface(surface7);
  154.  
  155. imageIndex++;
  156.  
  157. break;
  158. case 8:
  159. imageRect8.x = posX;
  160. imageRect8.y = posY;
  161. imageRect8.w = sizeX;
  162. imageRect8.h = sizeY;
  163.  
  164. SDL_Surface* surface8;
  165.  
  166. surface8 = IMG_Load(path);
  167.  
  168. imageSlot8 = SDL_CreateTextureFromSurface(renderer, surface8);
  169.  
  170. SDL_FreeSurface(surface8);
  171.  
  172. imageIndex++;
  173.  
  174. break;
  175. case 9:
  176. imageRect9.x = posX;
  177. imageRect9.y = posY;
  178. imageRect9.w = sizeX;
  179. imageRect9.h = sizeY;
  180.  
  181. SDL_Surface* surface9;
  182.  
  183. surface9 = IMG_Load(path);
  184.  
  185. imageSlot9 = SDL_CreateTextureFromSurface(renderer, surface9);
  186.  
  187. SDL_FreeSurface(surface9);
  188.  
  189. imageIndex++;
  190.  
  191. break;
  192. case 10:
  193. imageRect10.x = posX;
  194. imageRect10.y = posY;
  195. imageRect10.w = sizeX;
  196. imageRect10.h = sizeY;
  197.  
  198. SDL_Surface* surface10;
  199.  
  200. surface10 = IMG_Load(path);
  201.  
  202. imageSlot10 = SDL_CreateTextureFromSurface(renderer, surface10);
  203.  
  204. SDL_FreeSurface(surface10);
  205.  
  206. imageIndex++;
  207.  
  208. break;
  209. }
  210. }
  211.  
  212. void freeImageSlot(int imageSlot)
  213. {
  214. switch(imageSlot)
  215. {
  216. case 1:
  217. SDL_DestroyTexture(imageSlot1);
  218. break;
  219. case 2:
  220. SDL_DestroyTexture(imageSlot2);
  221. break;
  222. case 3:
  223. SDL_DestroyTexture(imageSlot3);
  224. break;
  225. case 4:
  226. SDL_DestroyTexture(imageSlot4);
  227. break;
  228. case 5:
  229. SDL_DestroyTexture(imageSlot5);
  230. break;
  231. case 6:
  232. SDL_DestroyTexture(imageSlot6);
  233. break;
  234. case 7:
  235. SDL_DestroyTexture(imageSlot7);
  236. break;
  237. case 8:
  238. SDL_DestroyTexture(imageSlot8);
  239. break;
  240. case 9:
  241. SDL_DestroyTexture(imageSlot9);
  242. break;
  243. case 10:
  244. SDL_DestroyTexture(imageSlot10);
  245. break;
  246. }
  247. }
  248.  
  249. void clearScene()
  250. {
  251. freeImageSlot(1);
  252. freeImageSlot(2);
  253. freeImageSlot(3);
  254. freeImageSlot(4);
  255. freeImageSlot(5);
  256. freeImageSlot(6);
  257. freeImageSlot(7);
  258. freeImageSlot(8);
  259. freeImageSlot(9);
  260. freeImageSlot(10);
  261.  
  262. deleteButtons();
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement