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.

74 lines
2.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package playground;
  2. import java.awt.Color;
  3. import controller.ReboundController;
  4. import gameobjects.GameObject;
  5. import gameobjects.RectObject;
  6. import collider.*;
  7. import org.apache.log4j.*;
  8. /**
  9. * Level that creates two RectObjects moving around and if ego is hit by them game is directly lost
  10. * (lives = 0).
  11. *
  12. */
  13. public class LevelMovingHitObjects extends SpaceInvadersLevel {
  14. private static Logger Logger = LogManager.getLogger(LevelMovingObjects.class);
  15. // FIXME add logger here
  16. private RectObject blueBox;
  17. private RectObject greenBox;
  18. @Override
  19. public void prepareLevel(String id) {
  20. super.prepareLevel(id);
  21. Logger.trace("Creating and adding two RectObjects with Collider");
  22. blueBox = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40, 40, Color.BLUE);
  23. this.addObject(blueBox);
  24. ReboundController boxControl = new ReboundController();
  25. blueBox.addController(boxControl);
  26. RectCollider colliderBlue = new RectCollider("ColliderBlue", blueBox, 40, 40);
  27. blueBox.addCollider(colliderBlue);
  28. greenBox = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40, 40, Color.GREEN);
  29. this.addObject(greenBox);
  30. ReboundController boxControl_2 = new ReboundController();
  31. greenBox.addController(boxControl_2);
  32. RectCollider colliderGreen = new RectCollider("ColliderGreen", greenBox, 40, 40);
  33. greenBox.addCollider(colliderGreen);
  34. Logger.debug("successfully finished prepareLevel with two RectObjects");
  35. }
  36. @Override
  37. void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
  38. if(enemy.id.contains("fly")) {
  39. this.lost = true;
  40. Playground.setGlobalFlag("egoLives", 0);
  41. Logger.info("ego hit a letal RectObject. Game ends NOW");
  42. } else {
  43. Logger.debug("ego hit one of the other aliens, calling parent class code");
  44. super.actionIfEgoCollidesWithEnemy(enemy, ego);
  45. HighscoreManager.writeHSToFile((Integer) Playground.getGlobalFlag("points"),
  46. (Integer) Playground.getGlobalFlag("highscore"));
  47. }
  48. }
  49. /**
  50. * "Moving Hitting Objects Level!" is the message.
  51. *
  52. * @return String "Moving & Hitting Objects Level!"
  53. */
  54. @Override
  55. protected String getStartupMessage() {
  56. return "Moving & Hitting Objects Level!";
  57. }
  58. }