Search in sources :

Example 1 with DirectionFlag

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]);
        }
    }
}
Also used : Position(org.apollo.game.model.Position) DirectionFlag(org.apollo.game.model.area.collision.CollisionUpdate.DirectionFlag) Direction(org.apollo.game.model.Direction) Region(org.apollo.game.model.area.Region) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

Collection (java.util.Collection)1 Map (java.util.Map)1 Direction (org.apollo.game.model.Direction)1 Position (org.apollo.game.model.Position)1 Region (org.apollo.game.model.area.Region)1 DirectionFlag (org.apollo.game.model.area.collision.CollisionUpdate.DirectionFlag)1