Manu
3 years ago
3 changed files with 102 additions and 4 deletions
-
5GameProject/src/base/BreakoutGame.java
-
2GameProject/src/base/GameLoop.java
-
99GameProject/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); |
||||
|
} |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue