diff --git a/src/org/apollo/game/model/area/Sector.java b/src/org/apollo/game/model/area/Sector.java index 3f582fe1..642ef928 100644 --- a/src/org/apollo/game/model/area/Sector.java +++ b/src/org/apollo/game/model/area/Sector.java @@ -52,7 +52,7 @@ public final class Sector { /** * 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. @@ -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 * coordinate pair. * - * @param x The x coordinate. - * @param y The y coordinate. + * @param position The {@link Position} of the tile. * @param entity The {@link EntityType}. * @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. */ - 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); } diff --git a/src/org/apollo/game/model/area/collision/CollisionMatrix.java b/src/org/apollo/game/model/area/collision/CollisionMatrix.java index 6c370591..075c49a8 100644 --- a/src/org/apollo/game/model/area/collision/CollisionMatrix.java +++ b/src/org/apollo/game/model/area/collision/CollisionMatrix.java @@ -15,6 +15,20 @@ import com.google.common.base.Preconditions; */ 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. */ @@ -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. */ 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; switch (direction) {