How about you use a Queue<T>
?
There are 4 significant members of Queue<T>
you can use:
Queue.Enqueue(T item)
- put your item at the end of the queue.
T Queue.Peek()
- look at the first item without removing it.
T Queue.Dequeue()
- get and remove the first item.
Queue.Count
- check how many items are in queue.
Sample usage
Here's what could be a class representing moves:
public enum MoveType
{
Fireball, Jump, Block
}
public class Move
{
public MoveType MoveType { get; private set; }
public double Duration { get; private set; }
//...
public Move(MoveType moveType)
{
this.MoveType = moveType;
switch (moveType)
{
case MoveType.Fireball:
this.Duration = 1.0;
break;
case MoveType.Block:
this.Duration = 0.5;
break;
case MoveType.Jump:
this.Duration = 0.8;
break;
}
}
}
Your update checks to see if moves are elapsed:
Queue<Move> _moveQueue = new Queue<Move>();
double _elapsedMoveTime = 0;
public override void Update(GameTime gameTime)
{
if (_moveQueue.Count > 0)
{
_elapsedMoveTime += gameTime.ElapsedGameTime.TotalSeconds;
Move current = _moveQueue.Peek();
if (_elapsedMoveTime > current.Duration)
{
_elapsedMoveTime -= current.Duration;
_moveQueue.Dequeue();
}
}
else
{
_elapsedMoveTime = 0;
}
}
To add a move to the queue, simply call
_moveQueue.Enqueue(new Move(MoveType.Fireball));
To get the current move, simply
Move currentMove = _moveQueue.Peek();
if(currentMove.MoveType == MoveType.Fireball)
//...
Also - don't count the duration in frames, count it in seconds (or milliseconds if you must).