Guest User

Untitled

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