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.

37 lines
1.2 KiB

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