Search in sources :

Example 1 with IAnimationController

use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.

the class Environment method load.

/**
 * Loads the specified entiy by performing the following steps:
 * <ol>
 * <li>add to physics engine</li>
 * <li>register entity for update</li>
 * <li>register animation controller for update</li>
 * <li>register movement controller for update</li>
 * <li>register AI controller for update</li>
 * </ol>
 *
 * @param entity
 */
private void load(final IEntity entity) {
    // 1. add to physics engine
    this.loadPhysicsEntity(entity);
    // 2. register for update or activate
    this.loadUpdatableOrEmitterEntity(entity);
    // 3. register animation controller for update
    final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
    if (animation != null) {
        Game.getLoop().attach(animation);
    }
    // 4. register movement controller for update
    if (entity instanceof IMobileEntity) {
        final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
        if (movementController != null) {
            Game.getLoop().attach(movementController);
        }
    }
    // 5. register ai controller for update
    final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
    if (controller != null) {
        Game.getLoop().attach(controller);
    }
    if (entity instanceof LightSource || entity instanceof StaticShadow) {
        this.updateColorLayers(entity);
    }
}
Also used : StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) LightSource(de.gurkenlabs.litiengine.graphics.LightSource)

Example 2 with IAnimationController

use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.

the class Environment method unload.

/**
 * Unload the specified entity by performing the following steps:
 * <ol>
 * <li>remove entities from physics engine</li>
 * <li>unregister units from update</li>
 * <li>unregister ai controller from update</li>
 * <li>unregister animation controller from update</li>
 * <li>unregister movement controller from update</li>
 * </ol>
 *
 * @param entity
 */
private void unload(final IEntity entity) {
    // 1. remove from physics engine
    if (entity instanceof CollisionBox) {
        final CollisionBox coll = (CollisionBox) entity;
        if (coll.isObstacle()) {
            Game.getPhysicsEngine().remove(coll.getBoundingBox());
        } else {
            Game.getPhysicsEngine().remove(coll);
        }
    } else if (entity instanceof ICollisionEntity) {
        final ICollisionEntity coll = (ICollisionEntity) entity;
        Game.getPhysicsEngine().remove(coll);
    }
    // 2. unregister from update
    if (entity instanceof IUpdateable) {
        Game.getLoop().detach((IUpdateable) entity);
    }
    // 3. unregister ai controller from update
    final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
    if (controller != null) {
        Game.getLoop().detach(controller);
    }
    // 4. unregister animation controller from update
    final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
    if (animation != null) {
        Game.getLoop().detach(animation);
    }
    // 5. unregister movement controller from update
    if (entity instanceof IMobileEntity) {
        final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
        if (movementController != null) {
            Game.getLoop().detach(movementController);
        }
    }
    if (entity instanceof Emitter) {
        Emitter em = (Emitter) entity;
        em.deactivate();
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) IUpdateable(de.gurkenlabs.litiengine.IUpdateable) ICollisionEntity(de.gurkenlabs.litiengine.entities.ICollisionEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Example 3 with IAnimationController

use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.

the class Camera method getViewPortDimensionCenter.

@Override
public Point2D getViewPortDimensionCenter(final IEntity entity) {
    final Point2D viewPortLocation = this.getViewPortLocation(entity);
    final IAnimationController animationController = Game.getEntityControllerManager().getAnimationController(entity);
    if (animationController == null || animationController.getCurrentAnimation() == null) {
        return new Point2D.Double(viewPortLocation.getX() + entity.getWidth() * 0.5, viewPortLocation.getY() + entity.getHeight() * 0.5);
    }
    final Spritesheet spriteSheet = animationController.getCurrentAnimation().getSpritesheet();
    return new Point2D.Double(viewPortLocation.getX() + spriteSheet.getSpriteWidth() * 0.5, viewPortLocation.getY() + spriteSheet.getSpriteHeight() * 0.5);
}
Also used : Point2D(java.awt.geom.Point2D) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController)

Example 4 with IAnimationController

use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.

the class EntityControllerManager method disposeControllers.

public void disposeControllers(final IEntity entity) {
    final IEntityController<? extends IEntity> aiController = this.getAIController(entity);
    if (aiController != null) {
        Game.getLoop().detach(aiController);
        this.aiControllers.remove(entity);
    }
    if (entity instanceof IMobileEntity) {
        final IMovementController<? extends IMobileEntity> controller = this.getMovementController((IMobileEntity) entity);
        if (controller != null) {
            Game.getLoop().detach(controller);
            this.movementControllers.remove(entity);
        }
    }
    final IAnimationController animationController = this.getAnimationController(entity);
    if (animationController != null) {
        animationController.dispose();
        this.animationControllers.remove(entity);
    }
}
Also used : IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController)

Example 5 with IAnimationController

use of de.gurkenlabs.litiengine.graphics.animation.IAnimationController in project litiengine by gurkenlabs.

the class RenderEngine method renderEntity.

@Override
public void renderEntity(final Graphics2D g, final IEntity entity) {
    if (entity == null) {
        return;
    }
    if (entity.getRenderType() == RenderType.NONE || !this.canRender(entity)) {
        return;
    }
    final RenderEvent<IEntity> renderEvent = new RenderEvent<>(g, entity);
    if (!this.entityRenderingConsumer.isEmpty()) {
        for (final Consumer<RenderEvent<IEntity>> consumer : this.entityRenderingConsumer) {
            consumer.accept(renderEvent);
        }
    }
    final IAnimationController animationController = Game.getEntityControllerManager().getAnimationController(entity);
    if (animationController != null) {
        final BufferedImage img = animationController.getCurrentSprite();
        if (img == null) {
            return;
        }
        if (animationController instanceof IEntityAnimationController<?> && ((IEntityAnimationController<?>) animationController).isAutoScaling()) {
            final double ratioX = entity.getWidth() / img.getWidth();
            final double ratioY = entity.getHeight() / img.getHeight();
            renderScaledImage(g, img, Game.getCamera().getViewPortLocation(entity.getLocation()), ratioX, ratioY);
        } else {
            float deltaX = (entity.getWidth() - img.getWidth()) / 2.0f;
            float deltaY = (entity.getHeight() - img.getHeight()) / 2.0f;
            renderImage(g, img, Game.getCamera().getViewPortLocation(entity.getX() + deltaX, entity.getY() + deltaY), animationController.getAffineTransform());
        }
    }
    if (entity instanceof IRenderable) {
        ((IRenderable) entity).render(g);
    }
    if (!this.entityRenderedConsumer.isEmpty()) {
        for (final Consumer<RenderEvent<IEntity>> consumer : this.entityRenderedConsumer) {
            consumer.accept(renderEvent);
        }
    }
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) BufferedImage(java.awt.image.BufferedImage)

Aggregations

IAnimationController (de.gurkenlabs.litiengine.graphics.animation.IAnimationController)5 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)3 IUpdateable (de.gurkenlabs.litiengine.IUpdateable)1 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)1 ICollisionEntity (de.gurkenlabs.litiengine.entities.ICollisionEntity)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)1 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)1 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)1 Point2D (java.awt.geom.Point2D)1 BufferedImage (java.awt.image.BufferedImage)1