mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Add height level support to matrices in Sector.
This commit is contained in:
@@ -52,7 +52,7 @@ public final class Sector {
|
|||||||
/**
|
/**
|
||||||
* The CollisionMatrix.
|
* The CollisionMatrix.
|
||||||
*/
|
*/
|
||||||
private final CollisionMatrix matrix = new CollisionMatrix(SECTOR_SIZE, SECTOR_SIZE);
|
private final CollisionMatrix[] matrices = CollisionMatrix.createMatrices(Position.HEIGHT_LEVELS, SECTOR_SIZE, SECTOR_SIZE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sector.
|
* Creates a new sector.
|
||||||
@@ -207,13 +207,15 @@ public final class Sector {
|
|||||||
* Returns whether or not an Entity of the specified {@link EntityType type} can traverse the tile at the specified
|
* Returns whether or not an Entity of the specified {@link EntityType type} can traverse the tile at the specified
|
||||||
* coordinate pair.
|
* coordinate pair.
|
||||||
*
|
*
|
||||||
* @param x The x coordinate.
|
* @param position The {@link Position} of the tile.
|
||||||
* @param y The y coordinate.
|
|
||||||
* @param entity The {@link EntityType}.
|
* @param entity The {@link EntityType}.
|
||||||
* @param direction The {@link Direction} the Entity is approaching from.
|
* @param direction The {@link Direction} the Entity is approaching from.
|
||||||
* @return {@code true} if the tile at the specified coordinate pair is traversable, {@code false} if not.
|
* @return {@code true} if the tile at the specified coordinate pair is traversable, {@code false} if not.
|
||||||
*/
|
*/
|
||||||
public boolean traversable(int x, int y, EntityType entity, Direction direction) {
|
public boolean traversable(Position position, EntityType entity, Direction direction) {
|
||||||
|
CollisionMatrix matrix = matrices[position.getHeight()];
|
||||||
|
int x = position.getLocalX(), y = position.getLocalY();
|
||||||
|
|
||||||
return matrix.traversable(x, y, entity, direction);
|
return matrix.traversable(x, y, entity, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,20 @@ import com.google.common.base.Preconditions;
|
|||||||
*/
|
*/
|
||||||
public final class CollisionMatrix {
|
public final class CollisionMatrix {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an array of CollisionMatrix objects, all of the specified width and length.
|
||||||
|
*
|
||||||
|
* @param count The length of the array to create.
|
||||||
|
* @param width The width of each CollisionMatrix.
|
||||||
|
* @param length The length of each CollisionMatrix.
|
||||||
|
* @return The array of CollisionMatrix objects.
|
||||||
|
*/
|
||||||
|
public static CollisionMatrix[] createMatrices(int count, int width, int length) {
|
||||||
|
CollisionMatrix[] matrices = new CollisionMatrix[count];
|
||||||
|
Arrays.setAll(matrices, index -> new CollisionMatrix(width, length));
|
||||||
|
return matrices;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that all types of traversal are allowed.
|
* Indicates that all types of traversal are allowed.
|
||||||
*/
|
*/
|
||||||
@@ -174,7 +188,7 @@ public final class CollisionMatrix {
|
|||||||
* @return {@code true} if the tile at the specified coordinate pair is traversable, {@code false} if not.
|
* @return {@code true} if the tile at the specified coordinate pair is traversable, {@code false} if not.
|
||||||
*/
|
*/
|
||||||
public boolean traversable(int x, int y, EntityType entity, Direction direction) {
|
public boolean traversable(int x, int y, EntityType entity, Direction direction) {
|
||||||
CollisionFlag[] flags = (entity == EntityType.PROJECTILE) ? CollisionFlag.projectiles() : CollisionFlag.mobs();
|
CollisionFlag[] flags = CollisionFlag.forType(entity);
|
||||||
int north = 0, east = 1, south = 2, west = 3;
|
int north = 0, east = 1, south = 2, west = 3;
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
|
|||||||
Reference in New Issue
Block a user