6 Commits
857baaaa94
...
aa642b5a49
Author | SHA1 | Message | Date |
---|---|---|---|
Manu | aa642b5a49 |
Hausaufgabe 9
|
2 years ago |
Manu | 43996524c7 |
Hausaufgabe 9
|
2 years ago |
Manu | 4e12a4bd68 |
Geändert
|
3 years ago |
Manu | 4ac0e82a85 |
Neuer Commit
|
3 years ago |
jkonert | d1bd4d1460 |
small typo fix in JavaDoc
|
3 years ago |
jkonert | 2ee8610620 |
BreakoutLevelBaseAdvanced for HA07 added
|
3 years ago |
8 changed files with 311 additions and 8 deletions
-
BIN.DS_Store
-
5GameProject/src/base/BreakoutGame.java
-
2GameProject/src/base/GameLoop.java
-
10GameProject/src/controller/BreakoutController.java
-
21GameProject/src/controller/MineController.java
-
99GameProject/src/playground/BreakoutLevel1.java
-
84GameProject/src/playground/BreakoutLevel2.java
-
98GameProject/src/playground/BreakoutLevelBaseAdvanced.java
@ -0,0 +1,10 @@ |
|||
package controller; |
|||
|
|||
public class BreakoutController extends EgoController { |
|||
|
|||
public BreakoutController(double width, double height) { |
|||
super(width, 0); |
|||
} |
|||
|
|||
|
|||
} |
@ -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); |
|||
} |
|||
|
@ -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; |
|||
} |
|||
|
|||
|
|||
} |
@ -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."); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue