hey guys...now I know how vertex array works..
so I have a game that has an enemy that multiplies by 2 when you killed it...
so considering I use loop to draw it...it gets too slow eventually
now.. I have this class
class Zombie
{
private :
sf::RectangleShape Rect;
const float speed;
int health;
public :
Zombie(const sf::RenderWindow& window, float speedVal, int healthVal) :
speed(speedVal),
health(healthVal)
{
std::srand(time(0));
Rect.setSize(sf::Vector2f(37, 37));
Rect.setOrigin(Rect.getSize().x / 2, Rect.getSize().y / 2);
sf::Vector2f position;
rand();
position.x = rand() % window.getSize().x;
rand();
position.y = rand() % window.getSize().y;
Rect.setPosition(position);
Rect.setFillColor(sf::Color(0, 200, 0));
}
void move(User& user)
{
if (Rect.getPosition().x < user.getPosition().x)
{
Rect.move(speed, 0);
}
else if (Rect.getPosition().x > user.getPosition().x)
{
Rect.move(-(speed), 0);
}
if (Rect.getPosition().y < user.getPosition().y)
{
Rect.move(0, speed);
}
else if (Rect.getPosition().y > user.getPosition().y)
{
Rect.move(0, -(speed));
}
sf::Vector2f difference;
difference.x = user.getPosition().x - Rect.getPosition().x;
difference.y = user.getPosition().y - Rect.getPosition().y;
float face = std::atan2(difference.y, difference.x);
float degrees = face * pi / 180;
Rect.setRotation(degrees);
}
void reInit(const sf::RenderWindow& window)
{
srand(time(0));
rand();
sf::Vector2f position;
position.x = rand() % window.getSize().x;
rand();
position.y = rand() % window.getSize().y;
Rect.setPosition(position);
health = 50;
}
void decHealth(int val)
{
health -= val;
}
const int& getHealth() const
{
return health;
}
const sf::Shape& getShape() const
{
return Rect;
}
bool hit(User& user)
{
if (Rect.getGlobalBounds().intersects(user.getGlobalBounds())) return true;
return false;
}
};
and I have this code
std::vector<Zombie> zombie;
considering the fact that when it gets too big it becomes slow...
how do I compress it to vertex array rather how do I transform only a member of the vertex array