Browse Source

Merge remote-tracking branch 'prof/main'

master
fdai7303 3 years ago
parent
commit
3efb976457
  1. 9
      GameProject/src/base/MovingObjectsGame.java
  2. 35
      GameProject/src/controller/ReboundController2.java
  3. 2
      GameProject/src/log4j2.xml
  4. 28
      GameProject/src/playground/LevelMovingHitObjects.java
  5. 2
      GameProject/src/playground/package-info.java

9
GameProject/src/base/MovingObjectsGame.java

@ -1,13 +1,17 @@
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}.
*
*/
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();
}
}

2
GameProject/src/log4j2.xml

@ -25,6 +25,6 @@
<Logger name="playground" level="info">
</Logger>
</loggers>
</configuration>

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!";
}
}

2
GameProject/src/playground/package-info.java

@ -2,7 +2,7 @@
* The package playground contains all level specific logic and control of level logic.
* The structure and general logic (with global and local flags to be stored/used)
* is provided in abstract base class {@link Playground}.<br>
* Child-classes implement specific logic for one level and game type (e.g. {@link SpaceInvadersLevel}).<b>
* Child-classes implement specific logic for one level and game type (e.g. {@link SpaceInvadersLevel}).<br>
*
* Generally, the base class {@link Playground} supports totally different game types to be implemented.
*/

Loading…
Cancel
Save