SFML community forums

Help => Graphics => Topic started by: Ditrih on April 06, 2013, 08:48:10 pm

Title: SFML 2.0 - Multiple Shoots
Post by: Ditrih on April 06, 2013, 08:48:10 pm
I had written fireball shoots and it's work's fine but it's designed only for one fireball at the moment so if i want to shoot 2 or more i must wait until my last die..English is not my strong suit...

How can i fix it ?

Fireball code :
   if(sf::Keyboard::isKeyPressed(sf::Keyboard::G))
                         {
                                 
                                 FireballState = true; // Exist or not
                                 
                       
                         }
                         if(FireballState)                                                                       
                                         {
                                               
                 
                         if(FireballSpeed.getElapsedTime().asMilliseconds() > 2 ) // Speed of change fireball frames
                                   {
            FireballSpeed.restart();
               
            vfireball.x = 7;
                        vfireball.y = 1;
           
                                   
            fireballmove = 1; /

                       
            Fireball.setTextureRect(sf::IntRect(vfireball.x * 26, vfireball.y * 27, 27, 27));          
               

            if(source.y == Down && i == 0) // source.y is my charecter direction
                        {                      
                                FireballDown = true;
                                Fireball.setPosition(sprite.getPosition().x, sprite.getPosition().y + 20);
            }
                        else if(source.y == Left && i == 0)
            {
                                FireballLeft = true;
                                        Fireball.setPosition(sprite.getPosition().x - 20, sprite.getPosition().y );
            }
                        else if(source.y == Right && i == 0)
                               
                {
                               
                                FireballRight = true;
                                Fireball.setPosition(sprite.getPosition().x + 20, sprite.getPosition().y );
            }
                                else if(source.y == Up && i == 0)
                        {
                                FireballUp = true;
                                        Fireball.setPosition(sprite.getPosition().x, sprite.getPosition().y - 20 );
                        }
                                                 if (FireballDown)
                                {
                                         Fireball.move( 0, fireballmove);
                                         
                                }

                         else if(FireballRight)
                                {
                                  Fireball.move( fireballmove,0);
                                }
                         else if (FireballLeft)
                                {
                Fireball.move( -fireballmove , 0);
                                }
                         else if (FireballUp)
                                {
                Fireball.move( 0 , -fireballmove );
                                }      
               
                        i++;
                       
         
                        Window.clear();

                         Window.draw(Fireball);
                       
                               
                        }
                                if(i == 500)  // There will be some smarter condition of fireball death when i'll have something except emptiness and character
                                {
                               
                        =
                        FireballState = false;
                        i = 0;
                       
                                FireballUp = false;
                                FireballRight = false;
                                FireballLeft = false;
                                FireballDown = false;
                       
                                }                              
                                                 
                         }

                         
Title: Re: SFML 2.0 - Multiple Shoots
Post by: zsbzsb on April 07, 2013, 05:11:26 pm
Sorry,i dont know english well
I'm learning SFML only second day so i'm sorry if my question seems so stupid
I spent a lot of hours on thinking how make my fireball fly after I release key and how to make few fireballs at the one moment

He-e-elp me TT

And the question is??? We really can not help you unless you ask a specific question.
Title: Re: SFML 2.0 - Multiple Shoots
Post by: Ditrih on April 09, 2013, 10:05:10 pm
Backed with specific question(Modified first post)
Title: Re: SFML 2.0 - Multiple Shoots
Post by: zsbzsb on April 10, 2013, 12:44:54 am
If you wish to have more than one fireball look into using a list such as std::list (http://www.cplusplus.com/reference/list/list/) or std::vector (http://www.cplusplus.com/reference/vector/vector/). Basically when you need a new fireball create a new fireball instance and put it into the list of fireballs.

And no, I will not take your code and modify it for you. If you need help with lists/vectors/arrays try out a little site known as google.
Title: Re: SFML 2.0 - Multiple Shoots
Post by: Halsys on April 10, 2013, 10:51:38 am
You could make a base class and make more classes for the fireball and the player.
Then make sure you have somewhere in the loop to go through all the actors that aren't NULL.
And what I meant by that is, I make all my classes derived from said actor and they all use polymorphism on a Vector or an array of pointers depending on the size of the project or what I am doing. And the base class(Actor) has three base functions:
~Initialization
~Update
~Draw
All those functions not implemented on the base class, but on each class I derived it from, I implemented them. So when I run the loop it Updates and Draws all the Actors, but when I load them they run Init.
Most likely on level load.
Hope it helps.