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.
108 lines
3.6 KiB
108 lines
3.6 KiB
package playground;
|
|
|
|
import java.awt.Color;
|
|
|
|
import collider.RectCollider;
|
|
import gameobjects.GameObject;
|
|
import gameobjects.RectObject;
|
|
|
|
public class BreakoutLevel2 extends BreakoutLevelBaseAdvanced {
|
|
|
|
@Override
|
|
protected int calcNrBricksX() {
|
|
return 6;
|
|
}
|
|
|
|
@Override
|
|
protected int calcNrBricksY() {
|
|
return 5;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickSizeX() {
|
|
return 60;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickSizeY() {
|
|
return 30;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickStartX() {
|
|
return 90;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickStartY() {
|
|
return 60;
|
|
}
|
|
|
|
@Override
|
|
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
|
|
for(int i = 0; i < 20; i++) {
|
|
//Zufällige Farbe
|
|
gameobjects.FallingStar effect = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), -240, 240, Color.RED, 3);
|
|
this.addObject(effect);
|
|
}
|
|
|
|
this.ball.setVY(this.ball.getVY()*-1);
|
|
this.deleteObject(brick.getId());
|
|
//logger.trace("Collision detected of ball and brick " + brick.getId());
|
|
}
|
|
|
|
@Override
|
|
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
|
|
if (ball.getX()>= (ego.getX() + 0.45d * 60)) {
|
|
this.ball.setVX(this.ball.getVX()*-1);
|
|
} else if (ball.getX()<= (ego.getX() - 0.45d * 60)) {
|
|
this.ball.setVX(this.ball.getVX()*-1);
|
|
}
|
|
this.ball.setVY(this.ball.getVY()*-1);
|
|
|
|
//logger.trace("Collision detected of ball and ego ");
|
|
}
|
|
|
|
@Override
|
|
protected GameObject createEgoObject() {
|
|
RectObject egoObject_BL1 = new RectObject("egoObject_BL1", this, 350, 550, 0, 0, 60, 10, Color.BLUE);
|
|
egoObject_BL1.addController(new controller.EgoController(60, 10));
|
|
egoObject_BL1.addCollider(new RectCollider("egoObject_BL1_Col", egoObject_BL1, 60, 10));
|
|
//logger.debug("Ego created ");
|
|
return egoObject_BL1;
|
|
}
|
|
|
|
@Override
|
|
protected GameObject createBall() {
|
|
gameobjects.FallingStar BallObject_BL1 = new gameobjects.FallingStar ("BallObject_BL1", this, 350, 350, 130, 130, Color.RED, 5);
|
|
BallObject_BL1.addController(new controller.ReboundController());
|
|
//logger.debug("Ball created ");
|
|
return BallObject_BL1;
|
|
}
|
|
|
|
@Override
|
|
protected GameObject createBrick(int row, int column) {
|
|
double a = Math.random();
|
|
|
|
if(a <= 0.25) {
|
|
RectObject brick0 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.GREEN);
|
|
brick0.addCollider(new RectCollider("brick" + row + column + "Col", brick0, 60, 30));
|
|
return brick0;
|
|
}
|
|
if(a > 0.25 && a <= 0.5) {
|
|
RectObject brick1 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.BLUE);
|
|
brick1.addCollider(new RectCollider("brick" + row + column + "Col", brick1, 60, 30));
|
|
return brick1;
|
|
}
|
|
if(a > 0.5 && a <= 0.75) {
|
|
RectObject brick2 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.PINK);
|
|
brick2.addCollider(new RectCollider("brick" + row + column + "Col", brick2, 60, 30));
|
|
return brick2;
|
|
}
|
|
RectObject brick3 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.YELLOW);
|
|
brick3.addCollider(new RectCollider("brick" + row + column + "Col", brick3, 60, 30));
|
|
return brick3;
|
|
//logger.debug("Brick created: " + brick.getId());
|
|
}
|
|
|
|
}
|