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

Making different enemys fire

Last post 9/7/2008 8:36 PM by XM. 2 replies.
  • 9/7/2008 6:23 PM

    Making different enemys fire

    In my code right now I have ships comming across the screen and a timer that ticks down to zero. When the timer goes to zero I have the enemys fire some bullets and reset the timer.

    Well, I have one dilemma I'm not sure how to fix: The only enemy that will fire bullets is the last one to be created. So one ship will fire, but when another one comes on screen the first ship won't ever fire again. How do I go about fixing this? Thanks

  • 9/7/2008 6:42 PM In reply to

    Re: Making different enemys fire

    Each enemy should have its own timer. You're probably doing something like this:

       timer -= gameTime.ElapsedGameTime.TotalSeconds;
       if(timer<=0)
       {
          ship.Fire();
          timer=timerReset;
       }

    What you want to do is have each individual ship carry its own timer, inside your Ship class:

       foreach(Ship ship in ships)
       {
          ship.timer -= gameTime.ElapsedGameTime.TotalSeconds;
          if(ship.timer<=0)
          {
             ship.Fire();
             ship.timer=timerReset;
          }
       }

    Hope this helps point you in the right direction.

  • 9/7/2008 8:36 PM In reply to

    Re: Making different enemys fire

    That did it! Thanks a lot :D
Page 1 of 1 (3 items) Previous Next