可以在slick2d上更改TiledMaps吗?

时间:2014-10-25 19:19:41

标签: java slick2d

我正在努力做一个非常简单的游戏,你只是在房间里徘徊,当你使用门到达其他房间时。 以下是screen

的外观

我使用这个简单的if if to change

if(input.isKeyDown(Input.KEY_UP)) {
      sprite = up;
      if(!isBlocked(x,y - delta * 0.1f) && y > 0) {
         sprite.update(delta);                // lower delta = lower speed animation
          y -= delta * 0.1f;
      }
      if(isDoor(x,y - delta * 0.1f)) {
          currentMap = currentRoom.getNorth().getMap();
          currentRoom = currentRoom.getNorth();
      }
}

“currentMap”是目前正在渲染的TiledMap。 “currentRoom”是当前在其中有TiledMap的房间,因为我需要更多的东西来存储房间。问题在于,当我上门时,游戏立即关闭并使用空指针,但在崩溃之前,我可以看到地图被更改的一瞥。

完整错误报告:

ERROR:null
java.lang.NullPointerException
at not.zuul.world.GameMain.update(GameMain.java:143)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at not.zuul.world.GameMain.main(GameMain.java:40)
Sat Oct 25 21:18:51 CEST 2014 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:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at not.zuul.world.GameMain.main(GameMain.java:40)

一些额外的代码,这些代码在init上调用。房间 - 字符串的散列图,其中包含门的字母(键),以及有价值的瓷砖地图(由于门的组合不同,有15个不同的房间。

而game_map又是一个hashmap,其中String(名称)用于键,而Class Room用于值。我使用“setRooms”为那个房间设置“邻居”,或者在那些门通向的其他地方,订单是(北,南,东,西)

public void initAllRooms() throws SlickException {
    rooms = new HashMap<String, TiledMap>();
    rooms.put("N", new TiledMap("resources/map/Rooms/room_north.tmx"));
    rooms.put("S", new TiledMap("resources/map/Rooms/room_south.tmx"));
    rooms.put("E", new TiledMap("resources/map/Rooms/room_east.tmx"));
    rooms.put("W", new TiledMap("resources/map/Rooms/room_west.tmx"));
    rooms.put("NE", new TiledMap("resources/map/Rooms/room_north_east.tmx"));
    rooms.put("NS", new TiledMap("resources/map/Rooms/room_north_south.tmx"));
    rooms.put("NW", new TiledMap("resources/map/Rooms/room_north_west.tmx"));
    rooms.put("SE", new TiledMap("resources/map/Rooms/room_south_east.tmx"));
    rooms.put("SW", new TiledMap("resources/map/Rooms/room_south_west.tmx"));
    rooms.put("EW", new TiledMap("resources/map/Rooms/room_east_west.tmx"));
    rooms.put("NSE", new TiledMap("resources/map/Rooms/room_north_south_east.tmx"));
    rooms.put("NSW", new TiledMap("resources/map/Rooms/room_north_south_west.tmx"));
    rooms.put("NEW", new TiledMap("resources/map/Rooms/room_north_east_west.tmx"));
    rooms.put("SEW", new TiledMap("resources/map/Rooms/room_south_east_west.tmx"));
    rooms.put("NSEW", new TiledMap("resources/map/Rooms/room_north_south_east_west.tmx"));
}

public void initMap() throws SlickException {
    game_map = new HashMap<String, Room>();
    game_map.put("outside", new Room(rooms.get("N"), "You're outside."));
    game_map.put("mainHall", new Room(rooms.get("NSEW"), "You're in main hall."));
    game_map.put("emptyRoom", new Room(rooms.get("NE"), "You're in empty room."));
    game_map.put("bathRoom", new Room(rooms.get("S"), "You're in bathroom"));
    game_map.put("kitchen", new Room(rooms.get("NW"), "You're in kitchen"));
    game_map.put("diningRoom", new Room(rooms.get("NS"), "You;re in dining room"));
    game_map.put("backYard", new Room(rooms.get("SE"), "You're in back yard"));
    game_map.put("storageRoom", new Room(rooms.get("W"), "You're in storage room"));

    game_map.get("outside").setRooms(game_map.get("mainHall"), null, null, null);
    game_map.get("mainHall").setRooms(game_map.get("diningRoom"), game_map.get("outside"),
            game_map.get("emptyRoom"), game_map.get("kitchen"));
    game_map.get("emptyRoom").setRooms(game_map.get("bathRoom"), null, game_map.get("mainHall"), null );
    game_map.get("bathRoom").setRooms(null, game_map.get("emptyRoom"), null, null);
    game_map.get("kitchen").setRooms(null, null, null, game_map.get("mainHall"));
    game_map.get("diningRoom").setRooms(game_map.get("backYard"), game_map.get("mainHall)"), null, null);
    game_map.get("backYard").setRooms(null, game_map.get("diningRoom"), game_map.get("storageRoom"), null);
    game_map.get("storageRoom").setRooms(null, null, null, game_map.get("backYard"));

}

1 个答案:

答案 0 :(得分:-1)

除非你提供堆栈跟踪和堆栈跟踪来自的行,否则无法提供帮助。

编辑:仍然需要查看崩溃发生在哪一行。