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.

63 lines
1.9 KiB

  1. package playground;
  2. import gameobjects.GameObject;
  3. import controller.LimitedTimeController;
  4. import gameobjects.TextObject;
  5. import java.awt.Color;
  6. import org.apache.logging.log4j.LogManager;
  7. import org.apache.logging.log4j.Logger;
  8. /**
  9. * extends {@link SpaceInvadersLevel}
  10. * <ul>
  11. * <li>Hit aliens twice to kill them
  12. * <li>they say AUA when not destroyed
  13. * </ul>
  14. */
  15. public class Level4 extends SpaceInvadersLevel {
  16. /** constant defining the number of shots needed to destroy an enemy */
  17. public static final int MAX_HITS = 2;
  18. private static Logger logger = LogManager.getLogger(Level4.class);
  19. @Override
  20. protected String getStartupMessage() {
  21. return "Jetzt gibts Saures!";
  22. }
  23. @Override
  24. void actionIfEnemyIsHit(GameObject e, GameObject shot) {
  25. double gameTime = this.getGameTime();
  26. Object counterFlag = e.getOrCreateObjectFlag("counter", Integer.valueOf(1));
  27. int counter = (Integer) counterFlag;
  28. if (counter >= MAX_HITS) {
  29. logger.trace("enemy was hit before for " + counter + " times, which is above "
  30. + LevelHitTwice.MAX_HITS);
  31. super.actionIfEnemyIsHit(e, shot);
  32. } else {
  33. logger.trace("enemy was hit before for "+counter+" times, which is below "+LevelHitTwice.MAX_HITS);
  34. e.setObjectFlag("counter", Integer.valueOf(counter + 1));
  35. // spawn a bonus points object
  36. double vx = 2 * (Math.random() - 0.5) * SHARDSPEED + e.getVX();
  37. double vy = 2 * (Math.random() - 0.5) * SHARDSPEED + e.getVY();
  38. logger.trace("creating new TextObject bonus" + e.getId());
  39. LimitedTimeController bonusTextController =
  40. new LimitedTimeController(gameTime, SpaceInvadersLevel.EXPL_DURATION);
  41. GameObject bonusText = new TextObject("bonus" + e.getId(), this, e.getX(), e.getY(), vx, vy,
  42. "Aua", 20, Color.YELLOW).addController(bonusTextController);
  43. this.addObject(bonusText);
  44. }
  45. deleteObject(shot.getId());
  46. }
  47. }