So I used the following post to help me render my isometric map in Slick2D:
Slick2D Isometric TiledMap Rendering Problem
Big thanks and credit to arminb for the code supplied and for the fix to be able to use it.
My question is, how would I go about getting the properties of the isometric tiles. I have a little character that can walk around on the map, but he can walk on the blocked tiles. I have no code to be able to detect the properties.
This is the code I am using. The map is generated correctly, and the character is generated correctly.
How would I get the properties of a tile that I walk on?
import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;
public class Game extends BasicGame {
private TiledMap map;
private Animation sprite, up, down, left, right;
private float x = 350f, y = 250f;
public static void main(String[] args) throws SlickException {
AppGameContainer app = new AppGameContainer(new Game());
app.setDisplayMode(800, 600, false);
app.setShowFPS(true);
app.start();
}
public Game() {
super("Test");
}
@Override
public void render(GameContainer arg0, Graphics arg1) throws SlickException {
map.render(350, 250);
sprite.draw((int)x, (int)y);
}
@Override
public void init(GameContainer arg0) throws SlickException {
Image [] movementUp = {new Image("data/wiz_up_one.jpg"),
new Image("data/wiz_up_two.jpg")};
Image [] movementDown = {new Image("data/wiz_down_one.jpg"),
new Image("data/wiz_down_two.jpg")};
Image [] movementLeft = {new Image("data/wiz_left_one.jpg"),
new Image("data/wiz_left_two.jpg")};
Image [] movementRight = {new Image("data/wiz_right_one.jpg"),
new Image("data/wiz_right_two.jpg")};
int [] duration = {300, 300};
up = new Animation(movementUp, duration, false);
down = new Animation(movementDown, duration, false);
left = new Animation(movementLeft, duration, false);
right = new Animation(movementRight, duration, false);
// Original orientation of the sprite. It will look right.
sprite = right;
map = new TiledMap("data/iso.tmx"); //path is valid!
}
@Override
public void update(GameContainer gc, int delta) throws SlickException {
Input input = gc.getInput();
if (input.isKeyDown(Input.KEY_UP))
{
sprite = up;
sprite.update(delta);
// The lower the delta the slowest the sprite will animate.
y -= delta * 0.1f;
}
else if (input.isKeyDown(Input.KEY_DOWN))
{
sprite = down;
sprite.update(delta);
y += delta * 0.1f;
}
else if (input.isKeyDown(Input.KEY_LEFT))
{
sprite = left;
sprite.update(delta);
x -= delta * 0.1f;
}
else if (input.isKeyDown(Input.KEY_RIGHT))
{
sprite = right;
sprite.update(delta);
x += delta * 0.1f;
}
}
}
enter code here