VG:Bullet Timing

From MyProjectFun
Jump to: navigation, search

This is a highly sought after feature. First, we need variables for a timer, then we need to modify our firing code. My example is based on player firing, so if you want enemies to fire on a timer, you should probably use local data to avoid counting down a single timer too quickly. Also, you'd want to modify your enemy's firing code.

Here's a bit of an example of how this works:

// Variables for PlayerFireFN to not fire a bullet hose
public static int FireTimer = 0;
public const int FireReset = 10;
 
// Player fire behavior
public static void PlayerFireFN()
{
  // If the player presses space
  if (This.Game.IsPressed(InputKey.Space))
  {
    // If the timer is up
    if (FireTimer <= 0)
    {
      // USUAL BULLET FIRING
 
      // Reset the timer
      FireTimer = FireReset;
    }
  }
  // Otherwise
  else
  {
    // Decrement the timer
    --FireTimer;
  }
}
Personal tools
Namespaces
Variants
Actions
Navigation
Engineering
Game Design
Multimedia Production
VG Programming
Downloads
Toolbox