Space von Team 22 (Nico B. Benjamin F. Lea A.)
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.

117 lines
3.4 KiB

package playground;
import java.awt.Color;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import collider.RectCollider;
import controller.EgoController;
import controller.ReboundController2;
import gameobjects.FallingStar;
import gameobjects.GameObject;
import gameobjects.RectObject;
/**
* Class that generates a level with one egoObject, ball and ten bricks which need to be destroyed with the ball.
*/
public class BreakoutLevel1 extends BreakoutLevelBase {
private static Logger logger2 = LogManager.getLogger(BreakoutLevel1.class);
/**
* This method defines the behavior when the ball hits a brick. It allows the ball to destroy the brick and move on in opposite direction.
*
* @param ball GameObject the one ball of the game.
* @param brick GameObject the brick that is hit.
*/
@Override
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
ball.setVY(ball.getVY() * -1);
this.deleteObject(brick.id);
}
/**
* This method defines the behavior when the ball hits the EgoObject.
*
* @param ball GameObject the one ball in the game.
* @param ego GameObject the object the player controls.
*
*/
@Override
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
ball.setVY(ball.getVY() * -1);
}
/**
* This method creates a new RectObject.
*
* @return ego object.
*/
@Override
protected GameObject createEgoObject() {
RectObject ego = new RectObject("ego", this, 350d, 550d, 0d, 0d, 80d, 10d, Color.BLUE);
EgoController eController = new EgoController(80d, 10d);
ego.addController(eController);
RectCollider collider1 = new RectCollider("collider1", ego, 80d, 10d);
ego.addCollider(collider1);
logger2.info("sucessfully created ego object with controller and collider");
return ego;
}
/**
* This method creates a new ball.
*
* @return ball
*/
@Override
protected GameObject createBall() {
FallingStar ball = new FallingStar("ball", this, 350d, 350d, 120d, 120d, Color.RED, 5d);
ReboundController2 bbound = new ReboundController2();
ball.addController(bbound);
logger2.info("sucessfully created ball object with controller");
return ball;
}
/**
* This method creates a new brick.
*
* @param row int row for position of the brick.
* @param column int column for the position of the brick.
*
* @return brick.
*/
@Override
protected GameObject createBrick(int row, int column) {
RectObject brick = new RectObject("brick" + row + column, this, 40d+ column * 65, 40d + row * 35, 0d, 0d, 60d, 30d, Color.GREEN);
RectCollider greenCollider = new RectCollider("greenCollider", brick, 60d, 30d);
brick.addCollider(greenCollider);
logger2.info("sucessfully created a brick object and collider");
return brick;
}
/**
* This method creates 3 rows and 10 columns with bricks. It also adds objects of ball and ego to Playground.
*/
@Override
public void prepareLevel(String level) {
this.ego = createEgoObject();
this.ball = createBall();
this.addObject(this.ego);
this.addObject(this.ball);
logger2.info("added ego and ball object to the current level");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 10; j++) {
this.addObject(createBrick(i ,j));
}
}
logger2.info("created all 30 bricks");
}
}