-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetManager.cpp
More file actions
69 lines (58 loc) · 2.05 KB
/
AssetManager.cpp
File metadata and controls
69 lines (58 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "AssetManager.hpp"
#include "ECS/Components.hpp"
AssetManager::AssetManager(Manager* man) : manager(man)
{
}
AssetManager::~AssetManager()
{
}
void AssetManager::CreateWall(Vector2D pos, int width, int height, std::string id)
{
auto& wall(manager->addEntity());
wall.addComponent<TransformComponent>(pos.x, pos.y, width, height, 1);
wall.addComponent<SpriteComponent>(id);
wall.addComponent<ColliderComponent>("Wall");
wall.addGroup(Game::groupMap);
}
void AssetManager::CreateEnemy(Vector2D pos, int width, int height, std::string id)
{
auto& enemy(manager->addEntity());
enemy.addComponent<TransformComponent>(pos.x, pos.y, width, height, 2);
enemy.addComponent<SpriteComponent>(id, 2, 60);
enemy.addComponent<ColliderComponent>("Enemy");
enemy.addGroup(Game::groupEnemies);
}
void AssetManager::CreatePlayerProjectile(Vector2D pos, Vector2D velocity, std::string tag)
{
auto& projectile(manager->addEntity());
projectile.addComponent<TransformComponent>(pos.x, pos.y, 2, 8, 1);
projectile.addComponent<SpriteComponent>("Projectile_E");
projectile.addComponent<ProjectileComponent>(velocity);
projectile.addComponent<ColliderComponent>(tag);
projectile.addGroup(Game::groupPlayerProjectiles);
}
void AssetManager::CreateEnemyProjectile(Vector2D pos, Vector2D velocity, std::string tag)
{
auto& projectile(manager->addEntity());
projectile.addComponent<TransformComponent>(pos.x, pos.y, 2, 8, 1);
projectile.addComponent<SpriteComponent>("Projectile_P");
projectile.addComponent<ProjectileComponent>(velocity);
projectile.addComponent<ColliderComponent>(tag);
projectile.addGroup(Game::groupEnemyProjectiles);
}
void AssetManager::AddTexture(std::string id, const char* path)
{
textures.emplace(id, TextureManager::LoadTexture(path));
}
SDL_Texture* AssetManager::GetTexture(std::string id)
{
return textures[id];
}
void AssetManager::AddFont(std::string id, std::string path, int fontSize)
{
fonts.emplace(id, TTF_OpenFont(path.c_str(), fontSize));
}
TTF_Font* AssetManager::GetFont(std::string id)
{
return fonts[id];
}