I need the character to be able to shoot fireballs only every 12 seconds. But I can still shoot before 12 seconds and I don't want that. So when I shoot a fireball I try to record it as the current GameTime.ElapsedGameTime value but it's not working.
here is the code
// Create a readonly variable which specifies how often the user can shoot.
private static readonly TimeSpan ShootInterval = TimeSpan.FromSeconds(12);
// Keep track of when the user last shot. Or null if they have never shot in the current session.
private TimeSpan? LastFireballShot;
private void UpdateFireball(GameTime theGameTime, KeyboardState aCurrentKeyboardState)
foreach (Fireball aFireball in mFireballs)
if (aCurrentKeyboardState.IsKeyDown(Keys.RightControl) == true && mPreviousKeyboardState.IsKeyDown(Keys.RightControl) == false)
//the user is trying to shoot
if (LastFireballShot == null || theGameTime.ElapsedGameTime - (TimeSpan)LastFireballShot >= ShootInterval)
// Allow the user to shoot because he either has not shot before or it's been 1 second since the last shot.