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.
 
 
 
 

55 lines
1.6 KiB

package playground;
import java.awt.Color;
import gameobjects.*;
public class BreakoutLevel3 extends BreakoutLevel2 {
@Override
public void prepareLevel(String level) {
this.setLevelFlag("points", 0);
super.setGlobalFlag("lives", 3);
TextObject points = new TextObject("Counter", this, 50D, 10D, 0D, 0D, "Points: "+ this.getLevelFlag("points").toString(), 20, Color.BLACK);
this.addObject(points);
TextObject lives = new TextObject("Counter2", this, 600D, 10D, 0D, 0D, "Lives: "+ super.getGlobalFlag("lives").toString(), 20, Color.GREEN);
this.addObject(lives);
super.prepareLevel(level);
}
@Override
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
super.actionIfBallHitsBrick(ball, brick);
int newPoints = Integer.valueOf(this.getLevelFlag("points").toString()) + 10;
this.setLevelFlag("points", newPoints);
this.addObject(new TextObject("Counter", this, 50D, 10D, 0D, 0D, "Points: "+ this.getLevelFlag("points").toString(), 20, Color.BLACK));
}
@Override
public void applyGameLogic() {
super.applyGameLogic();
if(ball.getY() > ego.getY()) {
int newLives = Integer.valueOf(super.getGlobalFlag("lives").toString()) - 1;
super.setGlobalFlag("lives", newLives);
this.addObject(new TextObject("Counter2", this, 600D, 10D, 0D, 0D, "Lives: "+ super.getGlobalFlag("lives").toString(), 20, Color.GREEN));
this.ball.setY(this.ego.getY()-20);
this.ball.setVY(this.ball.getVY()*-1);
}
}
@Override
public boolean gameOver() {
if(Integer.valueOf(super.getGlobalFlag("lives").toString())== 0) {
return true;
}
return false;
}
}