Hello!
I've got concerns about the my current game code. It's going to be a simple game but with educative code inside, a proof-of-concept. It's more advanced than the provided pong example, so I needed to separate objects.
Currently I've got a bunch of .h and .cpp files:
CAnimator - an animator class for animating sprites,
CCamera - manages cameras for one or two players,
CEntity - handles the players, monsters,
CInterface - all the GUI stuff is in here,
CLevel - manages the level related stuff,
CGame - groups all these togther, [/list]
It all works fine, and shaping up really nicely, but there are some things I don't like about it:
- It's half this and half that: SFML has references all around, and my classes use pointers (the actual example below does not actually show the pointers)
- Due to the SFML design, I'm not passing pointers but references to the constructors, which enforces me to initalize them on startup... which is exxxtremely restrictive
- I like the clean design of SFML but I seem to not understand some basic concepts here... I'm a pointer-user guy
For example, look at the following piece of code. You can see the animator and the entity class constructors. Since the entity has 2 animators, I have to initiate them in the constructor. And the dependencies would grow from class to class.
//! Constructor
CAnimator(sf::RenderWindow& Window, sf::Texture& Texture, int TileSize, sf::Sprite& Sprite,
const SAnimation& Animation = SAnimation())
: window(Window), texture(Texture), tileSize(TileSize), sprite(Sprite), animation(Animation)
{
/* ...*/
}
//! Constructor
CEntity::CEntity(sf::RenderWindow& Window, sf::Texture& Texture, int TileSize, CLevel& Level,
CInterface& Interface, const sf::Vector2i& TilePos, int Direction)
: window(Window), texture(Texture), tileSize(TileSize), level(Level), interface(Interface),
tilePos(TilePos), direction(Direction),
bodyAnimator(window, texture, tileSize, body), faceAnimator(window, texture, tileSize, face)
{
/* ... */
}
So, basically, I'd like advises on:
How to code nicely with SFML?Thanks in advance,
easy