a Class LoaderParams to load teh parameters of the different objects
/*
* LoaderParams.h
*
* Created on: 15 apr. 2014
* Author: JAN
*/
#ifndef LOADERPARAMS_H_
#define LOADERPARAMS_H_
#include <string>
using namespace std;
class LoaderParams {
public:
LoaderParams(int x, int y, int width, int height, std::string textureID) : m_x(x), m_y(y), m_width(width), m_height(height), m_textureID(textureID)
{
}
int getX() const { return m_x; }
int getY() const { return m_y; }
int getWidth() const { return m_width; }
int getHeight() const { return m_height; }
std::string getTextureID() const { return m_textureID; }
private:
int m_x;
int m_y;
int m_width;
int m_height;
std::string m_textureID;
};
#endif /* LOADERPARAMS_H_ */
also a class Game
* Game.h
*
* Created on: 15 apr. 2014
* Author: JAN
*/
#ifndef GAME_H_
#define GAME_H_
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <vector>
#include "TextureManager.h"
#include "Gameobject.h"
#include "SDLGameobject.h"
class Game {
public:
static Game* Instance()
{
if(s_pInstance == 0)
{
s_pInstance = new Game();
return s_pInstance;
}
return s_pInstance;
}
//simply set the running variable to true
bool init(const char* title, int xpos, int ypos, int width, int height, int flags);
void render();
void update();
void handleEvents();
void clean();
SDL_Renderer* getRenderer() const { return m_pRenderer; }
std::vector<GameObject*> m_gameObjects;
//a function to access private running variable
bool running() {return m_bRunning; }
private:
Game(); // create the s_pInstance member variable
static Game* s_pInstance;
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
int m_currentFrame;
bool m_bRunning;
};
typedef Game TheGame;
#endif /* GAME_H_ */
and finally a class TextureManager
/*
* TextureManager.h
*
* Created on: 15 apr. 2014
* Author: JAN
*/
#ifndef TEXTUREMANAGER_H_
#define TEXTUREMANAGER_H_
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <string>
#include <map>
using namespace std;
class TextureManager {
public:
static TextureManager* Instance()
{
if(s_pInstance == 0)
{
s_pInstance = new TextureManager();
return s_pInstance;
}
return s_pInstance;
}
bool load(std::string fileName,std::string id, SDL_Renderer* pRenderer);
void draw(std::string id, int x, int y, int width, int height, SDL_Renderer* pRenderer, SDL_RendererFlip flip = SDL_FLIP_NONE);
void drawFrame(std::string id, int x, int y, int width, int height, int currentRow, int currentFrame, SDL_Renderer* pRenderer, SDL_RendererFlip flip = SDL_FLIP_NONE);
std::map<std::string, SDL_Texture*> m_textureMap;
private:
TextureManager() {}
TextureManager(const TextureManager&);
TextureManager& operator=(const TextureManager&);
static TextureManager* s_pInstance;
};
typedef TextureManager TheTextureManager;
#endif /* TEXTUREMANAGER_H_ */
where am i placing my includes wrong? I don't seem to figure this out. Sometimes the error dissapears by Player and appears by enemy and the way around.
now i get expected type-specifier before 'Enemy' error
In game.h
s_pInstance = new Game();
Error undefined reference to `Game::Game()'
Solución
Game.h and SDLGameObject.h include each other. So, to correct that, replace #include "SDLGameObject.h" with class SDLGameObject in your Game.h file.
If you are calling the class in Game.cpp include your SDLGameObject.h header there instead of in Game.h because you will not have access to it any other way. Also, for good measure, move the inclusion of Game.h to your SDLGameObject.cpp definition file.
EDIT: You may also want to include Enemy.h in your Game.cpp file. This would be true for any class that your program states you don't have that type specified after your header include switches.