Hi. I have an enemy class like this:
//enemy class
class enemy {
public:
sf::RectangleShape rect;
float bottom, left, right, top;
sf::Texture enemytexture;
sf::Sprite enemysprite;
enemy(sf::Vector2f position, sf::Vector2f size, sf::Color color) {
enemytexture.loadFromFile("dwarf.png");
enemysprite.setTexture(enemytexture);
}
void update() {
fireanis.setPosition(rect.getPosition().x - 9, rect.getPosition().y - 45);
fireanis.setScale(0.5, 0.5);
}
};
int main () {.......
//create
enemy e1(enemy(sf::Vector2f(1900, 910), sf::Vector2f(15, 10), sf::Color(255, 255, 255, 0)));
//update
e1.update();
//draw
window.draw(e1.enemysprite);
/////////////////////////////////////////////////////////////////////////////////////////////
if i would like to create a new enemy i m using same way like enemy e2,e3,e4…..
But it doestn seem effective way for game programming i think.
My question is how can i create and draw multiple enemies with loops or are there another ways? is there any sample code?