Browse Source

fast fertig Hausi 8

master
Emma Nagelschmidt 3 years ago
parent
commit
e940909c32
  1. BIN
      GameProject.zip
  2. 1
      GameProject/src/base/BreakoutGame.java
  3. 108
      GameProject/src/playground/BreakoutLevel2.java

BIN
GameProject.zip

1
GameProject/src/base/BreakoutGame.java

@ -19,6 +19,7 @@ public class BreakoutGame extends GameLoop {
@Override
public void defineLevels() {
this.resetLevels(); // removes Level1 added by superclass constructor
this.addLevel(new BreakoutLevel2());
this.addLevel(new BreakoutLevel1()); // FIXME add this as soon as your level exists
}

108
GameProject/src/playground/BreakoutLevel2.java

@ -0,0 +1,108 @@
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());
}
}
Loading…
Cancel
Save