Browse Source

Geändert

main
Manu 3 years ago
parent
commit
4e12a4bd68
  1. 3
      GameProject/src/base/BreakoutGame.java
  2. 2
      GameProject/src/base/GameLoop.java
  3. 99
      GameProject/src/playground/BreakoutLevel1.java

3
GameProject/src/base/BreakoutGame.java

@ -11,7 +11,6 @@ import playground.*;
*/
public class BreakoutGame extends GameLoop {
private static Logger logger = LogManager.getLogger(BreakoutGame.class);
/**
* adds only one level to play ({@link playground.LevelBreakout1}).
@ -19,7 +18,7 @@ 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());// 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.
*/

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, 80, 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);
}
Loading…
Cancel
Save