6 Commits

  1. BIN
      .DS_Store
  2. 5
      GameProject/src/base/BreakoutGame.java
  3. 2
      GameProject/src/base/GameLoop.java
  4. 10
      GameProject/src/controller/BreakoutController.java
  5. 21
      GameProject/src/controller/MineController.java
  6. 99
      GameProject/src/playground/BreakoutLevel1.java
  7. 84
      GameProject/src/playground/BreakoutLevel2.java
  8. 98
      GameProject/src/playground/BreakoutLevelBaseAdvanced.java

BIN
.DS_Store

5
GameProject/src/base/BreakoutGame.java

@ -11,15 +11,14 @@ import playground.*;
*/
public class BreakoutGame extends GameLoop {
private static Logger logger = LogManager.getLogger(BreakoutGame.class);
/**
* adds only one level to play ({@link playground.LevelBreakout1}).
*/
@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.resetLevels();// removes Level1 added by superclass constructor
this.addLevel(new BreakoutLevel2());// this.addLevel(new BreakoutLevel1()); // FIXME add this as soon as your level exists
}
/**

2
GameProject/src/base/GameLoop.java

@ -40,7 +40,7 @@ public class GameLoop {
*/
private List<Playground> levels = new ArrayList<Playground>(0);
private static Logger logger = LogManager.getLogger(GameLoop.class);
protected static Logger logger = LogManager.getLogger(GameLoop.class);
/** constructor which calls {@link #defineLevels()}, which adds all levels of this game.
*/

10
GameProject/src/controller/BreakoutController.java

@ -0,0 +1,10 @@
package controller;
public class BreakoutController extends EgoController {
public BreakoutController(double width, double height) {
super(width, 0);
}
}

21
GameProject/src/controller/MineController.java

@ -4,7 +4,14 @@ import gameobjects.GameObject;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
/**
* Stops GameObject movement at bottom of level and let it 'fly' in x-direction towards ego object.
* If the object flies outside of the level (by x-coordinate) it is removed.
*
* The behavior looks like a sinking sea mine, which stays at a certain depth and moves left/right to catch the player.
*
*
*/
public class MineController extends ObjectController {
int rad = 3;
@ -17,13 +24,19 @@ public class MineController extends ObjectController {
this.lineSpeed = lineSpeed;
}
/**
* Fetches ego object by name 'ego' from current level and determines it's x-position.
* The controlled GameObject will move towards this position (in x-direction only).
* y-direction speed is reduced to zero, if the objects reached lower bound of level (high y-values).
* Only deletes the object if it flies out of visible game area.
*/
@Override
public void updateObject() {
if (gameObject.getY() >= this.getPlayground().getSizeY() - 10) {
this.gameObject.setVY(0);
if (xSpeed == 0.) {
GameObject ego = getPlayground().getObject("ego");
GameObject ego = this.getPlayground().getObject("ego");
double egoXPos = ego.getX();
if (egoXPos > this.gameObject.getX()) {
xSpeed = 50;
@ -38,9 +51,9 @@ public class MineController extends ObjectController {
}
if (this.gameObject.getX() < 0 || (this.gameObject.getX() > this.getPlayground().getSizeX())) {
logger.debug("deleting" + this.gameObject.getId());
getPlayground().deleteObject(this.gameObject.getId());
this.getPlayground().deleteObject(this.gameObject.getId());
}
applySpeedVector();
this.applySpeedVector();
}
}

99
GameProject/src/playground/BreakoutLevel1.java

@ -0,0 +1,99 @@
package playground;
import java.awt.Color;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import controller.EgoController;
import controller.ReboundController;
import gameobjects.GameObject;
import gameobjects.RectObject;
public class BreakoutLevel1 extends BreakoutLevelBase{
/**Erases the objects and reverses the speed.
*
* @param ball GameObject
* @param brick GameObject
*/
@Override
protected void actionIfBallHitsBrick(GameObject ball,GameObject brick) {
logger.info(brick.getId()+"hits");
this.deleteObject(brick.getId());
ball.setVX(ball.getVX()*1.0);
ball.setVY(ball.getVY()*-1.0);
}
/**When ego is hit, the direction changes.
*
* @param ball GameObject
* @param ego GameObject
*/
@Override
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
ball.setVX(ball.getVX()*1.0);
ball.setVY(ball.getVY()*-1.0);
logger.info("Ball collides with ego");
}
/**Creates the ego object and returns it.
* @return ego
*/
@Override
protected GameObject createEgoObject() {
RectObject ego = new RectObject("ego", this, 350, 550, 0, 0, 60, 10, Color.blue);
this.addObject(ego);
ego.addController(new EgoController(ego.getWidth(),ego.getHeight()));
ego.addCollider(new collider.RectCollider(ego.getId(),ego,ego.getWidth(),ego.getHeight()));
return ego;
}
/**Creates Ball object and returns it.
*
* @return ball
*/
@Override
protected GameObject createBall() {
gameobjects.FallingStar ball = new gameobjects.FallingStar("ball",this,350,350,120,120,Color.red,5);
ball.addController(new ReboundController());
return ball;
}
/** Creates a Brick.
* @param row int
* @param column int
* @return brick GameObject
*/
@Override
protected GameObject createBrick(int row, int column) {
RectObject brick = new RectObject("brick"+row+column,this,40+(column*68),40+(row*60),0,0,60,30,Color.green);
brick.addCollider(new collider.RectCollider(brick.getId(),brick,brick.getWidth(),brick.getHeight()));
return brick;
}
/**Prepares the level.
*
* @param level String
*/
@Override
public void prepareLevel(String level) {
this.ego = createEgoObject();
this.ball = createBall();
this.addObject(this.ego);
this.addObject(this.ball);
for (int i = 0; i < 3; i++) {
for (int e = 0; e < 10; e++) {
this.addObject(createBrick(i, e));
}
}
logger.info("Ready!");
}
private static Logger logger = LogManager.getLogger(BreakoutLevel1.class);
}

84
GameProject/src/playground/BreakoutLevel2.java

@ -0,0 +1,84 @@
package playground;
import java.awt.Color;
import controller.BreakoutController;
import controller.EgoController;
import controller.ReboundController;
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) {
if(ball.collisionDetection(brick)) {
ball.setVY(ball.getVY()*-1);
deleteObjectNow(brick.id);
}
}
@Override
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
if(ball.collisionDetection(ego)) {
ball.setVY(ball.getVY()*-1);
}
}
@Override
protected GameObject createEgoObject() {
RectObject ego = new RectObject("ego", this, 350, 550, 0, 0, 80, 10, Color.blue);
this.addObject(ego);
ego.addController(new BreakoutController(ego.getWidth(),ego.getHeight()));
ego.addCollider(new collider.RectCollider(ego.getId(),ego,ego.getWidth(),ego.getHeight()));
return ego;
}
@Override
protected GameObject createBall() {
gameobjects.FallingStar ball = new gameobjects.FallingStar("ball",this,350,350,130,130,Color.red,5);
ball.addController(new ReboundController());
return ball;
}
@Override
protected GameObject createBrick(int row, int column) {
RectObject brick = new RectObject("brick"+row+column,this,40+(column*68),40+(row*60),0,0,60,30,Color.yellow);
brick.addCollider(new collider.RectCollider(brick.getId(),brick,brick.getWidth(),brick.getHeight()));
return brick;
}
}

98
GameProject/src/playground/BreakoutLevelBaseAdvanced.java

@ -0,0 +1,98 @@
package playground;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/**
* Advanced version of abstract {@link BreakoutLevelBase} providing a complete implementation of
* {@link #prepareLevel(String)}. Additionally abstract methods for number of bricks in X and Y
* direction are provided as well as abstract methods for brick sizes and start coordinates.
*
* @see #calcNrBricksX()
* @see #calcNrBricksY()
* @see #getBrickSizeX()
* @see #getBrickSizeY()
* @see #getBrickStartX()
* @see #getBrickStartY()
*
*/
public abstract class BreakoutLevelBaseAdvanced extends BreakoutLevelBase {
private static Logger logger = LogManager.getLogger(BreakoutLevelBaseAdvanced.class);
/**
* provides the number of bricks to be set in horizontal direction.
*
* @return positive value of how many bricks are to be next to each other in X direction
*/
protected abstract int calcNrBricksX();
/**
* provides the number of bricks to be set in vertical direction.
*
* @return positive value of how many bricks are to be next to each other in Y direction
*/
protected abstract int calcNrBricksY();
/**
* provides the length of one brick.
*
* @return positive value of how long a brick should be in X direction.
*/
protected abstract double getBrickSizeX();
/**
* provides the height of one brick.
*
* @return positive value of how high a brick should be in Y direction.
*/
protected abstract double getBrickSizeY();
/**
* provides the start coordinate of upper left corner (X value).
*
* @return positive value of the X coordinate to use as the starting point of the upper left
* corner of the brick set.
*/
protected abstract double getBrickStartX();
/**
* provides the start coordinate of upper left corner (Y value).
*
* @return positive value of the Y coordinate to use as the starting point of the upper left
* corner of the brick set.
*/
protected abstract double getBrickStartY();
/**
* Prepares a complete Breakout type level and uses the values provided by implementations of
* {@link #calcNrBricksX()} and {@link #calcNrBricksY()} to generate the stone matrix.
* Furthermore, it relies on the methods {@link #createEgoObject()}, {@link #createBall} and {@link #createBrick},
* which are meant to be overwritten in subclasses. <br>
* Attention: For collision detection bricks created by {@link #createBrick(int, int)} need to have the String 'brick' in ID.
*
* @see LevelBreakoutBase#prepareLevel(String) for further information.
*
* @param level String passes by the game engine (not used currently and can be ignored).
*
*/
@Override
public void prepareLevel(String level) {
for (int y = 0; y < this.calcNrBricksY(); y++) {
for (int x = 0; x < this.calcNrBricksX(); x++) {
logger.trace("trying to create brick X, Y (" + x + "," + y + ")");
this.addObject(this.createBrick(x, y));
}
}
this.ego = this.createEgoObject();
this.ball = this.createBall();
this.addObject(this.ego);
this.addObject(this.ball);
logger.info("level preperation succeeded.");
}
}
Loading…
Cancel
Save