#ifndef GAMERESOURCES_H #define GAMERESOURCES_H #include #include #include class GameResources{ public: GameResources(); struct{ int runningFrames; int distancePerRunningFrame; SDL_Surface * running[4]; SDL_Surface * standing[4]; } dudes [4]; SDL_Surface * tiles[2]; private: SDL_Surface * load_and_set(const char *bump); SDL_Surface *load_and_set_Alpha(const char *bump); }; #endif #include "gameresources.h" #include "SDL_image.h" #include #include GameResources::GameResources() { dudes[0] = {2, 3, { load_and_set_Alpha("data/mobiles/bomberdude/blueduderunup.png"), load_and_set_Alpha("data/mobiles/bomberdude/blueduderundown.png"), load_and_set_Alpha("data/mobiles/bomberdude/blueduderunleft.png"), load_and_set_Alpha("data/mobiles/bomberdude/blueduderunright.png") }, { load_and_set_Alpha("data/mobiles/bomberdude/blueup.png"), load_and_set_Alpha("data/mobiles/bomberdude/bluedown.png"), load_and_set_Alpha("data/mobiles/bomberdude/blueleft.png"), load_and_set_Alpha("data/mobiles/bomberdude/blueright.png") } }; dudes[1].runningFrames = 2; dudes[2].runningFrames = 2; dudes[3].runningFrames = 2; } SDL_Surface * GameResources::load_and_set(const char *bump) { SDL_Surface *temp = IMG_Load(bump); if (temp == NULL) throw std::string("Unable to load bitmap."); SDL_Surface *image = SDL_DisplayFormat(temp); if (image == NULL) throw std::string("Unable to convert the bitmap."); Uint32 colorkey = SDL_MapRGB(image->format, 255, 0, 255); SDL_SetColorKey(image, (SDL_SRCCOLORKEY | SDL_RLEACCEL), colorkey); SDL_FreeSurface(temp); return image; } SDL_Surface * GameResources::load_and_set_Alpha(const char *bump) { std::cout << "Loading an alpha image \n"; std::cout.flush(); SDL_Surface *temp = IMG_Load(bump); std::cout << "Alpha image loaded\n"; std::cout.flush(); if (temp == NULL) throw std::string("Unable to load bitmap."); SDL_SetAlpha(temp, SDL_SRCALPHA, 0); Uint32 colorkey = SDL_MapRGB(temp->format, 255, 0, 255); SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL), colorkey); SDL_Surface *image = SDL_DisplayFormatAlpha(temp); if (image == NULL) throw std::string("Unable to convert the bitmap."); SDL_FreeSurface(temp); return image; }