1) How do you handle entities(or what you call them)
Here is how I currently handle them but it seems retarded... An entity(in my engine) is everything you can see on the screen. Every entity has a sprite, pos, an id etc(collision box... yeah... that was dumb.. but I'll soon get it out of there, just need to figure out some stuff before) it looks something like this:
Code: Select all
class Entity {
friend class EntityManager;
public:
Entity(): x(0), y(0), id(0), alive(true), interactible(true), loaded(false) {}
virtual ~Entity();
virtual void update(int diff); /* Main update function handles everything */
virtual void load(const string& filename); /* Loads the spritesheet for the Entity */
virtual void draw(); /* Renders the Entity on the screen */
virtual void remove(); /* Removes the Entity and frees the memory */
// ... some more functions down
In the main loop, based on the game state, it handled that state, if it was play state, it handled the play state, where i needed the reference to the player, and to all the enemies, to check whether somebody won(if player.dead or enemies.size() < 1 someone won... ). I realized it's a pretty dumb idea... so I wanted to ask where(and/or how) do you handle the game logic and how do you have access(if you do) to any unit(or entity).
2) How do you handle text output to the screen? Basically now I use a font file, and the sdl TTF_Render function to render text on the screen, I just find that this method is a huge pain in the ass... and I often have amazing bugs with it. So I figured that I'm definitely doing it wrong!
Here is a look to my font rendering process
Code: Select all
void Font::draw(const string& text, int x, int y, int alpha)
{
_text = TTF_RenderText_Solid(font,text.c_str(), textColor);
if(_text == NULL) {
Singleton<Log>::getInstance()->print("Could not draw text! %s", TTF_GetError());
} else {
SDL_SetAlpha(_text,SDL_SRCALPHA,alpha);
Singleton<Graphics>::getInstance()->Draw(this->_text,x,y);
SDL_FreeSurface(_text);
_text = NULL;
}
}