2012-03-19 23:57:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using Axios.Engine.Interfaces;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
2012-04-18 03:07:51 +00:00
|
|
|
|
using GameStateManagement;
|
2012-03-19 23:57:59 +00:00
|
|
|
|
|
|
|
|
|
namespace Axios.Engine
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Modeled after Nicks' implemenentation
|
|
|
|
|
* Source: http://www.gamedev.net/topic/473544-how-to-make-a-timer-using-xna/page__view__findpost__p__4107032
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-04-07 18:15:15 +00:00
|
|
|
|
public class AxiosTimer : AxiosGameObject
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
|
|
|
|
TimeSpan interval = new TimeSpan(0, 0, 1);
|
|
|
|
|
TimeSpan lastTick = new TimeSpan();
|
|
|
|
|
private bool _enabled = false;
|
|
|
|
|
|
|
|
|
|
public event EventHandler Tick;
|
|
|
|
|
|
|
|
|
|
public TimeSpan Interval
|
|
|
|
|
{
|
|
|
|
|
get { return interval; }
|
|
|
|
|
set { interval = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean Enabled
|
|
|
|
|
{
|
|
|
|
|
get { return _enabled; }
|
|
|
|
|
set { _enabled = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AxiosTimer()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-07 18:15:15 +00:00
|
|
|
|
public override void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
2012-04-08 19:40:58 +00:00
|
|
|
|
if (gameScreen.IsActive) //only "tick" if the window has focus - otherwise the Timer will play catchup
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
2012-04-08 19:40:58 +00:00
|
|
|
|
if (_enabled)
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
2012-04-08 19:40:58 +00:00
|
|
|
|
if (gameTime.TotalGameTime - lastTick >= interval)
|
2012-04-07 18:15:15 +00:00
|
|
|
|
{
|
2012-04-08 19:40:58 +00:00
|
|
|
|
if (Tick != null)
|
|
|
|
|
{
|
|
|
|
|
//EventArgs e = new EventArgs();
|
2012-03-19 23:57:59 +00:00
|
|
|
|
|
2012-04-08 19:40:58 +00:00
|
|
|
|
Tick(this, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastTick = gameTime.TotalGameTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-19 23:57:59 +00:00
|
|
|
|
lastTick = gameTime.TotalGameTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-07 18:15:15 +00:00
|
|
|
|
public override void LoadContent(AxiosGameScreen gameScreen)
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 03:07:51 +00:00
|
|
|
|
public override void HandleInput(AxiosGameScreen gameScreen, InputState input, Microsoft.Xna.Framework.GameTime gameTime)
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 03:07:51 +00:00
|
|
|
|
public override void HandleCursor(AxiosGameScreen gameScreen, InputState input)
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-07 18:15:15 +00:00
|
|
|
|
public override void UnloadContent(AxiosGameScreen gameScreen)
|
2012-03-19 23:57:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|