Skip to content

Commit

Permalink
Allow custom creatures to override default controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Mar 17, 2020
1 parent bccf1f2 commit 5af6f4d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/de/gurkenlabs/litiengine/entities/Creature.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.gurkenlabs.litiengine.environment.tilemap.TmxProperty;
import de.gurkenlabs.litiengine.graphics.animation.CreatureAnimationController;
import de.gurkenlabs.litiengine.graphics.animation.EntityAnimationController;
import de.gurkenlabs.litiengine.graphics.animation.IEntityAnimationController;
import de.gurkenlabs.litiengine.physics.IMovementController;
import de.gurkenlabs.litiengine.physics.MovementController;

Expand Down Expand Up @@ -62,7 +63,7 @@ public Creature(String spritesheetName) {
this.acceleration = movementInfo.acceleration();
this.deceleration = movementInfo.deceleration();
this.setTurnOnMove(movementInfo.turnOnMove());
this.addController(new MovementController<>(this));
this.addController(this.createMovementController());
}

if (spritesheetName != null) {
Expand Down Expand Up @@ -213,10 +214,18 @@ public String toString() {
}

protected void updateAnimationController() {
CreatureAnimationController<Creature> controller = new CreatureAnimationController<>(this, true);
IEntityAnimationController<?> controller = this.createAnimationController();
this.getControllers().addController(controller);
if (Game.world().environment() != null && Game.world().environment().isLoaded()) {
Game.loop().attach(controller);
}
}

protected IEntityAnimationController<?> createAnimationController() {
return new CreatureAnimationController<>(this, true);
}

protected IMovementController createMovementController() {
return new MovementController<>(this);
}
}

0 comments on commit 5af6f4d

Please sign in to comment.