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

Author Topic: SFML 2.0 - Multiple Shoots  (Read 2560 times)

0 Members and 1 Guest are viewing this topic.

Ditrih

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML 2.0 - Multiple Shoots
« 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;
                       
                                }                              
                                                 
                         }

                         
« Last Edit: April 09, 2013, 10:18:45 pm by Ditrih »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML 2.0 - Multiple Shoots
« Reply #1 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Ditrih

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML 2.0 - Multiple Shoots
« Reply #2 on: April 09, 2013, 10:05:10 pm »
Backed with specific question(Modified first post)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML 2.0 - Multiple Shoots
« Reply #3 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 or std::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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Halsys

  • Jr. Member
  • **
  • Posts: 66
  • Halsys like Hal.sys
    • View Profile
    • Email
Re: SFML 2.0 - Multiple Shoots
« Reply #4 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.
If you notice I put "....", in my sentences way too much... I'm sorry.

 

anything