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;
}
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));
});
}
}
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);
}
}
Aggregations