Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Snooping through the files now aren't you?
- // Compile With: g++ main.cpp loadImage.h -lSDL2 -lSDL2_image -o "Butter Game"
- #include <SDL2/SDL.h>
- #include <SDL2/SDL_image.h>
- SDL_Texture* imageSlot1;
- SDL_Texture* imageSlot2;
- SDL_Texture* imageSlot3;
- SDL_Texture* imageSlot4;
- SDL_Texture* imageSlot5;
- SDL_Texture* imageSlot6;
- SDL_Texture* imageSlot7;
- SDL_Texture* imageSlot8;
- SDL_Texture* imageSlot9;
- SDL_Texture* imageSlot10;
- SDL_Rect imageRect1;
- SDL_Rect imageRect2;
- SDL_Rect imageRect3;
- SDL_Rect imageRect4;
- SDL_Rect imageRect5;
- SDL_Rect imageRect6;
- SDL_Rect imageRect7;
- SDL_Rect imageRect8;
- SDL_Rect imageRect9;
- SDL_Rect imageRect10;
- bool imageSlot1Taken = false;
- bool imageSlot2Taken = false;
- bool imageSlot3Taken = false;
- bool imageSlot4Taken = false;
- bool imageSlot5Taken = false;
- bool imageSlot6Taken = false;
- bool imageSlot7Taken = false;
- bool imageSlot8Taken = false;
- bool imageSlot9Taken = false;
- bool imageSlot10Taken = false;
- int imageIndex = 1;
- extern SDL_Renderer* renderer;
- void loadImage(const char* path, int posX, int posY, int sizeX, int sizeY)
- {
- switch(imageIndex)
- {
- case 1:
- imageRect1.x = posX;
- imageRect1.y = posY;
- imageRect1.w = sizeX;
- imageRect1.h = sizeY;
- SDL_Surface* surface1;
- surface1 = IMG_Load(path);
- imageSlot1 = SDL_CreateTextureFromSurface(renderer, surface1);
- SDL_FreeSurface(surface1);
- imageIndex++;
- imageSlot1Taken = true;
- break;
- case 2:
- imageRect2.x = posX;
- imageRect2.y = posY;
- imageRect2.w = sizeX;
- imageRect2.h = sizeY;
- SDL_Surface* surface2;
- surface2 = IMG_Load(path);
- imageSlot2 = SDL_CreateTextureFromSurface(renderer, surface2);
- SDL_FreeSurface(surface2);
- imageIndex++;
- imageSlot2Taken = true;
- break;
- case 3:
- imageRect3.x = posX;
- imageRect3.y = posY;
- imageRect3.w = sizeX;
- imageRect3.h = sizeY;
- SDL_Surface* surface3;
- surface3 = IMG_Load(path);
- imageSlot3 = SDL_CreateTextureFromSurface(renderer, surface3);
- SDL_FreeSurface(surface3);
- imageIndex++;
- imageSlot3Taken = true;
- break;
- case 4:
- imageRect4.x = posX;
- imageRect4.y = posY;
- imageRect4.w = sizeX;
- imageRect4.h = sizeY;
- SDL_Surface* surface4;
- surface4 = IMG_Load(path);
- imageSlot4 = SDL_CreateTextureFromSurface(renderer, surface4);
- SDL_FreeSurface(surface4);
- imageIndex++;
- imageSlot4Taken = true;
- break;
- case 5:
- imageRect5.x = posX;
- imageRect5.y = posY;
- imageRect5.w = sizeX;
- imageRect5.h = sizeY;
- SDL_Surface* surface5;
- surface5 = IMG_Load(path);
- imageSlot5 = SDL_CreateTextureFromSurface(renderer, surface5);
- SDL_FreeSurface(surface5);
- imageIndex++;
- imageSlot5Taken = true;
- break;
- case 6:
- imageRect6.x = posX;
- imageRect6.y = posY;
- imageRect6.w = sizeX;
- imageRect6.h = sizeY;
- SDL_Surface* surface6;
- surface6 = IMG_Load(path);
- imageSlot6 = SDL_CreateTextureFromSurface(renderer, surface6);
- SDL_FreeSurface(surface6);
- imageIndex++;
- imageSlot6Taken = true;
- break;
- case 7:
- imageRect7.x = posX;
- imageRect7.y = posY;
- imageRect7.w = sizeX;
- imageRect7.h = sizeY;
- SDL_Surface* surface7;
- surface7 = IMG_Load(path);
- imageSlot7 = SDL_CreateTextureFromSurface(renderer, surface7);
- SDL_FreeSurface(surface7);
- imageIndex++;
- imageSlot7Taken = true;
- break;
- case 8:
- imageRect8.x = posX;
- imageRect8.y = posY;
- imageRect8.w = sizeX;
- imageRect8.h = sizeY;
- SDL_Surface* surface8;
- surface8 = IMG_Load(path);
- imageSlot8 = SDL_CreateTextureFromSurface(renderer, surface8);
- SDL_FreeSurface(surface8);
- imageIndex++;
- imageSlot8Taken = true;
- break;
- case 9:
- imageRect9.x = posX;
- imageRect9.y = posY;
- imageRect9.w = sizeX;
- imageRect9.h = sizeY;
- SDL_Surface* surface9;
- surface9 = IMG_Load(path);
- imageSlot9 = SDL_CreateTextureFromSurface(renderer, surface9);
- SDL_FreeSurface(surface9);
- imageIndex++;
- imageSlot9Taken = true;
- break;
- case 10:
- imageRect10.x = posX;
- imageRect10.y = posY;
- imageRect10.w = sizeX;
- imageRect10.h = sizeY;
- SDL_Surface* surface10;
- surface10 = IMG_Load(path);
- imageSlot10 = SDL_CreateTextureFromSurface(renderer, surface10);
- SDL_FreeSurface(surface10);
- imageIndex++;
- imageSlot10Taken = true;
- break;
- }
- }
- void freeImageSlot(int imageSlot)
- {
- switch(imageSlot)
- {
- case 1:
- SDL_DestroyTexture(imageSlot1);
- break;
- case 2:
- SDL_DestroyTexture(imageSlot2);
- break;
- case 3:
- SDL_DestroyTexture(imageSlot3);
- break;
- case 4:
- SDL_DestroyTexture(imageSlot4);
- break;
- case 5:
- SDL_DestroyTexture(imageSlot5);
- break;
- case 6:
- SDL_DestroyTexture(imageSlot6);
- break;
- case 7:
- SDL_DestroyTexture(imageSlot7);
- break;
- case 8:
- SDL_DestroyTexture(imageSlot8);
- break;
- case 9:
- SDL_DestroyTexture(imageSlot9);
- break;
- case 10:
- SDL_DestroyTexture(imageSlot10);
- break;
- }
- }
- void clearScene()
- {
- freeImageSlot(1);
- freeImageSlot(2);
- freeImageSlot(3);
- freeImageSlot(4);
- freeImageSlot(5);
- freeImageSlot(6);
- freeImageSlot(7);
- freeImageSlot(8);
- freeImageSlot(9);
- freeImageSlot(10);
- }
Add Comment
Please, Sign In to add comment