From 4e12a4bd68e7edfb97120c88ee1ad6801441ecc1 Mon Sep 17 00:00:00 2001 From: Manu Date: Thu, 16 Jun 2022 13:36:08 +0200 Subject: [PATCH] =?UTF-8?q?Ge=C3=A4ndert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GameProject/src/base/BreakoutGame.java | 5 +- GameProject/src/base/GameLoop.java | 2 +- .../src/playground/BreakoutLevel1.java | 99 +++++++++++++++++++ 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 GameProject/src/playground/BreakoutLevel1.java diff --git a/GameProject/src/base/BreakoutGame.java b/GameProject/src/base/BreakoutGame.java index 2c636ff..cf8cdac 100644 --- a/GameProject/src/base/BreakoutGame.java +++ b/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 BreakoutLevel1());// this.addLevel(new BreakoutLevel1()); // FIXME add this as soon as your level exists } /** diff --git a/GameProject/src/base/GameLoop.java b/GameProject/src/base/GameLoop.java index 49648cf..9837a1a 100644 --- a/GameProject/src/base/GameLoop.java +++ b/GameProject/src/base/GameLoop.java @@ -40,7 +40,7 @@ public class GameLoop { */ private List levels = new ArrayList(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. */ diff --git a/GameProject/src/playground/BreakoutLevel1.java b/GameProject/src/playground/BreakoutLevel1.java new file mode 100644 index 0000000..fa4e507 --- /dev/null +++ b/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); +} + \ No newline at end of file