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.

36 lines
925 B

  1. package controller;
  2. /**
  3. * Controls and abject that is deleted after a lifetime specified in the constructor, and when it
  4. * leaves the display.
  5. */
  6. public class LimitedTimeController extends ObjectController {
  7. int rad = 3;
  8. double g0 = -1;
  9. double duration = 0;
  10. /**
  11. * Constructor.
  12. *
  13. * @param g0 int initial game time at creation
  14. * @param duration int duration in seconds
  15. */
  16. public LimitedTimeController(double g0, double duration) {
  17. this.g0 = g0;
  18. this.duration = duration;
  19. }
  20. @Override
  21. public void updateObject() {
  22. double gameTime = this.getPlayground().getGameTime();
  23. applySpeedVector();
  24. if (gameObject.getY() >= getPlayground().getSizeY() || gameObject.getY() < 0
  25. || gameObject.getX() >= getPlayground().getSizeX() || gameObject.getX() < 0
  26. || (gameTime - g0) > duration) {
  27. this.getPlayground().deleteObject(this.gameObject.getId());
  28. }
  29. }
  30. }