5 Commits
64624f4273
...
6afed1ded1
Author | SHA1 | Message | Date |
---|---|---|---|
Nico B | 6afed1ded1 |
finished HA08
|
2 years ago |
Nico B | 0a88b6a89f |
pull hao8
|
2 years ago |
Nico B | eaced1bce7 |
mod
|
2 years ago |
jkonert | d1bd4d1460 |
small typo fix in JavaDoc
|
3 years ago |
jkonert | 2ee8610620 |
BreakoutLevelBaseAdvanced for HA07 added
|
3 years ago |
5 changed files with 265 additions and 8 deletions
-
3GameProject/src/base/BreakoutGame.java
-
21GameProject/src/controller/MineController.java
-
147GameProject/src/playground/BreakoutLevel2.java
-
98GameProject/src/playground/BreakoutLevelBaseAdvanced.java
-
2GameProject/src/playground/LevelMovingObjects.java
@ -0,0 +1,147 @@ |
|||||
|
package playground; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
|
||||
|
import collider.RectCollider; |
||||
|
import controller.EgoController; |
||||
|
import controller.LimitedTimeController; |
||||
|
import controller.ReboundController2; |
||||
|
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) { |
||||
|
for (int i = 0; i < 20; i++) { |
||||
|
double color = Math.random(); |
||||
|
Color random = null; |
||||
|
if (color <= 0.24) { |
||||
|
random = Color.RED; |
||||
|
} |
||||
|
else if (color >= 0.25 && color <= 0.49) { |
||||
|
random = Color.BLUE; |
||||
|
} |
||||
|
else if (color >= 0.5 && color <= 0.74) { |
||||
|
random = Color.YELLOW; |
||||
|
} |
||||
|
else if (color >= 0.75) { |
||||
|
random = Color.GREEN; |
||||
|
} |
||||
|
|
||||
|
double vx = Math.random(); |
||||
|
if(vx <= 0.49) { |
||||
|
vx *= 240; |
||||
|
} else { |
||||
|
vx *= -240; |
||||
|
} |
||||
|
|
||||
|
double vy = Math.random(); |
||||
|
if(vy <= 0.49) { |
||||
|
vy *= 240; |
||||
|
} else { |
||||
|
vy *= -240; |
||||
|
} |
||||
|
FallingStar fragment = new FallingStar("fragment"+ i + getGameTime(), this, brick.getX(), brick.getY(), vx, vy, random, 5d); |
||||
|
LimitedTimeController time = new LimitedTimeController(getGameTime(), 2); |
||||
|
fragment.addController(time); |
||||
|
this.addObject(fragment); |
||||
|
} |
||||
|
|
||||
|
ball.setVY(ball.getVY() * -1); |
||||
|
this.deleteObject(brick.id); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) { |
||||
|
if (ball.getVX() > 0 && ball.getX() <= ego.getX()- 25) { |
||||
|
ball.setVX(ball.getVX()*-1); |
||||
|
ball.setVY(ball.getVY() * -1); |
||||
|
} |
||||
|
else if (ball.getVX() < 0 && ball.getX() >= ego.getX() + 25) { |
||||
|
ball.setVX(ball.getVX() * -1); |
||||
|
ball.setVY(ball.getVY() * -1); |
||||
|
} |
||||
|
else { |
||||
|
ball.setVY(ball.getVY() * -1); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected GameObject createEgoObject() { |
||||
|
RectObject ego = new RectObject("ego", this, 350d, 550d, 0d, 0d, 60d, 10d, Color.BLUE); |
||||
|
EgoController eController = new EgoController(60d, 10d); |
||||
|
ego.addController(eController); |
||||
|
RectCollider collider1 = new RectCollider("collider1", ego, 60d, 10d); |
||||
|
ego.addCollider(collider1); |
||||
|
return ego; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected GameObject createBall() { |
||||
|
FallingStar ball = new FallingStar("ball", this, 350d, 350d, 130d, 130d, Color.RED, 5d); |
||||
|
ReboundController2 bbound = new ReboundController2(); |
||||
|
ball.addController(bbound); |
||||
|
return ball; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected GameObject createBrick(int row, int column) { |
||||
|
double color = Math.random(); |
||||
|
Color random = null; |
||||
|
if (color <= 0.24) { |
||||
|
random = Color.RED; |
||||
|
} |
||||
|
else if (color >= 0.25 && color <= 0.49) { |
||||
|
random = Color.BLUE; |
||||
|
} |
||||
|
else if (color >= 0.5 && color <= 0.74) { |
||||
|
random = Color.YELLOW; |
||||
|
} |
||||
|
else if (color >= 0.75) { |
||||
|
random = Color.GREEN; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
RectObject brick = new RectObject("brick" + row + column, this, 90d+ column * 120, 60d + row * 60d, 0d, 0d, 60d, 30d, random); |
||||
|
RectCollider greenCollider = new RectCollider("greenCollider", brick, 60d, 30d); |
||||
|
brick.addCollider(greenCollider); |
||||
|
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