[Add] Collision Detection

This commit is contained in:
Ritchie Cunningham 2022-03-07 13:58:36 +00:00
parent e1203e42b0
commit 97b1e857b0
4 changed files with 23 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -78,11 +78,17 @@ public class Map implements Drawable {
mapVertexArray.draw(target, newStates);
}
public Tile getTile(Location l) {
Vector2i position = l.getPosition();
Tile t = tileArray[position.x][position.y];
return t;
}
public boolean isValidLocation(Location l) {
Vector2i coordinates = l.getPosition();
return ((coordinates.x >= 0) && (coordinates.y >=0) &&
(coordinates.x < mapDimensions.x) &&
(coordinates.y < mapDimensions.y));
(coordinates.y < mapDimensions.y) && Tile.getCanWalkOn(getTile(l)));
}
}

View File

@ -30,4 +30,20 @@ public enum Tile {
public static int getSize() {
return tileSize;
}
public static boolean getCanWalkOn(Tile t) {
boolean able = false;
switch(t) {
case WATER:
able = false;
break;
case SAND:
able = true;
break;
case GRASS:
able = true;
break;
}
return able;
}
}