Search in sources :

Example 16 with IMapObject

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

the class MapComponent method renderMapObjectBounds.

private void renderMapObjectBounds(Graphics2D g) {
    // render all entities
    for (final IMapObjectLayer layer : Game.getEnvironment().getMap().getMapObjectLayers()) {
        if (layer == null) {
            continue;
        }
        if (!EditorScreen.instance().getMapSelectionPanel().isVisibleMapObjectLayer(layer.getName())) {
            continue;
        }
        Color colorBoundingBoxFill;
        if (layer.getColor() != null) {
            colorBoundingBoxFill = new Color(layer.getColor().getRed(), layer.getColor().getGreen(), layer.getColor().getBlue(), 15);
        } else {
            colorBoundingBoxFill = DEFAULT_COLOR_BOUNDING_BOX_FILL;
        }
        for (final IMapObject mapObject : layer.getMapObjects()) {
            if (mapObject == null) {
                continue;
            }
            MapObjectType type = MapObjectType.get(mapObject.getType());
            final BasicStroke shapeStroke = new BasicStroke(1f / Game.getCamera().getRenderScale());
            // render spawn points
            if (type == MapObjectType.SPAWNPOINT) {
                g.setColor(COLOR_SPAWNPOINT);
                Game.getRenderEngine().renderShape(g, new Rectangle2D.Double(mapObject.getBoundingBox().getCenterX() - 1, mapObject.getBoundingBox().getCenterY() - 1, 2, 2));
            } else if (type == MapObjectType.PATH) {
                if (mapObject.getPolyline() == null || mapObject.getPolyline().getPoints().isEmpty()) {
                    continue;
                }
                // found the path for the rat
                final Path2D path = MapUtilities.convertPolylineToPath(mapObject);
                if (path == null) {
                    continue;
                }
                g.setColor(COLOR_LANE);
                Game.getRenderEngine().renderOutline(g, path, shapeStroke);
                Point2D start = new Point2D.Double(mapObject.getLocation().getX(), mapObject.getLocation().getY());
                Game.getRenderEngine().renderShape(g, new Ellipse2D.Double(start.getX() - 1, start.getY() - 1, 3, 3));
                Game.getRenderEngine().renderText(g, "#" + mapObject.getId() + "(" + mapObject.getName() + ")", start.getX(), start.getY() - 5);
            }
            if (type != MapObjectType.COLLISIONBOX) {
                this.renderBoundingBox(g, mapObject, colorBoundingBoxFill, shapeStroke);
            }
            this.renderCollisionBox(g, mapObject, shapeStroke);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) IMapObjectLayer(de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer) Color(java.awt.Color) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObjectType(de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)

Example 17 with IMapObject

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

the class MapComponent method handleEntityDrag.

private void handleEntityDrag(int snappedDeltaX, int snappedDeltaY) {
    for (IMapObject selected : this.getSelectedMapObjects()) {
        selected.setX(selected.getX() + snappedDeltaX);
        selected.setY(selected.getY() + snappedDeltaY);
        IEntity entity = Game.getEnvironment().get(selected.getId());
        if (entity != null) {
            entity.setX(selected.getLocation().getX());
            entity.setY(selected.getLocation().getY());
        } else {
            Game.getEnvironment().reloadFromMap(selected.getId());
        }
        if (selected.equals(this.getFocusedMapObject())) {
            EditorScreen.instance().getMapObjectPanel().bind(selected);
            this.updateTransformControls();
        }
    }
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 18 with IMapObject

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

the class MapComponent method ensureUniqueIds.

private void ensureUniqueIds(IMap map) {
    int maxMapId = MapUtilities.getMaxMapId(map);
    List<Integer> usedIds = new ArrayList<>();
    for (IMapObject obj : map.getMapObjects()) {
        if (usedIds.contains(obj.getId())) {
            obj.setId(++maxMapId);
        }
        usedIds.add(obj.getId());
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)

Example 19 with IMapObject

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

the class MapObjectLoaderTests method testLightSourceMapObjectLoader.

@Test
public void testLightSourceMapObjectLoader() {
    LightSourceMapObjectLoader loader = new LightSourceMapObjectLoader();
    IEnvironment environment = mock(IEnvironment.class);
    IMapObject mapObject = mock(IMapObject.class);
    when(mapObject.getType()).thenReturn(MapObjectType.LIGHTSOURCE.name());
    when(mapObject.getId()).thenReturn(111);
    when(mapObject.getName()).thenReturn("testLight");
    when(mapObject.getLocation()).thenReturn(new Point(100, 100));
    when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
    when(mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_ALPHA)).thenReturn(100);
    when(mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_INTENSITY, 100)).thenReturn(100);
    when(mapObject.getCustomPropertyColor(MapObjectProperty.LIGHT_COLOR)).thenReturn(Color.WHITE);
    when(mapObject.getCustomPropertyBool(MapObjectProperty.LIGHT_ACTIVE, true)).thenReturn(true);
    when(mapObject.getCustomProperty(MapObjectProperty.LIGHT_SHAPE)).thenReturn(LightSource.ELLIPSE);
    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(), "testLight");
    assertEquals(entity.getLocation().getX(), 100, 0.0001);
    assertEquals(entity.getLocation().getY(), 100, 0.0001);
    LightSource light = (LightSource) entity;
    assertTrue(light.isActive());
    assertEquals(Color.WHITE.getRed(), light.getColor().getRed());
    assertEquals(Color.WHITE.getBlue(), light.getColor().getBlue());
    assertEquals(Color.WHITE.getGreen(), light.getColor().getGreen());
    assertEquals(100, light.getColor().getAlpha());
    assertEquals(100, light.getIntensity());
    assertEquals(LightSource.ELLIPSE, light.getLightShapeType());
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Test(org.junit.jupiter.api.Test)

Example 20 with IMapObject

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

the class MapObjectLoaderTests method testPropMapObjectLoader.

@Test
public void testPropMapObjectLoader() {
    PropMapObjectLoader loader = new PropMapObjectLoader();
    IEnvironment environment = mock(IEnvironment.class);
    IMapObject mapObject = mock(IMapObject.class);
    when(mapObject.getType()).thenReturn(MapObjectType.PROP.name());
    when(mapObject.getId()).thenReturn(111);
    when(mapObject.getName()).thenReturn("testProp");
    when(mapObject.getLocation()).thenReturn(new Point(100, 100));
    when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
    when(mapObject.getCustomProperty(MapObjectProperty.PROP_MATERIAL)).thenReturn(Material.PLASTIC.name());
    when(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_INDESTRUCTIBLE)).thenReturn(true);
    when(mapObject.getCustomPropertyBool(MapObjectProperty.COLLISION)).thenReturn(true);
    when(mapObject.getCustomPropertyInt(MapObjectProperty.HEALTH)).thenReturn(100);
    when(mapObject.getCustomPropertyFloat(MapObjectProperty.COLLISIONBOX_WIDTH)).thenReturn(100.0f);
    when(mapObject.getCustomPropertyFloat(MapObjectProperty.COLLISIONBOX_HEIGHT)).thenReturn(100.0f);
    when(mapObject.getCustomProperty(MapObjectProperty.COLLISION_ALGIN)).thenReturn("LEFT");
    when(mapObject.getCustomProperty(MapObjectProperty.COLLISION_VALGIN)).thenReturn("MIDDLE");
    when(mapObject.getCustomPropertyInt(MapObjectProperty.TEAM)).thenReturn(1);
    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(), "testProp");
    assertEquals(entity.getLocation().getX(), 100, 0.0001);
    assertEquals(entity.getLocation().getY(), 100, 0.0001);
    Prop prop = (Prop) entity;
    assertEquals(prop.getMaterial(), Material.PLASTIC);
    assertTrue(prop.isIndestructible());
    assertTrue(prop.hasCollision());
    assertEquals(prop.getAttributes().getHealth().getMaxValue().intValue(), 100);
    assertEquals(prop.getAttributes().getHealth().getCurrentValue().intValue(), 100);
    assertEquals(prop.getCollisionBoxWidth(), 100.0, 0.0001);
    assertEquals(prop.getCollisionBoxHeight(), 100.0, 0.0001);
    assertEquals(prop.getCollisionBoxAlign(), Align.LEFT);
    assertEquals(prop.getCollisionBoxValign(), Valign.MIDDLE);
    assertEquals(prop.getTeam(), 1);
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) Prop(de.gurkenlabs.litiengine.entities.Prop) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) Test(org.junit.jupiter.api.Test)

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