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.

44 lines
1.4 KiB

  1. package playground;
  2. import java.awt.Color;
  3. import gameobjects.*;
  4. public class BreakoutLevel3 extends BreakoutLevel2 {
  5. @Override
  6. public void prepareLevel(String level) {
  7. this.setLevelFlag("points", 0);
  8. super.setGlobalFlag("lives", 3);
  9. TextObject points = new TextObject("Counter", this, 50D, 10D, 0D, 0D, "Points: "+ this.getLevelFlag("points").toString(), 20, Color.BLACK);
  10. this.addObject(points);
  11. TextObject lives = new TextObject("Counter2", this, 600D, 10D, 0D, 0D, "Lives: "+ super.getGlobalFlag("lives").toString(), 20, Color.GREEN);
  12. this.addObject(lives);
  13. super.prepareLevel(level);
  14. }
  15. @Override
  16. protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
  17. super.actionIfBallHitsBrick(ball, brick);
  18. int newPoints = Integer.valueOf(this.getLevelFlag("points").toString()) + 10;
  19. this.setLevelFlag("points", newPoints);
  20. this.addObject(new TextObject("Counter", this, 50D, 10D, 0D, 0D, "Points: "+ this.getLevelFlag("points").toString(), 20, Color.BLACK));
  21. }
  22. @Override
  23. public void applyGameLogic() {
  24. super.applyGameLogic();
  25. if(ball.getY() > ego.getY()) {
  26. int newLives = Integer.valueOf(super.getGlobalFlag("lives").toString()) - 1;
  27. super.setGlobalFlag("newLives", newLives);
  28. this.addObject(new TextObject("Counter2", this, 600D, 10D, 0D, 0D, "Lives: "+ super.getGlobalFlag("newLives").toString(), 20, Color.GREEN));
  29. }
  30. }
  31. }