开发者

Adding delay between shots

Here is the my code, I call the function shooting each loop in main. This results in a lot of a really high rate of fire. I wish to add some delay to get a RoF of maybe 2-3/s but the only w开发者_Go百科ay I know how to do it delays my entire loop.

void game::shooting(){

if (P->shoot()){
  for(int i=0;i<3;i++){
   VGCVector der = VGCVector (-5+5*i,5);
   VGCVector hit = P->getPos();
   VGCVector calib = VGCVector (10,0);
   hit= hit+calib;
  SV.push_back(shot(hit,der,false));
  }


}
}


if ( NextShootTime < CurrentTime )
{
  Shoot();
  NextShootTime = CurrentTime + ShootDelay;
}

Initialise NextShootTime to 0 and you're set.

You may also want to handle queuing up multiple bullets in one frame in case the framerate is very low.


You need to pass in the time of the frame and check this against the intended rate of fire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜