Witam zabrałem się ostatnio za napisanie kodu mojej starej gry przy pomocy dziedziczenia, polimorfizmu i takich tam jednak nie jestem pewny czy taki zapis jest poprany oraz czy nie istnieje jego lepsza bardziej rozszerzalna forma. Informuje że kod działa poprawnie.
Si.h
class Si : public sf::Drawable {
protected:
int id = 0;
int posX = 0;
int posY = 0;
int rotate = 0;
float speed = 100.f;
int hp = 1;
float timeToNewMove;
sf::Sprite moobSprite;
sf::Clock moveClock;
bool newMove = true;
public:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
target.draw(moobSprite, states);
}
void generateVector();
};
BlueMoob.h
class BlueMoob : public Si {
public:
BlueMoob(sf::Texture &texture) {
Si::moobSprite.setTexture(texture);
Si::moobSprite.setPosition(500, 250);
Si::moobSprite.setOrigin(Si::moobSprite.getGlobalBounds().width / 2, Si::moobSprite.getGlobalBounds().height / 2);
}
};