Bounds check on getTile
This commit is contained in:
parent
7bece08683
commit
347f8f5dba
@ -13,6 +13,9 @@ public class Level {
|
|||||||
// Grid of tiles, [rows][columns]
|
// Grid of tiles, [rows][columns]
|
||||||
public LevelTile[][] tiles;
|
public LevelTile[][] tiles;
|
||||||
|
|
||||||
|
public int width;
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
|
||||||
public Level(PacDude game, String level) {
|
public Level(PacDude game, String level) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
@ -22,10 +25,13 @@ public class Level {
|
|||||||
|
|
||||||
LevelLoader loader = new LevelLoader(level);
|
LevelLoader loader = new LevelLoader(level);
|
||||||
tiles = loader.loadLevel();
|
tiles = loader.loadLevel();
|
||||||
|
|
||||||
|
height = tiles.length;
|
||||||
|
width = tiles[0].length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LevelTile getTile(int x, int y) {
|
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) {
|
public LevelTile getTile(float x, float y) {
|
||||||
|
Loading…
Reference in New Issue
Block a user