Post removed.
Post removed.
Post removed.
Last edited by TheRLG on Fri Dec 28, 2007 7:41 am, edited 5 times in total.
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.hey all can u look at my pseudocode and tell me if im missing anything for my weapon firing function? thanks
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:
for burst-shots its a bit more complicated because it depends on the fps and the firingrate/delay.
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
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
}
}
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;
}
}
oh and its quite late so dont assume this "code" to be flawless but the idea should be clear