SDL SPOOKY PLATFORMER ENGINE  0.2.0
An implementation of a platformer using sdl, implemented using an entity component system and efficient collision management.
SpriteManager.hpp
Go to the documentation of this file.
1 #ifndef SPRITE_MANAGER_HPP
2 #define SPRITE_MANAGER_HPP
3 
4 #include <SDL2/SDL.h>
5 #include <ResourceManager.hpp>
6 
10 class SpriteManager : public ResourceManager<SpriteManager, Sprite>
11 {
12 public:
17  {
18  static SpriteManager *instance = new SpriteManager();
19  return *instance;
20  }
21 
27  int startUp(SDL_Renderer *in)
28  {
29  ren = in;
30  fileMap.emplace("character_dark_blue", "./Assets/sprites/character_dark_blue.bmp");
31  fileMap.emplace("character_blue", "./Assets/sprites/character_blue.bmp");
32  fileMap.emplace("sprite", "./Assets/sprites/sprite.bmp");
33  fileMap.emplace("ghost_left", "./Assets/sprites/ghost_left.bmp");
34  fileMap.emplace("ghost_right", "./Assets/sprites/ghost_right.bmp");
35  return 1;
36  }
37 
43  std::shared_ptr<Sprite> Load(const std::string &path)
44  {
45 
46  std::shared_ptr<SDL_Surface> surface = std::shared_ptr<SDL_Surface>(SDL_LoadBMP(path.data()), SDL_FreeSurface);
47 
48  if (surface == NULL)
49  {
50  SDL_Log("Failed to allocate surface");
51  return NULL;
52  }
53  else
54  {
55  SDL_Log("Allocated a bunch of memory to create identical game character");
56  // Create a texture from our surface
57  // Textures run faster and take advantage of hardware acceleration
58  std::shared_ptr<Sprite> s = std::make_shared<Sprite>();
59  s->spriteSheet = surface;
60  s->texture = std::shared_ptr<SDL_Texture>(SDL_CreateTextureFromSurface(ren, surface.get()), SDL_DestroyTexture);
61  return s;
62  }
63  }
64 
65 private:
66  SDL_Renderer *ren;
67 };
68 
69 #endif
std::shared_ptr< Sprite > Load(const std::string &path)
Definition: SpriteManager.hpp:43
std::map< std::string, std::string > fileMap
stores location of resources
Definition: ResourceManager.hpp:156
int startUp(SDL_Renderer *in)
Definition: SpriteManager.hpp:27
static SpriteManager & instance()
Definition: SpriteManager.hpp:16
Definition: ResourceManager.hpp:62
Definition: SpriteManager.hpp:10