Skip to content

Commit

Permalink
Trigger entity moved event from the EntityNavigator
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Apr 19, 2020
1 parent ac9459f commit 6da1d94
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.IUpdateable;
import de.gurkenlabs.litiengine.entities.EntityMovedEvent;
import de.gurkenlabs.litiengine.entities.IMobileEntity;
import de.gurkenlabs.litiengine.graphics.IRenderable;
import de.gurkenlabs.litiengine.util.geom.GeometricUtilities;
Expand Down Expand Up @@ -174,6 +175,9 @@ public void update() {

final double angle = GeometricUtilities.calcRotationAngleInDegrees(this.entity.getCollisionBox().getCenterX(), this.entity.getCollisionBox().getCenterY(), coordinates[0], coordinates[1]);
final float pixelsPerTick = this.entity.getTickVelocity();
final Point2D oldLocation = this.getEntity().getLocation();
Game.physics().move(this.entity, (float) angle, (float) (distance < pixelsPerTick ? distance : pixelsPerTick));

this.getEntity().fireMovedEvent(new EntityMovedEvent(this.getEntity(), this.getEntity().getX() - oldLocation.getX(), this.getEntity().getY() - oldLocation.getY()));
}
}

0 comments on commit 6da1d94

Please sign in to comment.