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.
58 lines
1.4 KiB
58 lines
1.4 KiB
package playground;
|
|
|
|
import java.awt.Color;
|
|
|
|
import gameobjects.GameObject;
|
|
import gameobjects.TextObject;
|
|
|
|
public class BreakoutLevel3 extends BreakoutLevel0 {
|
|
|
|
TextObject pointsText = new TextObject("pointsText", this, 50, 10, 0.,0, "0", 20, Color.BLACK);
|
|
TextObject livesText = new TextObject("livesText", this, 600,10,0,0,"3", 20, Color.GREEN);
|
|
|
|
@Override
|
|
public void prepareLevel(String id) {
|
|
setLevelFlag("points", 0);
|
|
TextObject score = pointsText;
|
|
this.addObject(score);
|
|
setGlobalFlag("lives", 3);
|
|
TextObject lives = livesText;
|
|
this.addObject(lives);
|
|
super.prepareLevel(id);
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
|
|
super.actionIfBallHitsBrick(ball, brick);
|
|
int value = (int) getLevelFlag("points");
|
|
setLevelFlag("points", value + 10);
|
|
pointsText.setText("" + getLevelFlag("points"));
|
|
}
|
|
|
|
@Override
|
|
public void applyGameLogic (){
|
|
super.applyGameLogic();
|
|
int value = (int) getGlobalFlag("lives");
|
|
if(this.ball.getY() > this.ego.getY()) {
|
|
setGlobalFlag("lives", --value);
|
|
livesText.setText("" + value);
|
|
this.ball.setY(this.ego.getY() - 20);
|
|
this.ball.setX(this.ego.getX());
|
|
}
|
|
|
|
|
|
}
|
|
@Override
|
|
public boolean gameOver() {
|
|
int value = (int) getGlobalFlag("lives");
|
|
if (value <0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|