Search in sources :

Example 6 with StaticGameObject

use of org.apollo.game.model.entity.obj.StaticGameObject in project apollo by apollo-rsps.

the class CollisionManagerTests method createCollisionManager.

/**
 * Sets up dependencies for and creates a stub {@link CollisionManager}, then builds the collision matrices
 * using the {@code objects} given.
 *
 * @param objects The objects to build collision matrices from.
 * @return A new {@link CollisionManager} with a valid {@link RegionRepository} and every {@link CollisionMatrix}
 * built.
 */
private static CollisionManager createCollisionManager(MapObject... objects) {
    World world = new World();
    RegionRepository regions = world.getRegionRepository();
    CollisionManager collisionManager = world.getCollisionManager();
    for (MapObject object : objects) {
        // treat local coordinates as absolute for simplicity
        int x = object.getLocalX(), y = object.getLocalY();
        int height = object.getHeight();
        Position position = new Position(x, y, height);
        Region region = regions.fromPosition(position);
        region.addEntity(new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation()), false);
    }
    collisionManager.build(false);
    return collisionManager;
}
Also used : Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) Region(org.apollo.game.model.area.Region) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) World(org.apollo.game.model.World) MapObject(org.apollo.cache.map.MapObject)

Aggregations

Position (org.apollo.game.model.Position)6 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)6 World (org.apollo.game.model.World)5 Region (org.apollo.game.model.area.Region)5 RegionRepository (org.apollo.game.model.area.RegionRepository)5 HashSet (java.util.HashSet)4 Entity (org.apollo.game.model.entity.Entity)4 Player (org.apollo.game.model.entity.Player)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ItemOnObjectMessage (org.apollo.game.message.impl.ItemOnObjectMessage)3 Inventory (org.apollo.game.model.inv.Inventory)3 MapObject (org.apollo.cache.map.MapObject)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 MapIndex (org.apollo.cache.map.MapIndex)1 MapObjectsDecoder (org.apollo.cache.map.MapObjectsDecoder)1 ObjectActionMessage (org.apollo.game.message.impl.ObjectActionMessage)1 Item (org.apollo.game.model.Item)1