Space von Team 22 (Nico B. Benjamin F. Lea A.)
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.

77 lines
2.2 KiB

3 years ago
3 years ago
3 years ago
  1. package playground;
  2. import java.awt.Color;
  3. import org.apache.logging.log4j.LogManager;
  4. import org.apache.logging.log4j.Logger;
  5. import collider.RectCollider;
  6. import controller.ReboundController;
  7. import controller.ReboundController2;
  8. import gameobjects.GameObject;
  9. import gameobjects.RectObject;
  10. /**
  11. * Level that creates two RectObjects moving around and if ego is hit by them game is directly lost
  12. * (lives = 0).
  13. *
  14. */
  15. public class LevelMovingHitObjects extends SpaceInvadersLevel {
  16. private static Logger logger1 = LogManager.getLogger(LevelMovingHitObjects.class);
  17. @Override
  18. public void prepareLevel(String id) {
  19. super.prepareLevel(id);
  20. RectObject fly_enemy1 = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40, 40, Color.BLUE);
  21. RectObject fly_enemy2 = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40, 40, Color.GREEN);
  22. logger1.info("Created two rectobjects");
  23. ReboundController2 fly1_controller = new ReboundController2();
  24. ReboundController2 fly2_controller = new ReboundController2();
  25. logger1.info("Created two controllers");
  26. fly_enemy1.addController(fly1_controller);
  27. fly_enemy2.addController(fly2_controller);
  28. logger1.info("Added controller to Rectbjects");
  29. this.addObject(fly_enemy1);
  30. this.addObject(fly_enemy2);
  31. logger1.info("Added objects to LevelMoving<HItObejcts");
  32. RectCollider collider1 = new RectCollider("collider1", fly_enemy1, 40d, 40d);
  33. RectCollider collider2 = new RectCollider("collider2", fly_enemy2, 40d, 40d);
  34. logger1.info("Created two colliders");
  35. fly_enemy1.addCollider(collider1);
  36. fly_enemy2.addCollider(collider2);
  37. logger1.info("Added collider to rectobjects");
  38. }
  39. @Override
  40. void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
  41. if (enemy.id.equals("fly_enemy1") || enemy.id.equals("fly_enemy2")) {
  42. setGlobalFlag("egoLive", 0);
  43. this.lost = true;
  44. } else {
  45. super.actionIfEgoCollidesWithEnemy(enemy, ego);
  46. }
  47. }
  48. //FIXME add your method overrides here
  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. }