Commit 66204c4f authored by Colin Thomas's avatar Colin Thomas

Adding of classes necessary to make animations (unused for now)

parent d5d379a4
package graphics.guiSkeleton.sprites;
import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Colin on 30/12/15.
*/
public class Animation implements Serializable, Displayable
{
// global counter incremented each time we display game panel
private static int globalCounter = 0;
// local counter owned by the instance, used to know if the instance has to be updated
private int localCounter = globalCounter;
// local counter used to know when we are in the displaying of a frame
private int inFrameCounter = 0;
private int currentFrame = 0;
private List<Frame> frames = new ArrayList<Frame>();
public Animation(Sprite spriteSheet, int[] delayTable)
{
for (int i = 0 ; i < delayTable.length ; i++)
{
int width = spriteSheet.getSpriteImage().getWidth();
int height = spriteSheet.getSpriteImage().getHeight();
frames.add(new Frame(spriteSheet.getSpriteImage().getSubimage(i*width, 0, width, height), delayTable[i]));
}
}
public Animation(Sprite[] sprites, int[] delayTable)
{
for (int i = 0 ; i < delayTable.length ; i++)
{
frames.add(new Frame(sprites[i].getSpriteImage(), delayTable[i]));
}
}
public Animation(Sprite spriteSheet, int nbFrames, int delay)
{
for (int i = 0 ; i < nbFrames ; i++)
{
int width = spriteSheet.getSpriteImage().getWidth();
int height = spriteSheet.getSpriteImage().getHeight();
frames.add(new Frame(spriteSheet.getSpriteImage().getSubimage(i*width, 0, width, height), delay));
}
}
public Animation(Sprite[] sprites, int delay)
{
for (int i = 0 ; i < sprites.length ; i++)
{
frames.add(new Frame(sprites[i].getSpriteImage(), delay));
}
}
private void update()
{
localCounter ++;
inFrameCounter ++;
if (inFrameCounter > frames.get(currentFrame).getDelay())
{
inFrameCounter = 0;
currentFrame ++;
if (currentFrame >= frames.size())
currentFrame = 0;
}
}
public static void updateAnimation()
{
globalCounter++;
}
public BufferedImage getSpriteImage()
{
while (localCounter < globalCounter)
update();
return frames.get(currentFrame).getSpriteImage();
}
}
package graphics.guiSkeleton.sprites;
import java.awt.image.BufferedImage;
/**
* Created by Colin on 30/12/15.
*/
public interface Displayable
{
BufferedImage getSpriteImage();
}
package graphics.guiSkeleton.sprites;
import java.awt.image.BufferedImage;
import java.io.Serializable;
/**
* Created by Colin on 30/12/15.
*/
public class Frame implements Serializable
{
private BufferedImage spriteImage;
private int delay;
public Frame(BufferedImage arg_spriteImage, int arg_delay)
{
spriteImage = arg_spriteImage;
if(arg_delay > 0)
delay = arg_delay;
else
delay = 0;
}
public BufferedImage getSpriteImage()
{
return spriteImage;
}
protected int getDelay()
{
return delay;
}
}
package graphics.guiSkeleton.sprites;
import java.awt.image.BufferedImage;
import java.awt.peer.DialogPeer;
import java.io.Serializable;
/**
* Created by dupriez on 03/11/15.
*/
public class Sprite implements Serializable{
public class Sprite implements Serializable, Displayable{
private static final long serialVersionUID = 1L;
protected BufferedImage spriteImage;
private BufferedImage spriteImage;
public final BufferedImage getSpriteImage() {
return spriteImage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment