Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - codyjae

Pages: [1]
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).
 
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;
}

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


2
Graphics / deleting a class made up of SFML images
« on: June 25, 2014, 09:47:00 pm »
Hey, new to SFML but not to C/C++. 
So here is my issue, I created a linked list (manualy) to test what i could do right off the bat.  Originally it was a program to produce various circle shapes that bounce off the walls, basically an infinite amount of balls.  Now I made a function to start deleting them to go back to having 0 circles bumping around.  I used a pointer to iterate through the chain of them (the chain was also used to see where each was and to move them slightly everytime before a new window was rendered).  Then the last one in the chain was set to be deleted.  This caused a seg fault, so i ended up just removing the item from the chain and ignoring it for the rest of its existence.  And that is how i deleted it. 

I recently created a Galaga-like game using a self-made bullets class containing a circle shape for each.  Now to stop that initial problem i put them into a deque (using push_front()).  Now same issue arrised when i tried to erase them from the deque as they exited the window.  Although its small, I do feel like there are an endless amount of bullets/balls floating around outside the window as i cannot delete them.  Is there a solution to this? or is RAII going to make it irrelevant

Thanks ahead of time

Pages: [1]