Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace notContra
- {
- /// <summary>
- /// Creates a timer. Use the Add() or Wait() functions of TimerManager instead of creating one manually.
- /// </summary>
- public class Timer
- {
- float timeToWait;
- float elapsedTime;
- bool hasFinished;
- bool isLooping;
- int nrOfCycles;
- int timesToCycle;
- public bool HasFinished
- {
- get
- {
- return hasFinished;
- }
- }
- Timer()
- {
- isLooping = false;
- hasFinished = false;
- elapsedTime = 0;
- nrOfCycles = 0;
- }
- public Timer(float timeToWait) : base()
- {
- this.timeToWait = timeToWait;
- }
- public Timer(int timeToWait) : base()
- {
- this.timeToWait = timeToWait*1000;
- }
- public Timer(float timeToWait,bool isLooping,int timesToCycle) : base()
- {
- this.isLooping = isLooping;
- this.timeToWait = timeToWait;
- this.timesToCycle = timesToCycle;
- }
- public void Tick(GameTime gameTime)
- {
- if(elapsedTime >= timeToWait)
- {
- if(!isLooping)
- hasFinished = true;
- else
- {
- nrOfCycles++;
- elapsedTime = 0;
- }
- }
- else elapsedTime += gameTime.ElapsedGameTime.Milliseconds;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement