Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Snooping through the files now are we?
- // Compile With: g++ main.cpp loadImage.h playSound.h -lSDL2 -lSDL2_image -lSDL2_mixer -Wall -o "Butter Game"
- #include <SDL2/SDL.h>
- #include <SDL2/SDL_image.h>
- #include <iostream>
- 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;
- SDL_Rect hitbox1;
- SDL_Rect hitbox2;
- SDL_Rect hitbox3;
- SDL_Rect hitbox4;
- SDL_Rect hitbox5;
- SDL_Rect hitbox6;
- SDL_Rect hitbox7;
- SDL_Rect hitbox8;
- SDL_Rect hitbox9;
- SDL_Rect hitbox10;
- SDL_Rect hitbox11;
- SDL_Rect hitbox12;
- SDL_Rect hitbox13;
- SDL_Rect hitbox14;
- SDL_Rect hitbox15;
- SDL_Rect hitbox16;
- SDL_Rect hitbox17;
- SDL_Rect hitbox18;
- SDL_Rect hitbox19;
- SDL_Rect hitbox20;
- int hitboxIndex = 1;
- int imageIndex = 1;
- extern SDL_Renderer* renderer;
- extern void deleteButtons();
- int loadImage(const char* path, int posX, int posY, int sizeX, int sizeY)
- {
- if(imageIndex > 10)
- {
- imageIndex = 1;
- }
- 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++;
- std::cout << "imageIndex 1 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 2 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 3 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 4 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 5 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 6 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 7 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 8 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 9 loaded." << std::endl;
- 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++;
- std::cout << "imageIndex 10 loaded." << std::endl;
- break;
- }
- return imageIndex;
- }
- void loadSpecificImageSlot(const char* path, int posX, int posY, int sizeX, int sizeY, int imageSlot)
- {
- switch(imageSlot)
- {
- 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++;
- 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++;
- 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++;
- 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++;
- 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++;
- 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++;
- 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++;
- 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++;
- 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++;
- 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++;
- 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 createHitbox(int posX, int posY, int width, int height)
- {
- switch(hitboxIndex)
- {
- case 1:
- hitbox1.x = posX;
- hitbox1.y = posY;
- hitbox1.w = width;
- hitbox1.h = height;
- break;
- case 2:
- hitbox2.x = posX;
- hitbox2.y = posY;
- hitbox2.w = width;
- hitbox2.h = height;
- break;
- case 3:
- hitbox3.x = posX;
- hitbox3.y = posY;
- hitbox3.w = width;
- hitbox1.h = height;
- break;
- case 4:
- hitbox4.x = posX;
- hitbox4.y = posY;
- hitbox4.w = width;
- hitbox4.h = height;
- break;
- case 5:
- hitbox5.x = posX;
- hitbox5.y = posY;
- hitbox5.w = width;
- hitbox5.h = height;
- break;
- case 6:
- hitbox6.x = posX;
- hitbox6.y = posY;
- hitbox6.w = width;
- hitbox6.h = height;
- break;
- case 7:
- hitbox7.x = posX;
- hitbox7.y = posY;
- hitbox7.w = width;
- hitbox7.h = height;
- break;
- case 8:
- hitbox8.x = posX;
- hitbox8.y = posY;
- hitbox8.w = width;
- hitbox8.h = height;
- break;
- case 9:
- hitbox9.x = posX;
- hitbox9.y = posY;
- hitbox9.w = width;
- hitbox9.h = height;
- break;
- case 10:
- hitbox10.x = posX;
- hitbox10.y = posY;
- hitbox10.w = width;
- hitbox10.h = height;
- break;
- case 11:
- hitbox11.x = posX;
- hitbox11.y = posY;
- hitbox11.w = width;
- hitbox11.h = height;
- break;
- case 12:
- hitbox12.x = posX;
- hitbox12.y = posY;
- hitbox12.w = width;
- hitbox12.h = height;
- break;
- case 13:
- hitbox13.x = posX;
- hitbox13.y = posY;
- hitbox13.w = width;
- hitbox13.h = height;
- break;
- case 14:
- hitbox14.x = posX;
- hitbox14.y = posY;
- hitbox14.w = width;
- hitbox14.h = height;
- break;
- case 15:
- hitbox15.x = posX;
- hitbox15.y = posY;
- hitbox15.w = width;
- hitbox15.h = height;
- break;
- case 16:
- hitbox16.x = posX;
- hitbox16.y = posY;
- hitbox16.w = width;
- hitbox16.h = height;
- break;
- case 17:
- hitbox17.x = posX;
- hitbox17.y = posY;
- hitbox17.w = width;
- hitbox17.h = height;
- break;
- case 18:
- hitbox18.x = posX;
- hitbox18.y = posY;
- hitbox18.w = width;
- hitbox18.h = height;
- break;
- case 19:
- hitbox19.x = posX;
- hitbox19.y = posY;
- hitbox19.w = width;
- hitbox19.h = height;
- break;
- case 20:
- hitbox20.x = posX;
- hitbox20.y = posY;
- hitbox20.w = width;
- hitbox20.h = height;
- break;
- }
- }
- void clearScene()
- {
- imageIndex = 1;
- freeImageSlot(1);
- freeImageSlot(2);
- freeImageSlot(3);
- freeImageSlot(4);
- freeImageSlot(5);
- freeImageSlot(6);
- freeImageSlot(7);
- freeImageSlot(8);
- freeImageSlot(9);
- freeImageSlot(10);
- deleteButtons();
- }
Add Comment
Please, Sign In to add comment