WalkController.java 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package me.hammerle.supersnuvi.entity.components.ai;
  2. import me.hammerle.supersnuvi.entity.Entity;
  3. import me.hammerle.supersnuvi.tiles.Location;
  4. import me.hammerle.supersnuvi.util.Face;
  5. public class WalkController extends Controller
  6. {
  7. private float motion;
  8. public WalkController(Entity ent, float motion)
  9. {
  10. super(ent);
  11. this.motion = motion;
  12. }
  13. @Override
  14. public void tick()
  15. {
  16. if(ent.getHealth().isDead())
  17. {
  18. return;
  19. }
  20. ent.setMotionX(motion);
  21. }
  22. /*@Override
  23. public void onCollideWithEntity(Entity ent, Face face)
  24. {
  25. switchDirection(face);
  26. }
  27. @Override
  28. public void onCollideWithTile(Location loc, Face face)
  29. {
  30. switchDirection(face);
  31. }*/
  32. private void switchDirection(Face face)
  33. {
  34. if(face == Face.LEFT)
  35. {
  36. motion = -Math.abs(motion);
  37. }
  38. else if(face == Face.RIGHT)
  39. {
  40. motion = Math.abs(motion);
  41. }
  42. }
  43. }