From 9bd85c315fb659df2a1be18a121b3dbc1fccedb7 Mon Sep 17 00:00:00 2001 From: fdai7222 Date: Thu, 23 Jun 2022 13:52:36 +0200 Subject: [PATCH] konertversion ha9 added --- .../GameProject/src/base/BreakoutGame.java | 2 +- .../src/playground/BreakoutLevel0.java | 119 ++++++++++++++++++ .../src/playground/BreakoutLevel3.java | 12 ++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 spaceinvaders/GameProject/src/playground/BreakoutLevel0.java create mode 100644 spaceinvaders/GameProject/src/playground/BreakoutLevel3.java diff --git a/spaceinvaders/GameProject/src/base/BreakoutGame.java b/spaceinvaders/GameProject/src/base/BreakoutGame.java index a792147..d923597 100644 --- a/spaceinvaders/GameProject/src/base/BreakoutGame.java +++ b/spaceinvaders/GameProject/src/base/BreakoutGame.java @@ -19,7 +19,7 @@ public class BreakoutGame extends GameLoop { @Override public void defineLevels() { this.resetLevels(); // removes Level1 added by superclass constructor - this.addLevel(new BreakoutLevel2()); // FIXME add this as soon as your level exists + this.addLevel(new BreakoutLevel3()); // sorry for the git conflict this may cause! } /** diff --git a/spaceinvaders/GameProject/src/playground/BreakoutLevel0.java b/spaceinvaders/GameProject/src/playground/BreakoutLevel0.java new file mode 100644 index 0000000..842c1a1 --- /dev/null +++ b/spaceinvaders/GameProject/src/playground/BreakoutLevel0.java @@ -0,0 +1,119 @@ +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; + +/** + * simple solution example for Breakout game. + * + * not implemented: penalty if balls hits ground, no score for removed bricks, no bonus items, no + * lives. + * + * + */ + + +public class BreakoutLevel0 extends BreakoutLevelBase { + + private static Logger logger = LogManager.getLogger(BreakoutLevelBase.class); + + + protected GameObject createEgoObject() { + RectObject ro = new RectObject("ego", this, 350, 550, 0, 0, 80, 10, Color.BLUE); + ro.generateColliders(); + EgoController ec = new EgoController(80,10); + ro.addController(ec); + logger.info("ego created."); + + return ro; + } + + + protected GameObject createBall() { + GameObject co = new FallingStar("ball1", this, 350, 350, 100, 100, Color.RED, 5); + co.addController(new ReboundController2()); + logger.info("ball created."); + return co; + } + + + /** + * creates one brick. For + * collision {@link RectCollider} is used. + */ + @Override + protected GameObject createBrick(int row, int column) { + double xSize = 60; + double ySize = 30; + double xStart = 40; + double yStart = 40; + double space = 5; + Color c = Color.BLUE; + + RectObject ro = new RectObject("brick" + row + "/" + column, this, xStart + column * (xSize + space), + yStart + row * (ySize + space), 0, 0, xSize - 4, ySize - 4, c); + RectCollider rc = new RectCollider("egal", ro, xSize - 4, ySize - 4); + ro.addCollider(rc); + + return ro; + } + + /** + * lets ball bounce in Y direction, deletes brick. + */ + @Override + protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) { + + ball.setVY(ball.getVY() * -1); // bounce effect for ball + this.deleteObject(brick.getId()); // remove brick from field + logger.debug("deleted brick " + brick.getId()); + + } + + + /** + * Let the ball bounce off in Y direction. + * + */ + @Override + protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) { + double ballY = ball.getY(); + double egoY = ego.getY(); + ball.setY(ballY < egoY ? ballY - 10 : ballY + 10); // radius 5 hard coded. + ball.setVY(ball.getVY() * -1); + logger.debug("ball bounces of ego object."); + } + + + /** + * Prepares a Breakout level with a 3 x 3 matrix of blocks on top. This method relies on the + * methods {@link #createEgo}, {@link #createBall} and {@link #createBrick}, among others. + * + * @param level String passes by the game engine (not used currently and can be ignored). + */ + @Override + public void prepareLevel(String level) { + for (int y = 3; y < 6; y++) { + for (int x = 0; x < 3; x++) { + logger.trace("trying to create brick X, Y (" + x + "," + y + ")"); + GameObject brick = this.createBrick(x, y); + this.addObject(brick); + } + } + this.ego = this.createEgoObject(); + this.ball = this.createBall(); + this.addObject(this.ego); + this.addObject(this.ball); + logger.info("level preperation succeeded."); + + } + + +} diff --git a/spaceinvaders/GameProject/src/playground/BreakoutLevel3.java b/spaceinvaders/GameProject/src/playground/BreakoutLevel3.java new file mode 100644 index 0000000..cac5682 --- /dev/null +++ b/spaceinvaders/GameProject/src/playground/BreakoutLevel3.java @@ -0,0 +1,12 @@ +package playground; + + + +public class BreakoutLevel3 extends BreakoutLevel0 { + + // your code here + + +} + +