Browse Source

finished HA08

main
Nico B 2 years ago
parent
commit
6afed1ded1
  1. 3
      GameProject/src/base/BreakoutGame.java
  2. 147
      GameProject/src/playground/BreakoutLevel2.java

3
GameProject/src/base/BreakoutGame.java

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

147
GameProject/src/playground/BreakoutLevel2.java

@ -0,0 +1,147 @@
package playground;
import java.awt.Color;
import collider.RectCollider;
import controller.EgoController;
import controller.LimitedTimeController;
import controller.ReboundController2;
import gameobjects.FallingStar;
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++) {
double color = Math.random();
Color random = null;
if (color <= 0.24) {
random = Color.RED;
}
else if (color >= 0.25 && color <= 0.49) {
random = Color.BLUE;
}
else if (color >= 0.5 && color <= 0.74) {
random = Color.YELLOW;
}
else if (color >= 0.75) {
random = Color.GREEN;
}
double vx = Math.random();
if(vx <= 0.49) {
vx *= 240;
} else {
vx *= -240;
}
double vy = Math.random();
if(vy <= 0.49) {
vy *= 240;
} else {
vy *= -240;
}
FallingStar fragment = new FallingStar("fragment"+ i + getGameTime(), this, brick.getX(), brick.getY(), vx, vy, random, 5d);
LimitedTimeController time = new LimitedTimeController(getGameTime(), 2);
fragment.addController(time);
this.addObject(fragment);
}
ball.setVY(ball.getVY() * -1);
this.deleteObject(brick.id);
}
@Override
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
if (ball.getVX() > 0 && ball.getX() <= ego.getX()- 25) {
ball.setVX(ball.getVX()*-1);
ball.setVY(ball.getVY() * -1);
}
else if (ball.getVX() < 0 && ball.getX() >= ego.getX() + 25) {
ball.setVX(ball.getVX() * -1);
ball.setVY(ball.getVY() * -1);
}
else {
ball.setVY(ball.getVY() * -1);
}
}
@Override
protected GameObject createEgoObject() {
RectObject ego = new RectObject("ego", this, 350d, 550d, 0d, 0d, 60d, 10d, Color.BLUE);
EgoController eController = new EgoController(60d, 10d);
ego.addController(eController);
RectCollider collider1 = new RectCollider("collider1", ego, 60d, 10d);
ego.addCollider(collider1);
return ego;
}
@Override
protected GameObject createBall() {
FallingStar ball = new FallingStar("ball", this, 350d, 350d, 130d, 130d, Color.RED, 5d);
ReboundController2 bbound = new ReboundController2();
ball.addController(bbound);
return ball;
}
@Override
protected GameObject createBrick(int row, int column) {
double color = Math.random();
Color random = null;
if (color <= 0.24) {
random = Color.RED;
}
else if (color >= 0.25 && color <= 0.49) {
random = Color.BLUE;
}
else if (color >= 0.5 && color <= 0.74) {
random = Color.YELLOW;
}
else if (color >= 0.75) {
random = Color.GREEN;
}
RectObject brick = new RectObject("brick" + row + column, this, 90d+ column * 120, 60d + row * 60d, 0d, 0d, 60d, 30d, random);
RectCollider greenCollider = new RectCollider("greenCollider", brick, 60d, 30d);
brick.addCollider(greenCollider);
return brick;
}
}
Loading…
Cancel
Save