Hi!
I'm new with slick, and I want to train myself doing little game. My first goal now is to move my Image(Mario!) in my map, and stop the movement if there is a wall.
So to do it I did my map with MapEditor. I did 2 TileSet :
Wall: I set a property(blocked) and I put the value 'yes'.
Floor: It's my grass, where my character can walk. No porperty on it.
So no i can move my character in my map but he can move on the "wall" too. And I want to resolve it. So I tried this in my code:
Code:
public void update(GameContainer c, int delta) throws SlickException
{
// I have an attibute call map, to call my tilemap.so the type of map is
//tiledmap.
Input in=c.getInput();
if (in.isKeyDown(Input.KEY_UP)){
int id=(int)x+1;
boolean blocked = "yes".equals(map.getTileProperty(id, "blocked", "non"));
if(!blocked)
x++;
}
}
But this code doesn't works. I have this error:
Code:
Thu Mar 25 07:47:17 CET 2010 ERROR:null
java.lang.NullPointerException
at org.newdawn.slick.tiled.TiledMap.getTileProperty(TiledMap.java:297)
at Main.update(Main.java:82)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:657)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at Main.main(Main.java:56)
Thu Mar 25 07:47:17 CET 2010 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at Main.main(Main.java:56)
I don't understand..... what do I must to do?
Is there a better way? Why my code doesn't works?
Thanks.