Advertisement
errur

Timer.cs

Nov 13th, 2015
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace notContra
  8. {
  9.     /// <summary>
  10.     /// Creates a timer. Use the Add() or Wait() functions of TimerManager instead of creating one manually.
  11.     /// </summary>
  12.     public class Timer
  13.     {
  14.         float timeToWait;        
  15.         float elapsedTime;
  16.  
  17.         bool hasFinished;
  18.         bool isLooping;
  19.  
  20.         int nrOfCycles;
  21.         int timesToCycle;
  22.  
  23.         public bool HasFinished
  24.         {
  25.             get
  26.             {
  27.                 return hasFinished;
  28.             }
  29.         }
  30.         Timer()
  31.         {
  32.             isLooping = false;
  33.             hasFinished = false;
  34.             elapsedTime = 0;
  35.             nrOfCycles = 0;
  36.         }
  37.         public Timer(float timeToWait) : base()
  38.         {            
  39.             this.timeToWait = timeToWait;
  40.         }
  41.         public Timer(int timeToWait) : base()
  42.         {
  43.             this.timeToWait = timeToWait*1000;
  44.         }
  45.         public Timer(float timeToWait,bool isLooping,int timesToCycle) : base()
  46.         {
  47.             this.isLooping = isLooping;
  48.             this.timeToWait = timeToWait;
  49.             this.timesToCycle = timesToCycle;
  50.         }
  51.  
  52.         public void Tick(GameTime gameTime)
  53.         {
  54.             if(elapsedTime >= timeToWait)
  55.             {
  56.                 if(!isLooping)
  57.                     hasFinished = true;
  58.                 else
  59.                 {
  60.                     nrOfCycles++;
  61.                     elapsedTime = 0;
  62.                 }
  63.             }
  64.             else elapsedTime += gameTime.ElapsedGameTime.Milliseconds;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement