FollowHeroController.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package me.hammerle.supersnuvi.entity.ai;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. import me.hammerle.supersnuvi.entity.Hero;
  4. import me.hammerle.supersnuvi.tiles.Location;
  5. import me.hammerle.supersnuvi.util.Face;
  6. public class FollowHeroController extends EntityController
  7. {
  8. private final double motion;
  9. public FollowHeroController(Entity ent, double motion)
  10. {
  11. super(ent);
  12. this.motion = motion;
  13. }
  14. @Override
  15. public void tick()
  16. {
  17. Hero hero = ent.getLevel().getHero();
  18. if(hero.squaredDistance(ent) <= 102400)
  19. {
  20. double distance = ent.signedDistanceX(hero);
  21. if(distance < 0)
  22. {
  23. ent.setMotionX(motion);
  24. }
  25. else if(distance > 0)
  26. {
  27. ent.setMotionX(-motion);
  28. }
  29. }
  30. }
  31. @Override
  32. public void onCollideWithEntity(Entity ent, Face face)
  33. {
  34. }
  35. @Override
  36. public void onCollideWithTile(Location loc, Face face)
  37. {
  38. if((face == Face.LEFT || face == Face.RIGHT) &&
  39. Math.abs(ent.getPreviousMotionX() - ent.getMotionX()) > 0.001 &&
  40. Math.abs(ent.signedDistanceX(ent.getLevel().getHero())) > 0.001)
  41. {
  42. ent.jump();
  43. }
  44. }
  45. }