Commit f3aa8531 authored by Fardale's avatar Fardale

Merge branch 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project

parents a3303303 66204c4f
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;
......
......@@ -28,6 +28,7 @@ public class GroundTileSprite extends TileSprite
{
for (int i = 0; i < 4; i++)
{
// i%2 -> i ; i/2 -> j
spriteTable[k][i] = sprite.getSubimage((4*k + 3 * (i % 2)) * TileSpriteWidth(), (2 + 3 * (i / 2)) * TileSpriteHeight(), TileSpriteWidth(), TileSpriteHeight());
spriteTable[k][4 + i] = sprite.getSubimage((4*k + 1 + 2 * (i % 2) - (i / 2)) * TileSpriteWidth(), (2 + (i % 2) + 2 * (i / 2)) * TileSpriteHeight(), TileSpriteWidth(), TileSpriteHeight());
spriteTable[k][8 + i] = sprite.getSubimage((4*k + 2 * (i % 2) + (i / 2)) * TileSpriteWidth(), (3 - (i % 2) + 2 * (i / 2)) * TileSpriteHeight(), TileSpriteWidth(), TileSpriteHeight());
......
......@@ -26,6 +26,7 @@ public class WallTileSprite extends TileSprite
{
for (int i = 0; i < 4; i++)
{
// i%2 -> i ; i/2 -> j
spriteTable[k][i] = sprite.getSubimage((6*k + 5*(i % 2)) * TileSpriteWidth(), (2 + 5 * (i / 2)) * TileSpriteHeight(), TileSpriteWidth(), TileSpriteHeight());
spriteTable[k][4 + i] = sprite.getSubimage((6*k + 4 + (i % 2)) * TileSpriteWidth(), ((i / 2)) * TileSpriteHeight(), TileSpriteWidth(), TileSpriteHeight());
spriteTable[k][8 + i] = sprite.getSubimage((6*k + 2 + 3 * (i % 2) - 2 * (i / 2)) * TileSpriteWidth(), (2 + 2 * (i % 2) + 3 * (i / 2)) * TileSpriteHeight(), TileSpriteWidth(), TileSpriteHeight());
......@@ -69,6 +70,7 @@ public class WallTileSprite extends TileSprite
}
return result;
}
@Override
public char[][] getChar(TileAbstractType[][] mask) {
char result[][] = new char[2][2];
......
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