Post removed.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post removed.

Post by TheRLG »

Post removed.
Last edited by TheRLG on Fri Dec 28, 2007 7:41 am, edited 5 times in total.
FlyHigh
Posts: 111
Joined: Wed Mar 23, 2005 12:05 am

Post by FlyHigh »

before you fire the bullet, check you have more than 0, not after you fire it.
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

Post removed.
Last edited by TheRLG on Fri Dec 28, 2007 7:41 am, edited 1 time in total.
Guest

Post by Guest »

get rid of the pauses, if u use the firing rate, u dont need a pause.
en972
Posts: 27
Joined: Tue Apr 26, 2005 7:58 pm

Post by en972 »

That doesnt look like any code I've ever seen. Is that just an outline of your code?
Taliesen
Posts: 17
Joined: Fri Apr 22, 2005 7:39 am

Post by Taliesen »

hey all can u look at my pseudocode and tell me if im missing anything for my weapon firing function? thanks
Yeah, pseudocode means not really code...it is descriptions of what the code will do. Meaning more for seening whether or not the order and layout is correct, not whether or not the code will work.
mm765
Posts: 172
Joined: Fri May 28, 2004 10:12 am

Post by mm765 »

its not that simple :)
if you pause after each shot, then your graphics wouldnt be updated in that time. so you definitely have to get rid of the pause (or you could use a firing-thread but that would just add more complications).

instead you need to base it on the time that has passed since the last shot.
for single-shot-mode thats pretty easy:

Code: Select all

firesingleshot()
{
  if(availableBullets > 0)
  {
     if(currentTime - timeOfLastShot > firingDelay)
     {
        dischargeRound();
        availableBullets--;
        timeOfLastShot = currentTime;
     }
  }
  else 
  {
    return; // or play click-sound or whatever 
  }
}
for burst-shots its a bit more complicated because it depends on the fps and the firingrate/delay.

Code: Select all

fireBurstMode()
{
  if(availableBullets > 0)
  {

    if(bulletsLeftToFireForCurrentBurst == 0)
    {
        if(currentTime - lastBurstEnd > delayBetweenBursts)
        {
          bulletsLeftToFireForCurrentBurst = numberOfRoundsToFireInBurstMode;
          timeOfLastBurst = currentTime; // subtract X * firingdelay to shoot x bullets this frame
        }
        else
        {
           return;
        }
    }
  
     numberOfBulletsToFireThisFrame = min(currentTime - timeOfLastBurst / firingDelay,availableBullets, bulletsLeftToFireForCurrentBurst); // yeah i know theres no min() with 3 params ..thats left as an exercise for the reader
     for(int i = 0;i < numberOfBulletsToFireThisFrame;++i)
     {
        dischargeRound();
        availableBullets--;
        bulletsLeftToFireForCurrentBurst--;
        timeOfLastBurst = currentTime;
     }
     if(bulletsLeftToFireForCurrentBurst == 0)
     {
        lastBurstEnd = currentTime;
     }
  }
  else
  {
    return;
  }

}

if you dont want to fire multiple rounds in one frame (which would be fired directly after each other with no delay) you can of course change it so that at most one round is fired in the frame (at most because it could be your firingdelay is larger than one frames time so there could be frames with no round being fired)

oh and its quite late so dont assume this "code" to be flawless but the idea should be clear :)
Post Reply