Alrighty. I have created the code similarly to that, used an array of sf::RectangleShape's and boolean values, made a for loop in the game engine which checked if the boolean value was true. If it were true, it'd draw the rectangles. Upon collision the boolean values would turn false, and thus it would not draw the bullet. It has a cap of 15 bullets, here's my code so far:
//Shoot.h
class shoot {
public:
bool ifw, shooting[51], seebullet[51];
void shootmusket(sf::RectangleShape enemy123, sf::Sprite player, int direction
);
shoot();
void shootbullet();
void deletebullet(int b);
sf::RectangleShape bullet[51];
int damage;
private:
sf::Clock shoottimer;
void makebullet(int direction, int z);
void makebullet(int direction, int z, int x, int y);
int velx[51], vely[51];
bool cb[51];
} shoot;
// Shooting.h
void game::shoot::shootmusket(sf::RectangleShape enemy123, sf::Sprite player, int direction) {
sf::Time shoottime = shoottimer.getElapsedTime();
if (shoottime.asSeconds() >= 2.0 && gamer.sprint > 0) {
shoottimer.restart();
gamer.sprint -= 5;
std::cout << gamer.sprint << std::endl;
int d = direction;
if (!cb[1])
makebullet(d, 1);
else if (!cb[2])
makebullet(d, 2);
else if (!cb[3])
makebullet(d, 3);
else if (!cb[4])
makebullet(d, 4);
else if (!cb[5])
makebullet(d, 5);
else if (!cb[6])
makebullet(d, 6);
else if (!cb[7])
makebullet(d, 7);
else if (!cb[8])
makebullet(d, 8);
else if (!cb[9])
makebullet(d, 9);
else if (!cb[10])
makebullet(d, 10);
else if (!cb[11])
makebullet(d, 11);
else if (!cb[12])
makebullet(d, 12);
else if (!cb[13])
makebullet(d, 13);
else if (!cb[14])
makebullet(d, 14);
else if (!cb[15])
makebullet(d, 15);
else
std::cout << "No Free Bullet Slots\n";
damage = 5;
}
}
game::shoot::shoot() {
shoottimer.restart();
}
void game::shoot::makebullet(int direction, int z) {
if (direction == 3 || direction == 4)
bullet[z].setSize(sf::Vector2f(5, 3));
else if (direction == 1 || direction == 2)
bullet[z].setSize(sf::Vector2f(3, 5));
bullet[z].setFillColor(sf::Color(100, 100, 5));
shooting[z] = 1;
bullet[z].setPosition(gamer.player.getPosition().x, gamer.player.getPosition().y);
velx[z] = 0;
vely[z] = 0;
if (direction == 1)
vely[z] = -5;
if (direction == 2)
vely[z] = 5;
if (direction == 3)
velx[z] = -5;
if (direction == 4)
velx[z] = 5;
cb[z] = 1;
}
void game::shoot::shootbullet() {
for (int x = 0; x <= 10; x++) {
bullet[x].move(velx[x], vely[x]);
seebullet[x] = 1;
}
}
void game::shoot::deletebullet(int b) {
bullet[b].setPosition(gamer.player.getPosition().x, gamer.player.getPosition().y);
cb[b] = 0;
velx[b] = 0;
vely[b] = 0;
seebullet[b] = 0;
shooting[b] = 0;
}
// Portion of Game Engine
// Shoot Bullet
for (int x = 0; x < 15; x++) {
if (shoot.shooting[x])
shoot.shootbullet();
}
// Bullet Collision
if (enemy1.seen) {
for (int x = 0; x < 15; x++) {
if(shoot.bullet[x].getGlobalBounds().intersects(enemy1.enemyr.getGlobalBounds())) {
enemy1.health -= shoot.damage;
shoot.deletebullet(x);
enemy1.ifdead();
std::cout << "BULLET " << x << " HIT TARGET ENEMY1\n";
}
}
enemy1.updateai();
}
for (int x = 0; x <= 15; x++) {
if(shoot.bullet[x].getGlobalBounds().intersects(wall.getGlobalBounds())) {
shoot.seebullet[x] = 0;
shoot.deletebullet(x);
}
if(shoot.bullet[x].getGlobalBounds().intersects(wall2.getGlobalBounds())) {
shoot.seebullet[x] = 0;
shoot.deletebullet(x);
}
if(shoot.bullet[x].getGlobalBounds().intersects(wall3.getGlobalBounds())) {
shoot.seebullet[x] = 0;
shoot.deletebullet(x);
}
if(shoot.bullet[x].getGlobalBounds().intersects(wall4.getGlobalBounds())) {
shoot.seebullet[x] = 0;
shoot.deletebullet(x);
}
}
// Draw Bullets to the Screen
for (int x = 0; x < 15; x++) {
if (shoot.seebullet[x])
window.draw(shoot.bullet[x]);
}
I'd say that that ain't bad for a 13-year-old. Does this look good? Any suggestions? Thanks.