Search in sources :

Example 6 with Creature

use of de.gurkenlabs.litiengine.entities.Creature in project litiengine by gurkenlabs.

the class IconTreeListRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    this.label.setIcon(Icons.DEFAULT_NODE);
    this.label.setText(value.toString());
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        if (node.getUserObject() instanceof IconTreeListItem) {
            IconTreeListItem iconItem = (IconTreeListItem) node.getUserObject();
            this.label.setText(iconItem.getUserObject().toString());
            if (iconItem.getIcon() != null) {
                this.label.setIcon(iconItem.getIcon());
            } else if (iconItem.getUserObject() instanceof Prop) {
                Prop prop = (Prop) iconItem.getUserObject();
                label.setIcon(getIcon(prop));
            } else if (iconItem.getUserObject() instanceof Creature) {
                Creature creature = (Creature) iconItem.getUserObject();
                label.setIcon(getIcon(creature));
            }
        }
    }
    UIDefaults defaults = UIManager.getDefaults();
    this.label.setOpaque(true);
    this.label.setBackground(hasFocus || selected ? defaults.getColor("Tree.selectionBackground") : defaults.getColor("Tree.background"));
    this.label.setForeground(hasFocus || selected ? defaults.getColor("Tree.selectionForeground") : defaults.getColor("Tree.foreground"));
    this.label.setBorder(hasFocus ? focusBorder : normalBorder);
    return label;
}
Also used : UIDefaults(javax.swing.UIDefaults) Creature(de.gurkenlabs.litiengine.entities.Creature) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Prop(de.gurkenlabs.litiengine.entities.Prop)

Example 7 with Creature

use of de.gurkenlabs.litiengine.entities.Creature in project litiengine by gurkenlabs.

the class PhysicsTests method testBasicCollisionDetection.

@Test
public void testBasicCollisionDetection() {
    try (GameLoop loop = new GameLoop(30)) {
        Creature ent = new Creature();
        ent.setSize(16, 16);
        ent.setCollision(true);
        ent.setCollisionBoxWidth(16);
        ent.setCollisionBoxHeight(16);
        ent.setLocation(10, 10);
        IPhysicsEngine engine = new PhysicsEngine();
        engine.add(ent);
        loop.start();
        loop.attach(() -> {
            assertFalse(engine.collides(9, 9));
            assertFalse(engine.collides(27, 27));
            assertTrue(engine.collides(10.00001, 10.00001));
            assertTrue(engine.collides(25.99999, 25.99999));
            Rectangle2D rect1 = new Rectangle2D.Double(0, 0, 10, 10);
            Rectangle2D rect2 = new Rectangle2D.Double(10, 10, 0, 0);
            Rectangle2D rect3 = new Rectangle2D.Double(10, 10, 1, 1);
            Rectangle2D rect4 = new Rectangle2D.Double(8, 8, 3, 3);
            Rectangle2D rect5 = new Rectangle2D.Double(25.99999, 10, 10, 20);
            assertFalse(engine.collides(rect1));
            assertFalse(engine.collides(rect2));
            assertTrue(engine.collides(rect3));
            assertTrue(engine.collides(rect4));
            assertTrue(engine.collides(rect5));
        });
    }
}
Also used : Creature(de.gurkenlabs.litiengine.entities.Creature) GameLoop(de.gurkenlabs.litiengine.GameLoop) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.jupiter.api.Test)

Example 8 with Creature

use of de.gurkenlabs.litiengine.entities.Creature in project litiengine by gurkenlabs.

the class Environment method remove.

@Override
public void remove(final IEntity entity) {
    if (entity == null) {
        return;
    }
    if (this.entities.get(entity.getRenderType()) != null) {
        this.entities.get(entity.getRenderType()).entrySet().removeIf(e -> e.getValue().getMapId() == entity.getMapId());
    }
    for (String tag : entity.getTags()) {
        if (this.entitiesByTag.containsKey(tag)) {
            this.entitiesByTag.get(tag).remove(entity);
            if (this.entitiesByTag.get(tag).isEmpty()) {
                this.entitiesByTag.remove(tag);
            }
        }
    }
    if (entity instanceof Emitter) {
        Emitter emitter = (Emitter) entity;
        this.groundRenderable.remove(emitter.getGroundRenderable());
        this.overlayRenderable.remove(emitter.getOverlayRenderable());
        this.emitters.remove(emitter);
    }
    if (entity instanceof MapArea) {
        this.mapAreas.remove(entity);
    }
    if (entity instanceof Prop) {
        this.props.remove(entity);
    }
    if (entity instanceof Creature) {
        this.creatures.remove(entity);
    }
    if (entity instanceof CollisionBox) {
        this.colliders.remove(entity);
        this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
    }
    if (entity instanceof LightSource) {
        this.lightSources.remove(entity);
        this.updateColorLayers(entity);
    }
    if (entity instanceof Trigger) {
        this.triggers.remove(entity);
    }
    if (entity instanceof Spawnpoint) {
        this.spawnPoints.remove(entity);
    }
    if (entity instanceof StaticShadow) {
        this.staticShadows.remove(entity);
        this.updateColorLayers(entity);
    }
    if (entity instanceof IMobileEntity) {
        this.mobileEntities.values().remove(entity);
    }
    if (entity instanceof ICombatEntity) {
        this.combatEntities.values().remove(entity);
    }
    this.unload(entity);
    for (Consumer<IEntity> cons : this.entityRemovedConsumers) {
        cons.accept(entity);
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Creature(de.gurkenlabs.litiengine.entities.Creature) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Prop(de.gurkenlabs.litiengine.entities.Prop) IEntity(de.gurkenlabs.litiengine.entities.IEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) Trigger(de.gurkenlabs.litiengine.entities.Trigger) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Aggregations

Creature (de.gurkenlabs.litiengine.entities.Creature)8 Prop (de.gurkenlabs.litiengine.entities.Prop)4 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)3 IEntity (de.gurkenlabs.litiengine.entities.IEntity)3 Trigger (de.gurkenlabs.litiengine.entities.Trigger)3 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)3 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)3 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)3 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)3 Test (org.junit.jupiter.api.Test)3 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)2 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 GameLoop (de.gurkenlabs.litiengine.GameLoop)1 Effect (de.gurkenlabs.litiengine.abilities.effects.Effect)1 Direction (de.gurkenlabs.litiengine.entities.Direction)1 IconTreeListItem (de.gurkenlabs.utiliti.swing.IconTreeListItem)1 Rectangle2D (java.awt.geom.Rectangle2D)1 UIDefaults (javax.swing.UIDefaults)1