first commit
This commit is contained in:
69
src/assetmgr/AssetManager.cpp
Normal file
69
src/assetmgr/AssetManager.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* AssetManager.cpp
|
||||
*
|
||||
* Created on: Apr 4, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#include "AssetManager.h"
|
||||
#include "../ecs/Components.h"
|
||||
#include "../ecs/ECS.h"
|
||||
|
||||
|
||||
class Manager;
|
||||
|
||||
AssetManager::AssetManager(Manager* man) : manager(man)
|
||||
{}
|
||||
|
||||
AssetManager::~AssetManager()
|
||||
{}
|
||||
|
||||
// void AssetManager::CreateProjectile(Vector2D pos, Vector2D vel, int range, int speed, std::string id)
|
||||
// {
|
||||
// auto& projectile(manager->addEntity());
|
||||
// projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1);
|
||||
// projectile.addComponent<SpriteComponent>(id);
|
||||
// projectile.addComponent<ProjectileComponent>(range,speed,vel);
|
||||
// projectile.addComponent<ColliderComponent>("projectile");
|
||||
// projectile.addGroup(Game::groupProjectiles);
|
||||
// ;}
|
||||
|
||||
//void AssetManager::CreateText(Vector2D pos, std::string textToDisplay, std::string id)
|
||||
//{
|
||||
// auto& text(manager->addEntity());
|
||||
// text.addComponent<TransformComponent>(pos.x,pos.y,32,32,1);
|
||||
//
|
||||
// text.addGroup(Game::groupUI);
|
||||
//}
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
//Sound Mixer
|
||||
//Sound Clips
|
||||
void AssetManager::AddSoundClip(std::string id, const char* path)
|
||||
{
|
||||
soundClips.emplace(id, MusicManager::LoadSound(path));
|
||||
}
|
||||
Mix_Chunk* AssetManager::GetSoundClip(std::string id)
|
||||
{
|
||||
return soundClips[id];
|
||||
}
|
||||
|
||||
//Music
|
||||
void AssetManager::AddMusicTrack(std::string id, const char* path)
|
||||
{
|
||||
musicTracks.emplace(id, MusicManager::LoadMusic(path));
|
||||
}
|
||||
Mix_Music* AssetManager::GetMusicTrack(std::string id)
|
||||
{
|
||||
return musicTracks[id];
|
||||
}
|
55
src/assetmgr/AssetManager.h
Normal file
55
src/assetmgr/AssetManager.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* AssetManager.h
|
||||
*
|
||||
* Created on: Apr 4, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_ASSETMANAGER_H_
|
||||
#define SRC_ASSETMANAGER_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "TextureManager.h"
|
||||
#include "../game/Vector2D.h"
|
||||
#include "../ecs/ECS.h"
|
||||
#include "../game/Game.hpp"
|
||||
//#include <SDL2/SDL_mixer.h>
|
||||
#include "MusicManager.h"
|
||||
|
||||
class AssetManager
|
||||
{
|
||||
public:
|
||||
AssetManager(Manager* man);
|
||||
~AssetManager();
|
||||
|
||||
|
||||
//gameobjects
|
||||
// void CreateProjectile(Vector2D pos, Vector2D vel, int range, int speed, std::string id);
|
||||
void CreateText(Vector2D pos, std::string textToDisplay, std::string id);
|
||||
|
||||
//texture management
|
||||
void AddTexture(std::string id, const char* path);
|
||||
SDL_Texture* GetTexture(std::string id);
|
||||
|
||||
//Sound Mixer
|
||||
//Sound Clips
|
||||
void AddSoundClip(std::string id, const char* path);
|
||||
Mix_Chunk* GetSoundClip(std::string id);
|
||||
|
||||
//Music
|
||||
void AddMusicTrack(std::string id, const char* path);
|
||||
Mix_Music* GetMusicTrack(std::string id);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Manager* manager;
|
||||
std::map<std::string, SDL_Texture*> textures;
|
||||
std::map<std::string, Mix_Chunk*> soundClips;
|
||||
std::map<std::string, Mix_Music*> musicTracks;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SRC_ASSETMANAGER_H_ */
|
41
src/assetmgr/GameObject.cpp
Normal file
41
src/assetmgr/GameObject.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* GameObject.cpp
|
||||
*
|
||||
* Created on: Feb 11, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#include "GameObject.h"
|
||||
#include "TextureManager.h"
|
||||
|
||||
GameObject::GameObject(const char* texturesheet, int x, int y)
|
||||
{
|
||||
|
||||
objTexture = TextureManager::LoadTexture(texturesheet);
|
||||
|
||||
xpos = x;
|
||||
ypos = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GameObject::Update()
|
||||
{
|
||||
xpos++;
|
||||
// ypos = 0;
|
||||
|
||||
srcRect.h = 40;
|
||||
srcRect.w = 30;
|
||||
srcRect.x = 0;
|
||||
srcRect.y = 0;
|
||||
|
||||
destRect.x = xpos;
|
||||
destRect.y = ypos;
|
||||
destRect.w = srcRect.w * 2;
|
||||
destRect.h = srcRect.h * 2;
|
||||
}
|
||||
|
||||
void GameObject::Render()
|
||||
{
|
||||
SDL_RenderCopy(Game::renderer, objTexture, &srcRect, &destRect);
|
||||
}
|
34
src/assetmgr/GameObject.h
Normal file
34
src/assetmgr/GameObject.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* GameObject.h
|
||||
*
|
||||
* Created on: Feb 11, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_GAMEOBJECT_H_
|
||||
#define SRC_GAMEOBJECT_H_
|
||||
|
||||
#include "../game/Game.hpp"
|
||||
|
||||
class GameObject
|
||||
{
|
||||
|
||||
public:
|
||||
GameObject(const char* texturesheet, int x, int y);
|
||||
~GameObject();
|
||||
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
private:
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
SDL_Texture* objTexture;
|
||||
SDL_Rect srcRect, destRect;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* SRC_GAMEOBJECT_H_ */
|
78
src/assetmgr/Map.cpp
Normal file
78
src/assetmgr/Map.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Map.cpp
|
||||
*
|
||||
* Created on: Feb 13, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#include "Map.h"
|
||||
#include "../game/Game.hpp"
|
||||
#include <fstream>
|
||||
#include "../ecs/ECS.h"
|
||||
#include "../ecs/Components.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
extern Manager manager;
|
||||
|
||||
Map::Map(std::string tID, int ms, int ts) : texID(tID), mapScale(ms), tileSize(ts)
|
||||
{
|
||||
scaledSize = ms* ts;
|
||||
width = 0;
|
||||
height = 0;
|
||||
tSize = ts;
|
||||
}
|
||||
|
||||
Map::~Map()
|
||||
{
|
||||
}
|
||||
|
||||
void Map::LoadMap(std::string path, int sizeX, int sizeY, int scale)
|
||||
{
|
||||
char c;
|
||||
std::fstream mapFile;
|
||||
mapFile.open(path);
|
||||
int srcX, srcY;
|
||||
|
||||
width = tSize*scale*sizeX;
|
||||
height = tSize*scale*sizeY;
|
||||
|
||||
for (int y = 0; y < sizeY; y++)
|
||||
{
|
||||
for (int x = 0; x < sizeX; x++)
|
||||
{
|
||||
mapFile.get(c);
|
||||
srcY = atoi(&c) * tileSize;
|
||||
mapFile.get(c);
|
||||
srcX = atoi(&c) * tileSize;
|
||||
AddTile(srcX, srcY, x*scaledSize, y*scaledSize);
|
||||
mapFile.ignore(2,',');
|
||||
}
|
||||
}
|
||||
|
||||
mapFile.ignore();
|
||||
// colliders
|
||||
for (int y =0; y < sizeY; y++)
|
||||
{
|
||||
for (int x = 0; x < sizeX; x++)
|
||||
{
|
||||
mapFile.get(c);
|
||||
if (c == '1')
|
||||
{
|
||||
auto& tcol(manager.addEntity());
|
||||
tcol.addComponent<ColliderComponent>("terrain",x*scaledSize,y*scaledSize,tileSize,scale);
|
||||
tcol.addGroup(Game::groupColliders);
|
||||
mapFile.ignore();
|
||||
}
|
||||
mapFile.ignore(2,',');
|
||||
}
|
||||
}
|
||||
mapFile.close();
|
||||
}
|
||||
|
||||
void Map::AddTile(int srcX, int srcY, int xpos, int ypos)
|
||||
{
|
||||
auto& tile(manager.addEntity());
|
||||
tile.addComponent<TileComponent>(srcX,srcY,xpos,ypos,tileSize, mapScale, texID);
|
||||
tile.addGroup(Game::groupMap);
|
||||
}
|
33
src/assetmgr/Map.h
Normal file
33
src/assetmgr/Map.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Map.h
|
||||
*
|
||||
* Created on: Feb 13, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_MAP_H_
|
||||
#define SRC_MAP_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
class Map
|
||||
{
|
||||
public:
|
||||
Map(std::string tID, int ms, int ts);
|
||||
~Map();
|
||||
|
||||
void LoadMap(std::string path, int sizeX, int sizeY, int scale);
|
||||
void AddTile(int srcX, int srcY, int xpos, int ypos);
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int tSize;
|
||||
|
||||
private:
|
||||
std::string texID;
|
||||
int mapScale;
|
||||
int tileSize;
|
||||
int scaledSize;
|
||||
};
|
||||
|
||||
#endif /* SRC_MAP_H_ */
|
26
src/assetmgr/MusicManager.cpp
Normal file
26
src/assetmgr/MusicManager.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* MusicManager.cpp
|
||||
*
|
||||
* Created on: Apr 9, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#include "MusicManager.h"
|
||||
#include "SDL2/SDL_mixer.h"
|
||||
|
||||
Mix_Music* MusicManager::LoadMusic(const char* path){
|
||||
Mix_Music* music = Mix_LoadMUS(path);
|
||||
return music;
|
||||
}
|
||||
|
||||
Mix_Chunk* MusicManager::LoadSound(const char* path){
|
||||
Mix_Chunk* sfx = Mix_LoadWAV(path);
|
||||
return sfx;
|
||||
}
|
||||
|
||||
void Play(Mix_Music* music, int replay)
|
||||
{
|
||||
|
||||
}
|
||||
void Pause(Mix_Music* music){}
|
||||
void Stop(Mix_Music* music){}
|
25
src/assetmgr/MusicManager.h
Normal file
25
src/assetmgr/MusicManager.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* MusicManager.h
|
||||
*
|
||||
* Created on: Apr 9, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_MUSICMANAGER_H_
|
||||
#define SRC_MUSICMANAGER_H_
|
||||
|
||||
#include "../game/Game.hpp"
|
||||
#include "SDL2/SDL_mixer.h"
|
||||
|
||||
class MusicManager
|
||||
{
|
||||
public:
|
||||
static Mix_Music* LoadMusic(const char* path);
|
||||
static void Play(Mix_Music* music);
|
||||
static void Pause(Mix_Music* music);
|
||||
static void Stop(Mix_Music* music);
|
||||
static Mix_Chunk* LoadSound(const char* path);
|
||||
};
|
||||
|
||||
|
||||
#endif /* SRC_MUSICMANAGER_H_ */
|
22
src/assetmgr/TextureManager.cpp
Normal file
22
src/assetmgr/TextureManager.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* TextureManager.cpp
|
||||
*
|
||||
* Created on: Feb 11, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#include "TextureManager.h"
|
||||
|
||||
SDL_Texture* TextureManager::LoadTexture(const char* texture)
|
||||
{
|
||||
SDL_Surface* tempSurface = IMG_Load(texture);
|
||||
SDL_Texture* tex = SDL_CreateTextureFromSurface(Game::renderer, tempSurface);
|
||||
SDL_FreeSurface(tempSurface);
|
||||
return tex;
|
||||
}
|
||||
|
||||
void TextureManager::Draw(SDL_Texture* tex, SDL_Rect src, SDL_Rect dest, SDL_RendererFlip flip)
|
||||
{
|
||||
|
||||
SDL_RenderCopyEx(Game::renderer, tex, &src, &dest, NULL, NULL, flip);
|
||||
}
|
23
src/assetmgr/TextureManager.h
Normal file
23
src/assetmgr/TextureManager.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* TextureManager.h
|
||||
*
|
||||
* Created on: Feb 11, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#ifndef SRC_TEXTUREMANAGER_H_
|
||||
#define SRC_TEXTUREMANAGER_H_
|
||||
|
||||
// #include <SDL2/SDL_image.h>
|
||||
#include "../game/Game.hpp"
|
||||
|
||||
class TextureManager
|
||||
{
|
||||
public:
|
||||
static SDL_Texture* LoadTexture(const char* fileName);
|
||||
static void Draw(SDL_Texture* tex, SDL_Rect src, SDL_Rect dest, SDL_RendererFlip flip);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SRC_TEXTUREMANAGER_H_ */
|
Reference in New Issue
Block a user