use of org.apollo.game.model.area.collision.CollisionUpdate.DirectionFlag in project apollo by apollo-rsps.
the class CollisionManager method apply.
/**
* Apply a {@link CollisionUpdate} to the game world.
*
* @param update The update to apply.
*/
public void apply(CollisionUpdate update) {
Region prev = null;
CollisionUpdateType type = update.getType();
Map<Position, Collection<DirectionFlag>> map = update.getFlags().asMap();
for (Map.Entry<Position, Collection<DirectionFlag>> entry : map.entrySet()) {
Position position = entry.getKey();
int height = position.getHeight();
if (bridges.contains(new Position(position.getX(), position.getY(), 1))) {
if (--height < 0) {
continue;
}
}
if (prev == null || !prev.contains(position)) {
prev = regions.fromPosition(position);
}
int localX = position.getX() % Region.SIZE;
int localY = position.getY() % Region.SIZE;
CollisionMatrix matrix = prev.getMatrix(height);
CollisionFlag[] mobs = CollisionFlag.mobs();
CollisionFlag[] projectiles = CollisionFlag.projectiles();
for (DirectionFlag flag : entry.getValue()) {
Direction direction = flag.getDirection();
if (direction == Direction.NONE) {
continue;
}
int orientation = direction.toInteger();
if (flag.isImpenetrable()) {
flag(type, matrix, localX, localY, projectiles[orientation]);
}
flag(type, matrix, localX, localY, mobs[orientation]);
}
}
}
Aggregations