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.
122 lines
3.5 KiB
122 lines
3.5 KiB
package playground;
|
|
|
|
import java.awt.Color;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import controller.*;
|
|
import collider.RectCollider;
|
|
import gameobjects.FallingStar;
|
|
import gameobjects.GameObject;
|
|
import gameobjects.RectObject;
|
|
|
|
public class BreakoutLevel1 extends BreakoutLevelBase {
|
|
|
|
private static Logger logger = LogManager.getLogger(BreakoutLevel1.class);
|
|
|
|
/**
|
|
* Method that gets called by applyGameLogic() whenever the ball collides with a brick.
|
|
* --> this brick will be deleted.
|
|
* Ball bounces back.
|
|
*
|
|
* @param ball A reference to the current ball object
|
|
* @param brick A reference to the ego object
|
|
*/
|
|
@Override
|
|
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
|
|
deleteObject(brick.getId());
|
|
ball.setVY(ball.getVY()*-1);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Method that gets called by applyGameLogic() whenever the ball collides with the ego object.
|
|
* --> Ball bounces back.
|
|
*
|
|
* @param ball A reference to the current ball object
|
|
* @param ego A reference to the ego object
|
|
*/
|
|
@Override
|
|
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
|
|
ball.setVY(ball.getVY()*-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Creates the ego object and returns it, called by {@link #prepareLevel}. Does NOT add the ego
|
|
* object to the playground, but returns it.
|
|
*
|
|
* @return The created ego object instance (of class {@link RectObject} with
|
|
* {@link EgoController}.
|
|
*/
|
|
@Override
|
|
protected GameObject createEgoObject() {
|
|
RectObject blueBox = new RectObject("ego", this, 350, 550, 0, 0, 80, 10, Color.BLUE);
|
|
blueBox.generateColliders();
|
|
EgoController ec = new EgoController(30);
|
|
blueBox.addController(ec);
|
|
logger.info("ego created.");
|
|
return blueBox;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Creates the ball object and returns it, called by #prepareLevel. Does NOT add the ball object
|
|
* to the playground, but returns it.
|
|
*
|
|
* @return The created ball object instance (of class {@link FallingStar})
|
|
*/
|
|
@Override
|
|
protected GameObject createBall() {
|
|
GameObject ball = new FallingStar("ball1", this, 350, 350, 120, 120, Color.RED, 5);
|
|
ball.addController(new ReboundController());
|
|
logger.info("ball created.");
|
|
return ball;
|
|
}
|
|
|
|
|
|
/**
|
|
* Creates the GameObject (RectObject) instance representing a single brick at a certain grid
|
|
* position. The brick is NOT added here, but returned.
|
|
*
|
|
* @param row row position in the grid, ranges from 0 to calcNrBricksY()-1
|
|
* @param column column position in the grid of bricks, ranges from 0 to calcNrBricksX()-1
|
|
* @return The GameObject instance (really a RectObject) representing the created brick.
|
|
*/
|
|
@Override
|
|
protected GameObject createBrick(int row, int column) {
|
|
RectObject brick = new RectObject("brick"+row+column, this, 40 + row * 69, 40 + column * 40, 0, 0, 60, 30, Color.GREEN);
|
|
brick.addCollider(new RectCollider("brickcoll"+row+column, brick, 60, 30));
|
|
logger.info("brick created.");
|
|
return brick;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* added ego object, ball and rows of bricks to the level.
|
|
*
|
|
* @param level level String to identify the level.
|
|
*/
|
|
@Override
|
|
public void prepareLevel(String level) {
|
|
GameObject ego1 = this.createEgoObject();
|
|
this.ego = ego1;
|
|
this.addObject(ego1);
|
|
|
|
|
|
GameObject ball1 = this.createBall();
|
|
this.ball = ball1;
|
|
this.addObject(ball1);
|
|
|
|
for (int x = 0; x < 10; x++) {
|
|
for (int y = 0; y < 3; y++) {
|
|
GameObject greenBricks = this.createBrick(x,y);
|
|
this.addObject(greenBricks);
|
|
}
|
|
}
|
|
}
|
|
}
|