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.
150 lines
3.6 KiB
150 lines
3.6 KiB
package playground;
|
|
|
|
import java.awt.Color;
|
|
|
|
import controller.EgoController;
|
|
import controller.*;
|
|
import gameobjects.FallingStar;
|
|
import gameobjects.GameObject;
|
|
import gameobjects.RectObject;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import java.util.Random;
|
|
|
|
import collider.RectCollider;
|
|
|
|
public class BreakoutLevel2 extends BreakoutLevelBaseAdvanced {
|
|
|
|
Random randomizer = new Random();
|
|
|
|
private static Logger logger = LogManager.getLogger(BreakoutLevel2.class);
|
|
|
|
@Override
|
|
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
|
|
deleteObject(brick.getId());
|
|
ball.setVY(ball.getVY()*-1);
|
|
for(int i = 0; i < 20; i++) {
|
|
this.addObject(this.createMiniBall("miniball"+i, brick.getX(), brick.getY()));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
protected GameObject createMiniBall(String ballID, double xpos, double ypos) {
|
|
double speedx = randomizer.nextInt(480);
|
|
if(speedx > 240) {
|
|
speedx = speedx/2*-1;
|
|
}
|
|
double speedy = randomizer.nextInt(480);
|
|
if(speedy > 240) {
|
|
speedy = speedy/2*-1;
|
|
}
|
|
GameObject ball = new FallingStar("MiniBall1"+ ballID, this, xpos, ypos, speedx, speedy, new Color(randomizer.nextInt(255),randomizer.nextInt(255),randomizer.nextInt(255)), 3);
|
|
ball.addController(new LimitedTimeController(this.gameTime, 3));
|
|
//logger.info("ball created.");
|
|
return ball;
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
|
|
ball.setVY(ball.getVY()*-1);
|
|
|
|
if(ball.getX() < ego.getX() && ball.getVX() >0) {
|
|
ball.setVX(ball.getVX()*-1);
|
|
}
|
|
if(ball.getX() > ego.getX() && ball.getVX() <0) {
|
|
ball.setVX(ball.getVX()*-1);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected int calcNrBricksX() {
|
|
|
|
// lt. Aufgabe sollten es eigentlich 6 sein - die passen allerdings nicht komplett ins Fenster ;)
|
|
// --> deshalb haben wir nur 5...
|
|
return 5;
|
|
}
|
|
|
|
@Override
|
|
protected int calcNrBricksY() {
|
|
// TODO Auto-generated method stub
|
|
return 5;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickSizeX() {
|
|
// TODO Auto-generated method stub
|
|
return 60;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickSizeY() {
|
|
// TODO Auto-generated method stub
|
|
return 30;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickStartX() {
|
|
// TODO Auto-generated method stub
|
|
return 90;
|
|
}
|
|
|
|
@Override
|
|
protected double getBrickStartY() {
|
|
// TODO Auto-generated method stub
|
|
return 60;
|
|
}
|
|
|
|
@Override
|
|
protected GameObject createEgoObject() {
|
|
RectObject blueBox = new RectObject("ego", this, 350, 550, 0, 0, 60, 10, Color.BLUE);
|
|
blueBox.generateColliders();
|
|
EgoController ec = new EgoController(30);
|
|
blueBox.addController(ec);
|
|
logger.info("ego created.");
|
|
return blueBox;
|
|
}
|
|
|
|
@Override
|
|
protected GameObject createBall() {
|
|
GameObject ball = new FallingStar("ball1", this, 350, 350, 130, 130, Color.RED, 5);
|
|
ball.addController(new ReboundController());
|
|
logger.info("ball created.");
|
|
return ball;
|
|
}
|
|
|
|
@Override
|
|
protected GameObject createBrick(int row, int column) {
|
|
double xPos = getBrickStartX()+(2*row*getBrickSizeX());
|
|
double yPos = getBrickStartY()+(2*column*getBrickSizeY());
|
|
//if(row % 2 == 0 || column % 2 == 0) {
|
|
// return null;
|
|
//}
|
|
|
|
Color col = null;
|
|
double random = Math.random();
|
|
if(random < 0.25) {
|
|
col = Color.GREEN;
|
|
}
|
|
if(random >= 0.25 && random < 0.5) {
|
|
col = Color.RED;
|
|
}
|
|
if(random >= 0.5 && random < 0.75) {
|
|
col = Color.BLUE;
|
|
}
|
|
if(random >= 0.75) {
|
|
col = Color.YELLOW;
|
|
}
|
|
|
|
RectObject brick = new RectObject("brick"+row+column, this, xPos, yPos, 0, 0, 60, 30, col);
|
|
|
|
|
|
|
|
brick.addCollider(new RectCollider("brickcoll"+row+column, brick, 60, 30));
|
|
logger.info("brick created.");
|
|
return brick;
|
|
}
|
|
|
|
}
|