Space von Team 22 (Nico B. Benjamin F. Lea A.)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
961 B

  1. package controller;
  2. /** Controller to let Objects bounce from the outer level limits back and forth.
  3. *
  4. */
  5. public class ReboundController2 extends ObjectController {
  6. /** inverts the x y direction speeds if the outer limits are reached.
  7. *
  8. */
  9. @Override
  10. public void updateObject() {
  11. double sizeX = this.getPlayground().preferredSizeX();
  12. double sizeY = this.getPlayground().preferredSizeY();
  13. double objSizeX = 30;
  14. double objSizeY = 30;
  15. if (this.getX() < objSizeX) {
  16. this.setVX(this.getVX() * -1);
  17. this.setX(objSizeX);
  18. } else if (this.getX() > sizeX - objSizeX) {
  19. this.setVX(this.getVX() * -1);
  20. this.setX(sizeX - objSizeX);
  21. }
  22. if (this.getY() < objSizeY) {
  23. this.setVY(this.getVY() * -1);
  24. this.setY(objSizeY);
  25. } else if (this.getY() > sizeY - objSizeY) {
  26. this.setVY(this.getVY() * -1);
  27. this.setY(sizeY - objSizeY);
  28. }
  29. this.applySpeedVector();
  30. }
  31. }