|
|
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 Geschwindigkeiten
int effectVX = (int)(Math.random() * 480) - 240; int effectVY = (int)(Math.random() * 480) - 240; //Fallingstarobject
// gameobjects.FallingStar effect = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.RED, 3);
// effect.addController(new controller.LimitedTimeController(getGameTime(), 2));
// this.addObject(effect);
double a = Math.random(); if(a <= 0.25) { gameobjects.FallingStar effect0 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.GREEN, 3); effect0.addController(new controller.LimitedTimeController(getGameTime(), 2)); this.addObject(effect0); } if(a > 0.25 && a <= 0.5) { gameobjects.FallingStar effect1 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.BLUE, 3); effect1.addController(new controller.LimitedTimeController(getGameTime(), 2)); this.addObject(effect1); } if(a > 0.5 && a <= 0.75) { gameobjects.FallingStar effect2 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.PINK, 3); effect2.addController(new controller.LimitedTimeController(getGameTime(), 2)); this.addObject(effect2); } if(a > 0.75) { gameobjects.FallingStar effect3 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.YELLOW, 3); effect3.addController(new controller.LimitedTimeController(getGameTime(), 2)); this.addObject(effect3); }
} 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());
}
}
|