XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Good shoot algorithm

Last post 21/02/2009 23:12 by Kenny hp. 2 replies.
  • 21/02/2009 18:39

    Good shoot algorithm

    I would like to get a similar shoot like this:

    http://www.youtube.com/watch?v=-L9nGo22xgQ

    I have almost achieved,  but is not as good as I'd like, when I press the shoot button, the first time not work. This is my shoot functi
    if (Keyboard.GetState().IsKeyDown(Keys.Space))  
                {  
     
                    float intervaloTiempo = 300f;  
                      
                    temporizador += (float)gameTime.ElapsedGameTime.Milliseconds;  
     
                    if (intervaloTiempo < temporizador)  
                    {  
                        Disparo disparo = new Disparo(juegoActual, posicion, Enumerados.TiposDisparo.Basico, gameTime);  
                        juegoActual.Components.Add(disparo);  
                        temporizador = 0f;  
                    }  
                } 

    Any idea?

     

     

  • 21/02/2009 18:47 In reply to

    Re: Good shoot algorithm

    Move the following code out of the if statement:

     

    temporizador += (float)gameTime.ElapsedGameTime.Milliseconds;     
     

    The problem is that your delay timer is only accumulating time when you press your fire button.  You want it to accumulate time at every update.

    I also notice from the video you linked that there appears to be a limit on the bullets the character can have active at any given time.  If you want to implement that, then you will need to maintain a counter that decrements everytime you shoot and then increments everytime your bullets hit an object or boundry.  Then add a check to your if statement that only fires a bullet when the counter is above 0.

     

  • 21/02/2009 23:12 In reply to

    Re: Good shoot algorithm

    Thank's! it's just i need, now works perfect!
Page 1 of 1 (3 items) Previous Next