Bounds check on getTile

This commit is contained in:
Matt Low 2019-12-25 19:11:33 +04:00
parent 7bece08683
commit 347f8f5dba

View File

@ -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) {