// Path: hermes/Hermes.java
// public class Hermes {
// 	
// 	private static PApplet _parentApplet = null; //Storage of sketch's PApplet. 
// 	private static float _timeScale = 1.0f; // the time scale used by Hermes motion and physics calculations
// 	
// 	/**
// 	 * Sets the time scale for calculating motion and physics. This is seconds/unit, so a value of 2 will mean
// 	 * 	each 2 seconds correspond to one time unit.
// 	 * @param scale
// 	 */
// 	public static void setTimeScale(float scale) {
// 		_timeScale = scale;
// 	}
// 	
// 	/**
// 	 * Returns the Hermes time scale.
// 	 * @return	the time scale
// 	 */
// 	public static float getTimeScale() {
// 		return _timeScale;
// 	}
// 	
// 	/**
// 	 * Returns the <code>PApplet</code> that Hermes is running in.
// 	 */
// 	public static PApplet getPApplet() {
// 		synchronized(_parentApplet) {
// 			return _parentApplet;
// 		}
// 	}
// 	
// 	/**
// 	 * Set the PApplet that all utilities use. Called <code>Hermes.setPApplet(this)</code> before doing anything else!
// 	 */
// 	public static void setPApplet(PApplet parentApplet) {
// 		_parentApplet = parentApplet;		
// 	}
// 	
// 	/**
// 	 * Causes the calling thread to sleep, catches InterruptedException.
// 	 * @param time	the time (in milliseconds) to sleep
// 	 */
// 	public static void unsafeSleep(long time) {
// 		try {
// 			Thread.sleep(time);
// 		} catch (InterruptedException e) {}
// 	}
// 	
// }


import hermes.Hermes;
import java.util.ArrayList;
import processing.core.*;
package hermes.animation;



/**
 * <p>This class is used to store the PImages that make up a single animation and some properties
 * that aid in playing that animation. These properties values should be thought of as "default"
 * for this particular Animation, values that you know will work well or be used the most often. </p>
 * 
 * <p>The key properties are:</p>
 * <ul>
 * <li>millisecondsPerFrame - specifies the rate at which the frames should be advanced. In other words, 
 * how long a given frame appears on screen before advancing to the next.
 *
 * <li>interruptible - This is used to determine what happens when an AnimatedSprite's setActiveAnimation is called while this Animation is playing. 
 * By default, this is set to true on construction.
 * <p>If set to true, the AnimatedSprite will immediately switch to the new Animation.</p>
 * <p>If set to false, this Animation will play to completion before changing 
 * If numberOfTimesToPlay is set to INFINITE_LOOPS, it will play to the end of the cycle before switching. 
 * Otherwise, the Animation will play through the remaining cycles it has left before switching.
 * Upon completion of playback, if setActiveAnimation has been called one or more times, the 
 * AnimatedSprite's activeAnimation will be set to the one specified by the most recent call.</p>
 * 
 * 
 * <li><p>numberOfTimesToPlay - Specifies how many times this animation will play.
 * It can be set to any positive integer value, or INFINITE_LOOPS for looping the Animation
 * infinitely. By default, this is set to INFINITE_LOOPS on construction.
 * If the animation completes playing through its numberOfTimesToPlay and no calls
 * to AnimatedSprite's setActiveAnimation were made, the Animation will display its defaultFrame.
 * 
 * <li><p>defaultFrame - the index of the frame that completed animations will rest on. By default
 * this is set to 0 (the first frame in the Animation) on construction.
 * </ul>
 */
public class Animation implements AnimationConstants {

	private int _millisecondsPerFrame; //in milliseconds
	private boolean _isInterruptible = true; //this specifies if the Animation can be escaped at on any frame
	private int _numberOfTimesToPlay = INFINITE_LOOPS;
	private int _defaultFrame = 0;

	ArrayList<PImage> _frames; //Collection of each frame used in the Animation


	/**
	 * Builds an Animation from several image files on disk (where each is an individual frame in the Animation), and adds it to the Sprite's collection of Animations
	 * 
	 * <p>The method loads files with numbers starting from 0 to (numberOfImagesToLoad-1) and assumes numerical contiguity
	 * <br>ex. Explosion0.jpg, Explosion1.jpg, Explosion2.jpg would have method call:
	 * <br>addAnimationFromSequenceOfImages("Explosion", 3, ".jpg");</P>
	 * 
	 * <p>Works with all image filetypes supported by PImage: .gif, .jgp, tga, .png</p>
	 * 
	 * @param imageSequenceNamePrefix 	file prefix of all of the images to be loaded into this Animation ex. "Explosion"
	 * @param numberOfImagesToLoad		total number of images to load (note: your names should be indexed starting from 0)
	 * @param fileType					file extension including the 'dot' - supports: ".gif" ".jgp" ".tga" ".png"
	 * @param millisecondsPerFrame		amount of time each frame in the Animation is displayed, in milliseconds

	 */
	public Animation(String imageSequenceNamePrefix, int numberOfImagesToLoad, String fileType, int millisecondsPerFrame) {
		//asserts to check for valid inputs
		assert supportImageType(fileType): "addAnimation Error: Images of filetype: "+fileType+"not supported.\n Suported types: .gif, .jgp, tga, .png";

		_millisecondsPerFrame = millisecondsPerFrame;
		
		ArrayList<PImage> currentAnimation = new ArrayList<PImage>(); // make an ArrayList to store Animation being built

		//populates current Animation with the files named: <imageSequenceNamePrefix>i<fileType>
		//ex. Explosion4.jpg
		for (int i = 0; i < numberOfImagesToLoad; i++) { 
// Path: hermes/Hermes.java
// public class Hermes {
// 	
// 	private static PApplet _parentApplet = null; //Storage of sketch's PApplet. 
// 	private static float _timeScale = 1.0f; // the time scale used by Hermes motion and physics calculations
// 	
// 	/**
// 	 * Sets the time scale for calculating motion and physics. This is seconds/unit, so a value of 2 will mean
// 	 * 	each 2 seconds correspond to one time unit.
// 	 * @param scale
// 	 */
// 	public static void setTimeScale(float scale) {
// 		_timeScale = scale;
// 	}
// 	
// 	/**
// 	 * Returns the Hermes time scale.
// 	 * @return	the time scale
// 	 */
// 	public static float getTimeScale() {
// 		return _timeScale;
// 	}
// 	
// 	/**
// 	 * Returns the <code>PApplet</code> that Hermes is running in.
// 	 */
// 	public static PApplet getPApplet() {
// 		synchronized(_parentApplet) {
// 			return _parentApplet;
// 		}
// 	}
// 	
// 	/**
// 	 * Set the PApplet that all utilities use. Called <code>Hermes.setPApplet(this)</code> before doing anything else!
// 	 */
// 	public static void setPApplet(PApplet parentApplet) {
// 		_parentApplet = parentApplet;		
// 	}
// 	
// 	/**
// 	 * Causes the calling thread to sleep, catches InterruptedException.
// 	 * @param time	the time (in milliseconds) to sleep
// 	 */
// 	public static void unsafeSleep(long time) {
// 		try {
// 			Thread.sleep(time);
// 		} catch (InterruptedException e) {}
// 	}
// 	
// }


// Path: hermes/animation/Animation.java
import hermes.Hermes;
import java.util.ArrayList;
import processing.core.*;

package hermes.animation;



/**
 * <p>This class is used to store the PImages that make up a single animation and some properties
 * that aid in playing that animation. These properties values should be thought of as "default"
 * for this particular Animation, values that you know will work well or be used the most often. </p>
 * 
 * <p>The key properties are:</p>
 * <ul>
 * <li>millisecondsPerFrame - specifies the rate at which the frames should be advanced. In other words, 
 * how long a given frame appears on screen before advancing to the next.
 *
 * <li>interruptible - This is used to determine what happens when an AnimatedSprite's setActiveAnimation is called while this Animation is playing. 
 * By default, this is set to true on construction.
 * <p>If set to true, the AnimatedSprite will immediately switch to the new Animation.</p>
 * <p>If set to false, this Animation will play to completion before changing 
 * If numberOfTimesToPlay is set to INFINITE_LOOPS, it will play to the end of the cycle before switching. 
 * Otherwise, the Animation will play through the remaining cycles it has left before switching.
 * Upon completion of playback, if setActiveAnimation has been called one or more times, the 
 * AnimatedSprite's activeAnimation will be set to the one specified by the most recent call.</p>
 * 
 * 
 * <li><p>numberOfTimesToPlay - Specifies how many times this animation will play.
 * It can be set to any positive integer value, or INFINITE_LOOPS for looping the Animation
 * infinitely. By default, this is set to INFINITE_LOOPS on construction.
 * If the animation completes playing through its numberOfTimesToPlay and no calls
 * to AnimatedSprite's setActiveAnimation were made, the Animation will display its defaultFrame.
 * 
 * <li><p>defaultFrame - the index of the frame that completed animations will rest on. By default
 * this is set to 0 (the first frame in the Animation) on construction.
 * </ul>
 */
public class Animation implements AnimationConstants {

	private int _millisecondsPerFrame; //in milliseconds
	private boolean _isInterruptible = true; //this specifies if the Animation can be escaped at on any frame
	private int _numberOfTimesToPlay = INFINITE_LOOPS;
	private int _defaultFrame = 0;

	ArrayList<PImage> _frames; //Collection of each frame used in the Animation


	/**
	 * Builds an Animation from several image files on disk (where each is an individual frame in the Animation), and adds it to the Sprite's collection of Animations
	 * 
	 * <p>The method loads files with numbers starting from 0 to (numberOfImagesToLoad-1) and assumes numerical contiguity
	 * <br>ex. Explosion0.jpg, Explosion1.jpg, Explosion2.jpg would have method call:
	 * <br>addAnimationFromSequenceOfImages("Explosion", 3, ".jpg");</P>
	 * 
	 * <p>Works with all image filetypes supported by PImage: .gif, .jgp, tga, .png</p>
	 * 
	 * @param imageSequenceNamePrefix 	file prefix of all of the images to be loaded into this Animation ex. "Explosion"
	 * @param numberOfImagesToLoad		total number of images to load (note: your names should be indexed starting from 0)
	 * @param fileType					file extension including the 'dot' - supports: ".gif" ".jgp" ".tga" ".png"
	 * @param millisecondsPerFrame		amount of time each frame in the Animation is displayed, in milliseconds

	 */
	public Animation(String imageSequenceNamePrefix, int numberOfImagesToLoad, String fileType, int millisecondsPerFrame) {
		//asserts to check for valid inputs
		assert supportImageType(fileType): "addAnimation Error: Images of filetype: "+fileType+"not supported.\n Suported types: .gif, .jgp, tga, .png";

		_millisecondsPerFrame = millisecondsPerFrame;
		
		ArrayList<PImage> currentAnimation = new ArrayList<PImage>(); // make an ArrayList to store Animation being built

		//populates current Animation with the files named: <imageSequenceNamePrefix>i<fileType>
		//ex. Explosion4.jpg
		for (int i = 0; i < numberOfImagesToLoad; i++) { 
			PImage currentImage = Hermes.getPApplet().loadImage(imageSequenceNamePrefix + i + fileType);