package pelletQuest.map;
import pelletQuest.resources.GraphicsManager;
import org.newdawn.slick.geom.Vector2f;
public class Tile {
protected String terrain;
protected Vector2f[] images;
protected int timer;
protected int delay;
public Tile (String compiledTile) {
if (compiledTile.charAt(0) == '!') {
images = new Vector2f[new Integer(compiledTile.substring(1,2)).intValue()];
delay = new Integer(compiledTile.substring(2,6)).intValue();
for (int i=0; i < images.length; i++) {
int u = new Integer(compiledTile.substring(6+(i*4),8+(i*4))).intValue();
int v = new Integer(compiledTile.substring(8+(i*4),10+(i*4))).intValue();
images[i] = new Vector2f(u, v);
}
terrain = compiledTile.substring(6+(images.length*4));
} else {
delay = 1;
images = new Vector2f[1];
int u = new Integer(compiledTile.substring(0,2)).intValue();
int v = new Integer(compiledTile.substring(2,4)).intValue();
images[0] = new Vector2f(u, v);
terrain = compiledTile.substring(4);
}
}
public String getTerrain() {
return terrain;
}
public void draw(String spritesheet, int x, int y) {
int index = (timer/delay)%images.length;
GraphicsManager.getSprite(spritesheet, (int)images[index].x, (int)images[index].y).draw(x,y);
}
public String toString() {
return terrain;
}
public void update (int delta) {
timer += delta;
}
}