Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
AssetManager.h
1#ifndef _BOMBERMAN_MANAGERS_ASSET_MANAGER_H_
2#define _BOMBERMAN_MANAGERS_ASSET_MANAGER_H_
3
4#include <SDL.h>
5#include <SDL_mixer.h>
6#include <SDL_ttf.h>
7#include <memory>
8#include <string>
9#include <unordered_map>
10
11namespace bomberman
12{
18 enum class Texture : int
19 {
20 MenuBack,
21 Stone,
22 Grass,
23 Brick,
24 Player,
25 Enemy1,
26 Enemy2,
27 Enemy3,
28 Bomb,
29 BombSpark,
30 Explosion,
31 Door,
32 PowerupSpeed,
33 PowerupInvincible,
34 PowerupRange,
35 PowerupBombs
36 };
41 enum class MusicEnum : int
42 {
43 MainMenu,
44 Level
45 };
50 enum class SoundEnum : int
51 {
52 Win,
53 Lose,
54 Explosion
55 };
61 {
62 template<typename T> std::size_t operator()(T t) const
63 {
64 return static_cast<std::size_t>(t);
65 }
66 };
67
73 {
74 public:
80 void load(SDL_Renderer* renderer);
86 std::shared_ptr<TTF_Font> getFont() const;
95 std::shared_ptr<TTF_Font> getFont(int pointSize) const;
103 std::shared_ptr<SDL_Texture> getTexture(Texture texture);
110 std::shared_ptr<Mix_Music> getMusic(MusicEnum music);
117 std::shared_ptr<Mix_Chunk> getSound(SoundEnum sound);
118
119 private:
124 void loadFont();
132 void loadTexture(SDL_Renderer* renderer, Texture texture, const std::string& filePath);
139 void loadMusic(MusicEnum music, const std::string& filePath);
146 void loadSound(SoundEnum sound, const std::string& filePath);
147
148 std::shared_ptr<TTF_Font> font = nullptr; // font
149 std::string fontPath_; // path used to load font, for sized variants
150 std::unordered_map<Texture, std::shared_ptr<SDL_Texture>, EnumClassHash> textures; // map of textures
151 std::unordered_map<MusicEnum, std::shared_ptr<Mix_Music>, EnumClassHash> musics; // map of music
152 std::unordered_map<SoundEnum, std::shared_ptr<Mix_Chunk>, EnumClassHash> sounds; // map of sounds
153 };
154} // namespace bomberman
155
156#endif // _BOMBERMAN_MANAGERS_ASSET_MANAGER_H_
Asset Manager.
Definition AssetManager.h:73
std::shared_ptr< Mix_Chunk > getSound(SoundEnum sound)
Get sound.
Definition AssetManager.cpp:57
void load(SDL_Renderer *renderer)
Load assets.
Definition AssetManager.cpp:8
std::shared_ptr< TTF_Font > getFont() const
Get font at its default loaded point size.
Definition AssetManager.cpp:42
std::shared_ptr< SDL_Texture > getTexture(Texture texture)
Get textures.
Definition AssetManager.cpp:47
std::shared_ptr< Mix_Music > getMusic(MusicEnum music)
Get music.
Definition AssetManager.cpp:52
Hash for Texture enum.
Definition AssetManager.h:61