diff --git a/core/src/com/me/pacman/level/Level.java b/core/src/com/me/pacman/level/Level.java index 77b2836..79d3d66 100644 --- a/core/src/com/me/pacman/level/Level.java +++ b/core/src/com/me/pacman/level/Level.java @@ -13,6 +13,9 @@ public class Level { // Grid of tiles, [rows][columns] public LevelTile[][] tiles; + public int width; + public int height; + public Level(PacDude game, String level) { this.game = game; @@ -22,10 +25,13 @@ public class Level { LevelLoader loader = new LevelLoader(level); tiles = loader.loadLevel(); + + height = tiles.length; + width = tiles[0].length; } public LevelTile getTile(int x, int y) { - return tiles[y][x]; + return y >= 0 && y < height && x >= 0 && x < width ? tiles[y][x] : null; } public LevelTile getTile(float x, float y) {