Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public void collisonHandler(Helicopter h) {
  2. Rectangle r = h.getBoundingRectangle();
  3. /*
  4. * There was some problems with the bounds, so i had to set x pos here too
  5. */
  6. this.boundingRectangle.x = this.isFlipped() ? this.position.x + Settings.ANIMATION_WIDTH : this.position.x;
  7. //r.x = this.isFlipped() ? h.getPosition().x + Settings.ANIMATION_WIDTH : h.getPosition().x;
  8.  
  9. if (r.overlaps(this.boundingRectangle)) {
  10. if (r.y > this.boundingRectangle.y) {
  11. this.updateVelocityByCollisionY();
  12. h.updateVelocityByCollisionY();
  13. }
  14. if (r.x > this.boundingRectangle.x) {
  15. System.out.println(this.boundingRectangle.x);
  16. System.out.println(r.x);
  17. this.updateVelocityByCollisionX();
  18. h.updateVelocityByCollisionX();
  19. }
  20. }
  21. }
  22.  
  23. private void updateVelocityByCollisionX() {
  24. this.velocity.x *= -1;
  25. this.scaleX *= -1;
  26. this.position.add(this.velocity);
  27. this.position.add(this.velocity);
  28. if (!this.isFlipped()) {
  29. this.position.x += Settings.ANIMATION_WIDTH;
  30. } else {
  31. this.position.x -= Settings.ANIMATION_WIDTH;
  32. }
  33. }
  34.  
  35. private void updateVelocityByCollisionY() {
  36. this.velocity.y *= -1;
  37. this.position.add(this.velocity);
  38. this.position.add(this.velocity);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement