[Add] Collision Detection
This commit is contained in:
parent
e1203e42b0
commit
97b1e857b0
Binary file not shown.
Binary file not shown.
@ -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)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user