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.

71 lines
2.0 KiB

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. blueBox = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40, 40, Color.BLUE);
  22. this.addObject(blueBox);
  23. ReboundController boxControl = new ReboundController();
  24. blueBox.addController(boxControl);
  25. RectCollider colliderBlue = new RectCollider("ColliderBlue", blueBox, 40, 40);
  26. blueBox.addCollider(colliderBlue);
  27. greenBox = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40, 40, Color.GREEN);
  28. this.addObject(greenBox);
  29. ReboundController boxControl_2 = new ReboundController();
  30. greenBox.addController(boxControl_2);
  31. RectCollider colliderGreen = new RectCollider("ColliderGreen", greenBox, 40, 40);
  32. greenBox.addCollider(colliderGreen);
  33. }
  34. @Override
  35. void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
  36. super.actionIfEgoCollidesWithEnemy(enemy, ego);
  37. if(enemy.id.contains("fly")) {
  38. this.lost = true;
  39. Playground.setGlobalFlag("egoLives", 0);
  40. Logger.info("ego hit a letal RectObject. Game ends NOW");
  41. HighscoreManager.writeHSToFile((Integer) Playground.getGlobalFlag("points"),
  42. (Integer) Playground.getGlobalFlag("highscore"));
  43. }
  44. }
  45. /**
  46. * "Moving Hitting Objects Level!" is the message.
  47. *
  48. * @return String "Moving & Hitting Objects Level!"
  49. */
  50. @Override
  51. protected String getStartupMessage() {
  52. return "Moving & Hitting Objects Level!";
  53. }
  54. }