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.

49 lines
1.4 KiB

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