FollowHeroController.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package me.hammerle.supersnuvi.entity.components.ai;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. public class FollowHeroController extends Controller
  4. {
  5. private final float motion;
  6. private boolean jump;
  7. public FollowHeroController(Entity ent, float motion)
  8. {
  9. super(ent);
  10. this.motion = motion;
  11. this.jump = false;
  12. }
  13. /*@Override
  14. public void tick()
  15. {
  16. if(ent.getHealth().isDead())
  17. {
  18. return;
  19. }
  20. Entity hero = ent.getLevel().getHero();
  21. if(hero.squaredDistance(ent) <= 409600)
  22. {
  23. if(jump)
  24. {
  25. jump = false;
  26. SoundUtils.playSound(SoundUtils.Sound.LONDONER_JUMP);
  27. ent.getMovement().jump();
  28. }
  29. float distance = ent.signedDistanceX(hero);
  30. if(distance < 0)
  31. {
  32. ent.setMotionX(motion * ent.getMovementPenalty().getFactor());
  33. }
  34. else if(distance > 0)
  35. {
  36. ent.setMotionX(-motion * ent.getMovementPenalty().getFactor());
  37. }
  38. }
  39. }
  40. @Override
  41. public void onCollideWithEntity(Entity ent, Face face)
  42. {
  43. if(this.ent.signedDistanceX(ent) == 0)
  44. {
  45. if(ent.getX() - this.ent.getX() > 0)
  46. {
  47. ent.setMotionX(6.0f);
  48. }
  49. else
  50. {
  51. ent.setMotionX(-6.0f);
  52. }
  53. ent.getHealth().addHealth(-0.05);
  54. if(ent.getMovement().useCollisionBox())
  55. {
  56. jump = true;
  57. }
  58. }
  59. }
  60. @Override
  61. public void onCollideWithTile(Location loc, Face face)
  62. {
  63. if((face == Face.LEFT || face == Face.RIGHT) &&
  64. Math.abs(ent.getPreviousMotionX() - ent.getMotionX()) > 0.001 &&
  65. Math.abs(ent.signedDistanceX(ent.getLevel().getHero())) > 0.001)
  66. {
  67. jump = true;
  68. }
  69. }*/
  70. }