Browse Source

adding files afor HA06 (using RectCollider and Logger)

main
jkonert 3 years ago
parent
commit
58355dbed8
  1. 9
      GameProject/src/base/MovingObjectsGame.java
  2. 35
      GameProject/src/controller/ReboundController2.java
  3. 28
      GameProject/src/playground/LevelMovingHitObjects.java

9
GameProject/src/base/MovingObjectsGame.java

@ -1,7 +1,9 @@
package base;
import java.io.IOException;
import playground.LevelMovingObjects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import playground.*;
/**
* main class to start a game with only one level {@link playground.LevelMovingObjects}.
@ -9,6 +11,8 @@ import playground.LevelMovingObjects;
*/
public class MovingObjectsGame extends GameLoop {
private static Logger logger = LogManager.getLogger(MovingObjectsGame.class);
/**
* starts this game.
*
@ -17,6 +21,7 @@ public class MovingObjectsGame extends GameLoop {
* thrown (and game ends).
*/
public static void main(String[] args) throws IOException {
logger.info("Starting Game Program...let's play and don't get hit!");
GameLoop myGame = new MovingObjectsGame();
myGame.runGame(args);
}
@ -27,7 +32,7 @@ public class MovingObjectsGame extends GameLoop {
@Override
public void defineLevels() {
this.resetLevels();
this.addLevel(new LevelMovingObjects());
this.addLevel(new LevelMovingHitObjects());
}
}

35
GameProject/src/controller/ReboundController2.java

@ -0,0 +1,35 @@
package controller;
/** Controller to let Objects bounce from the outer level limits back and forth.
*
*/
public class ReboundController2 extends ObjectController {
/** inverts the x y direction speeds if the outer limits are reached.
*
*/
@Override
public void updateObject() {
double sizeX = this.getPlayground().preferredSizeX();
double sizeY = this.getPlayground().preferredSizeY();
double objSizeX = 30;
double objSizeY = 30;
if (this.getX() < objSizeX) {
this.setVX(this.getVX() * -1);
this.setX(objSizeX);
} else if (this.getX() > sizeX - objSizeX) {
this.setVX(this.getVX() * -1);
this.setX(sizeX - objSizeX);
}
if (this.getY() < objSizeY) {
this.setVY(this.getVY() * -1);
this.setY(objSizeY);
} else if (this.getY() > sizeY - objSizeY) {
this.setVY(this.getVY() * -1);
this.setY(sizeY - objSizeY);
}
this.applySpeedVector();
}
}

28
GameProject/src/playground/LevelMovingHitObjects.java

@ -0,0 +1,28 @@
package playground;
/**
* Level that creates two RectObjects moving around and if ego is hit by them game is directly lost
* (lives = 0).
*
*/
public class LevelMovingHitObjects extends SpaceInvadersLevel {
// FIXME add logger here
//FIXME add your method overrides here
/**
* "Moving Hitting Objects Level!" is the message.
*
* @return String "Moving & Hitting Objects Level!"
*/
@Override
protected String getStartupMessage() {
return "Moving & Hitting Objects Level!";
}
}
Loading…
Cancel
Save