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
1.1 KiB

  1. package controller;
  2. import org.apache.logging.log4j.Logger;
  3. import org.apache.logging.log4j.LogManager;
  4. /**
  5. * This class controls the space invaders.
  6. */
  7. public class EnemyController extends ObjectController {
  8. private static Logger logger = LogManager.getLogger(EnemyController.class);
  9. @Override
  10. public void updateObject() {
  11. logger.trace("updatre" + gameObject.getId());
  12. if ((gameObject.getX() > this.getPlayground().getSizeX() * 0.9) && (gameObject.getVX() > 0)) {
  13. logger.trace("toleft!" + gameObject.getX());
  14. gameObject.setVX(-this.getVX());
  15. }
  16. if ((gameObject.getX() < this.getPlayground().getSizeX() * 0.1) && (gameObject.getVX() < 0)) {
  17. logger.trace("toright!" + gameObject.getX());
  18. gameObject.setVX(-this.getVX());
  19. }
  20. // if it reaches the bottom, delete it and deduct points
  21. if (gameObject.getY() >= this.getPlayground().getSizeY()) {
  22. this.getPlayground().deleteObject(gameObject.getId());
  23. // add to points counter
  24. Integer pts = (Integer) this.getPlayground().getGlobalFlag("points");
  25. this.getPlayground().setGlobalFlag("points", pts - 200);
  26. }
  27. applySpeedVector();
  28. }
  29. }