package de.rico.adventure.actions.custom;

import javax.media.opengl.GL;

import de.rico.adventure.actions.AbstractAction;
import de.rico.adventure.actions.ActionScheduler;

/**
 * This game action can be used to delay the game for a specified amount
 * of miliseconds.
 * @author Frank Bruns
 *
 */
public class Delay extends AbstractAction
{
	private int delay = 0;
	private int cumulatedTime = 0;

	/**
	 * Creates a new delay game action with the specified amount
	 * of time.
	 * @param delay  time in miliseconds to delay the game
	 */
	public Delay(int delay)
	{
		this.delay = delay;
	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#update(long)
	 */
	@Override
	public void update(long elapsedTime)
	{
		this.cumulatedTime += elapsedTime;

		// if the delayed time has ended kill the game action
		if(this.cumulatedTime >= this.delay)
			ActionScheduler.getInstance().removeFirst();

	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#draw(javax.media.opengl.GL)
	 */
	@Override
	public void draw(GL gl)
	{
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see de.rico.adventure.actions.AbstractAction#finishUp()
	 */
	@Override
	public void finishUp()
	{
		// do nothing
	}
}
