diff --git a/spaceinvaders/GameProject/.project b/spaceinvaders/GameProject/.project index 0a0a9e3..46662e1 100644 --- a/spaceinvaders/GameProject/.project +++ b/spaceinvaders/GameProject/.project @@ -14,15 +14,4 @@ org.eclipse.jdt.core.javanature - - - 1654173149171 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - diff --git a/spaceinvaders/GameProject/src/base/MovingObjectsGame.java b/spaceinvaders/GameProject/src/base/MovingObjectsGame.java index 7191923..93ec2ad 100644 --- a/spaceinvaders/GameProject/src/base/MovingObjectsGame.java +++ b/spaceinvaders/GameProject/src/base/MovingObjectsGame.java @@ -32,7 +32,6 @@ public class MovingObjectsGame extends GameLoop { @Override public void defineLevels() { this.resetLevels(); - //this.addLevel(new LevelMovingObjects()); this.addLevel(new LevelMovingHitObjects()); } diff --git a/spaceinvaders/GameProject/src/controller/MineController.java b/spaceinvaders/GameProject/src/controller/MineController.java index 5aa7e83..8558db4 100644 --- a/spaceinvaders/GameProject/src/controller/MineController.java +++ b/spaceinvaders/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(); } } diff --git a/spaceinvaders/GameProject/src/log4j2.xml b/spaceinvaders/GameProject/src/log4j2.xml index 63b0589..f21f70a 100644 --- a/spaceinvaders/GameProject/src/log4j2.xml +++ b/spaceinvaders/GameProject/src/log4j2.xml @@ -20,7 +20,7 @@ - + diff --git a/spaceinvaders/GameProject/src/playground/BreakoutLevelBase.java b/spaceinvaders/GameProject/src/playground/BreakoutLevelBase.java index 0a67890..79ddd44 100644 --- a/spaceinvaders/GameProject/src/playground/BreakoutLevelBase.java +++ b/spaceinvaders/GameProject/src/playground/BreakoutLevelBase.java @@ -127,7 +127,7 @@ public abstract class BreakoutLevelBase extends Playground { if (this.ego.collisionDetection(ball)) { logger.trace("Collision detected of ball and ego"); - actionIfBallHitsEgo(this.ball, this.ego); + this.actionIfBallHitsEgo(this.ball, this.ego); } } diff --git a/spaceinvaders/GameProject/src/playground/BreakoutLevelBaseAdvanced.java b/spaceinvaders/GameProject/src/playground/BreakoutLevelBaseAdvanced.java new file mode 100644 index 0000000..1022481 --- /dev/null +++ b/spaceinvaders/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.
+ * 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."); + } + +}