Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package kopako.entities.components;
  2.  
  3. import kopako.collision.AABBbox;
  4. import kopako.entities.Entity;
  5. import kopako.utility.Component;
  6. import kopako.utility.EntityComponent;
  7. import kopako.utility.Location;
  8. import kopako.utility.graphics.Coordinates;
  9.  
  10.  
  11. public class Collidable extends EntityComponent {
  12.  
  13.  
  14. private AABBbox Box;
  15. private Location last;
  16. private AABBbox wtfTest;
  17.  
  18. public Collidable(Entity e) {
  19. super(e);
  20. this.setID(Component.COLLIDABLE);
  21. last = getEntity().getLocation().clone();
  22. }
  23.  
  24. @Override
  25. public void update(int delta) {
  26.  
  27. // if (Box != null) {
  28. // float x = Coordinates.subtract(getEntity().getLocation().getX(),last.getX());
  29. // float y = Coordinates.subtract(getEntity().getLocation().getY(),last.getY());
  30. //System.out.println("X:" + x + " Y:" + y);
  31. // wtfTest = Box.clone();
  32. // Box.moveLocation(x, y);
  33.  
  34. // System.out.println("Last:" + wtfTest.getLeft() + " Current:" + Box.getLeft());
  35. // last = getEntity().getLocation().clone();
  36. // }
  37. }
  38.  
  39.  
  40.  
  41. public final void NewBoundingBox(Location l, float height, float width) {
  42. Box = new AABBbox(l,height,width);
  43.  
  44. }
  45.  
  46. public final AABBbox getBoundingBox() {
  47. return Box;
  48. }
  49.  
  50. public final boolean isColliding(AABBbox test) {
  51.  
  52. if (Box != null) {
  53. return Box.colliding(test);
  54. }
  55. return false;
  56. }
  57.  
  58. public final boolean willCollide(AABBbox test, float moveX, float moveY) {
  59.  
  60. if (Box != null) {
  61. AABBbox goTo = Box.clone();
  62. goTo.moveLocation(moveX, moveY);
  63.  
  64. return goTo.colliding(test);
  65. }
  66. return false;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement