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.
70 lines
1.8 KiB
70 lines
1.8 KiB
package playground;
|
|
|
|
import java.awt.Color;
|
|
|
|
import gameobjects.GameObject;
|
|
|
|
public class BreakoutLevel3 extends BreakoutLevel2 {
|
|
|
|
gameobjects.TextObject textPoints, textLives;
|
|
|
|
/** Creates flags and TextObjects to display scores and Lives.
|
|
*
|
|
* @param level String
|
|
*/
|
|
@Override
|
|
public void prepareLevel(String level) {
|
|
setGlobalFlag("points", 0);
|
|
getOrCreateGlobalFlag("lives", 3);
|
|
textPoints = new gameobjects.TextObject("textPoints", this, 50 , 10, 0, 0, "Score: 0", 10, Color.black);
|
|
textLives = new gameobjects.TextObject("textLives", this, 600 , 10, 0, 0, "Lives: "+(int)getOrCreateGlobalFlag("lives", 3), 10, Color.black);
|
|
this.addObject(textPoints);
|
|
this.addObject(textLives);
|
|
|
|
super.prepareLevel(level);
|
|
}
|
|
|
|
/** Sets the Score if a Brick is hitted.
|
|
*
|
|
* @param ball GameObject
|
|
* @param brick
|
|
*/
|
|
@Override
|
|
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
|
|
super.actionIfBallHitsBrick(ball, brick);
|
|
|
|
setGlobalFlag("points", (int)(getGlobalFlag("points")) + 10);
|
|
textPoints.setText("Score: "+(int)getGlobalFlag("points"));
|
|
|
|
}
|
|
|
|
/** If the Ball goes under the Ego, Lives are decreased and Ball is set above Ego.
|
|
*/
|
|
@Override
|
|
public void applyGameLogic() {
|
|
super.applyGameLogic();
|
|
|
|
if(ball.getY() > ego.getY()) {
|
|
setGlobalFlag("lives", (int)(getGlobalFlag("lives")) - 1);
|
|
textLives.setText("Lives: "+(int)getGlobalFlag("lives"));
|
|
if(ball.getVY() > 0) {
|
|
ball.setVY(ball.getVY() *- 1);
|
|
}
|
|
ball.setY(ego.getY()-20.0);
|
|
}
|
|
}
|
|
|
|
/** game ends if egoLives < 0 .
|
|
*
|
|
* @return gameOver boolean
|
|
*/
|
|
@Override
|
|
public boolean gameOver() {
|
|
if((int)getGlobalFlag("lives") < 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|