Search in sources :

Example 21 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class MapObjectLoaderTests method testColliderMapObjectLoader.

@Test
public void testColliderMapObjectLoader() {
    CollisionBoxMapObjectLoader loader = new CollisionBoxMapObjectLoader();
    IEnvironment environment = mock(IEnvironment.class);
    IMapObject mapObject = mock(IMapObject.class);
    when(mapObject.getType()).thenReturn(MapObjectType.COLLISIONBOX.name());
    when(mapObject.getId()).thenReturn(111);
    when(mapObject.getName()).thenReturn("testCollider");
    when(mapObject.getLocation()).thenReturn(new Point(100, 100));
    when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
    when(mapObject.getWidth()).thenReturn(200);
    when(mapObject.getHeight()).thenReturn(200);
    Collection<IEntity> entities = loader.load(environment, mapObject);
    Optional<IEntity> opt = entities.stream().findFirst();
    assertTrue(opt.isPresent());
    IEntity entity = entities.stream().findFirst().get();
    assertNotNull(entity);
    assertEquals(entity.getMapId(), 111);
    assertEquals(entity.getName(), "testCollider");
    assertEquals(entity.getLocation().getX(), 100, 0.0001);
    assertEquals(entity.getLocation().getY(), 100, 0.0001);
    CollisionBox collider = (CollisionBox) entity;
    assertEquals(collider.getCollisionBoxWidth(), 200.0, 0.0001);
    assertEquals(collider.getCollisionBoxHeight(), 200.0, 0.0001);
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox) Test(org.junit.jupiter.api.Test)

Example 22 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class PropertyPanel method updateEnvironment.

protected void updateEnvironment() {
    if (getDataSource() instanceof IMapObject) {
        IMapObject obj = (IMapObject) getDataSource();
        Game.getEnvironment().reloadFromMap(obj.getId());
        if (MapObjectType.get(obj.getType()) == MapObjectType.LIGHTSOURCE) {
            Game.getEnvironment().getAmbientLight().updateSection(getDataSource().getBoundingBox());
        }
    }
}
Also used : IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 23 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class Environment method loadFromMap.

@Override
public void loadFromMap(final int mapId) {
    for (final IMapObjectLayer layer : this.getMap().getMapObjectLayers()) {
        Optional<IMapObject> opt = layer.getMapObjects().stream().filter(mapObject -> mapObject.getType() != null && !mapObject.getType().isEmpty() && mapObject.getId() == mapId).findFirst();
        if (opt.isPresent()) {
            IMapObject mapObject = opt.get();
            this.addMapObject(mapObject);
            break;
        }
    }
}
Also used : Color(java.awt.Color) AmbientLight(de.gurkenlabs.litiengine.graphics.AmbientLight) Rectangle2D(java.awt.geom.Rectangle2D) Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) IMovementController(de.gurkenlabs.litiengine.physics.IMovementController) IMapLoader(de.gurkenlabs.litiengine.environment.tilemap.IMapLoader) Map(java.util.Map) FileUtilities(de.gurkenlabs.litiengine.util.io.FileUtilities) Trigger(de.gurkenlabs.litiengine.entities.Trigger) Creature(de.gurkenlabs.litiengine.entities.Creature) Shape(java.awt.Shape) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RenderType(de.gurkenlabs.litiengine.graphics.RenderType) Logger(java.util.logging.Logger) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Collectors(java.util.stream.Collectors) List(java.util.List) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) Optional(java.util.Optional) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) IEntityController(de.gurkenlabs.litiengine.entities.ai.IEntityController) Game(de.gurkenlabs.litiengine.Game) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Rectangle(java.awt.Rectangle) GeometricUtilities(de.gurkenlabs.litiengine.util.geom.GeometricUtilities) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox) IMap(de.gurkenlabs.litiengine.environment.tilemap.IMap) MapUtilities(de.gurkenlabs.litiengine.environment.tilemap.MapUtilities) Quality(de.gurkenlabs.litiengine.configuration.Quality) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Graphics2D(java.awt.Graphics2D) StaticShadowLayer(de.gurkenlabs.litiengine.graphics.StaticShadowLayer) Prop(de.gurkenlabs.litiengine.entities.Prop) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) ICollisionEntity(de.gurkenlabs.litiengine.entities.ICollisionEntity) MapProperty(de.gurkenlabs.litiengine.environment.tilemap.MapProperty) IRenderable(de.gurkenlabs.litiengine.graphics.IRenderable) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) TmxMapLoader(de.gurkenlabs.litiengine.environment.tilemap.TmxMapLoader) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) Consumer(java.util.function.Consumer) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType) TimeUtilities(de.gurkenlabs.litiengine.util.TimeUtilities) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) StaticShadowType(de.gurkenlabs.litiengine.graphics.StaticShadowType) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) Collections(java.util.Collections) IUpdateable(de.gurkenlabs.litiengine.IUpdateable) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Aggregations

IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)23 IEntity (de.gurkenlabs.litiengine.entities.IEntity)7 Dimension (java.awt.Dimension)6 Point (java.awt.Point)5 Test (org.junit.jupiter.api.Test)5 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)4 Point2D (java.awt.geom.Point2D)4 Rectangle2D (java.awt.geom.Rectangle2D)4 IMapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)3 MapObjectType (de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)3 BasicStroke (java.awt.BasicStroke)3 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)2 Prop (de.gurkenlabs.litiengine.entities.Prop)2 Trigger (de.gurkenlabs.litiengine.entities.Trigger)2 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)2 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)2 Color (java.awt.Color)2 Stroke (java.awt.Stroke)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2