1
Graphics / Re: deleting a class made up of SFML images
« on: June 26, 2014, 09:58:05 pm »
Thank you, and i apologize for the vagueness.
How, though, do you use RAII? I have more or less made a small scale version of what i was hoping to do, and it gets laggy very fast with all the circles going around, even though only a few of them are actually relevant. being able to kill off the ones not being used would be awesome, but i have no idea how. I can attach my .cpp file (very simple to read as most of my code is in functions on .h).
I guess another thing, is there a smarter way of doing this? Again new to SFML and this forum so feel free to yell at me if i post something overly ignorant
Thanks ahead of time
How, though, do you use RAII? I have more or less made a small scale version of what i was hoping to do, and it gets laggy very fast with all the circles going around, even though only a few of them are actually relevant. being able to kill off the ones not being used would be awesome, but i have no idea how. I can attach my .cpp file (very simple to read as most of my code is in functions on .h).
int main(int argc, char* argv[])
{
int enemycount;
std::cout << "How many enemies?" << std::endl;
std::cin >> enemycount;
user player_user;
sf::RenderWindow window(sf::VideoMode(800,600,10), "Shooter Jaynt");
window.setVerticalSyncEnabled(true);
window.setMouseCursorVisible(false);
player_user.reloadtime = 1;
player_user.alive = 1;
std::vector <ai*> enemy; //contains all enemies (circles that shoot small circles)
for(int i = 0; i < enemycount; i++)
{
ai* tmp;
tmp = new ai(400,(rand() % 80));
enemy.push_back(tmp);
}
while(window.isOpen())
{
for(int i = 0; i < enemycount; i++)
{
//this checks for collisions, causes a great deal of lag but i have no idea any other way of doing it
for(int p = 0; p < player_user.bullets_active.size(); p++)
{
if(player_user.bullets_active[p].bullet.getGlobalBounds().intersects(enemy[i]->player.getGlobalBounds())){
enemy[i]->alive = 0;
enemy[i]->player.move(700,-20);
player_user.bullets_active[p].alive = 0;
player_user.bullets_active[p].bullet.move(700,-20);
}
}
enemy[i]->reloadtimef();
enemy[i]->shoot_bullets(player_user);
enemy[i]->move_bullets();
enemy[i]->move_player();
enemy[i]->move_target(player_user);
}
player_user.reloadtimef();
player_user.check_for_shoot();
player_user.checkforexit(window);
player_user.move_bullets(window);
player_user.move_target_right(window);
player_user.move_target_left(window);
player_user.move_player_right(window);
player_user.move_player_left(window);
window.clear(sf::Color(10,10,10));
//display enemy bullets
for(int i = 0; i < enemycount; i++){
if(enemy[i]->alive == 1){
enemy[i]->displaybullets(window);
window.draw(enemy[i]->player);
}
}
player_user.displaybullets(window);
window.draw(player_user.player);
window.draw(player_user.target);
window.display();
}
return 0;
}
{
int enemycount;
std::cout << "How many enemies?" << std::endl;
std::cin >> enemycount;
user player_user;
sf::RenderWindow window(sf::VideoMode(800,600,10), "Shooter Jaynt");
window.setVerticalSyncEnabled(true);
window.setMouseCursorVisible(false);
player_user.reloadtime = 1;
player_user.alive = 1;
std::vector <ai*> enemy; //contains all enemies (circles that shoot small circles)
for(int i = 0; i < enemycount; i++)
{
ai* tmp;
tmp = new ai(400,(rand() % 80));
enemy.push_back(tmp);
}
while(window.isOpen())
{
for(int i = 0; i < enemycount; i++)
{
//this checks for collisions, causes a great deal of lag but i have no idea any other way of doing it
for(int p = 0; p < player_user.bullets_active.size(); p++)
{
if(player_user.bullets_active[p].bullet.getGlobalBounds().intersects(enemy[i]->player.getGlobalBounds())){
enemy[i]->alive = 0;
enemy[i]->player.move(700,-20);
player_user.bullets_active[p].alive = 0;
player_user.bullets_active[p].bullet.move(700,-20);
}
}
enemy[i]->reloadtimef();
enemy[i]->shoot_bullets(player_user);
enemy[i]->move_bullets();
enemy[i]->move_player();
enemy[i]->move_target(player_user);
}
player_user.reloadtimef();
player_user.check_for_shoot();
player_user.checkforexit(window);
player_user.move_bullets(window);
player_user.move_target_right(window);
player_user.move_target_left(window);
player_user.move_player_right(window);
player_user.move_player_left(window);
window.clear(sf::Color(10,10,10));
//display enemy bullets
for(int i = 0; i < enemycount; i++){
if(enemy[i]->alive == 1){
enemy[i]->displaybullets(window);
window.draw(enemy[i]->player);
}
}
player_user.displaybullets(window);
window.draw(player_user.player);
window.draw(player_user.target);
window.display();
}
return 0;
}
I guess another thing, is there a smarter way of doing this? Again new to SFML and this forum so feel free to yell at me if i post something overly ignorant
Thanks ahead of time