9 Commits

  1. 1
      .gitignore
  2. 33
      GameProject/src/base/MovingObjectsGame.java
  3. 9
      GameProject/src/collider/package-info.java
  4. 15
      GameProject/src/controller/EgoController.java
  5. 2
      GameProject/src/controller/ObjectController.java
  6. 20
      GameProject/src/controller/ReboundController.java
  7. 7
      GameProject/src/gameobjects/package-info.java
  8. 2
      GameProject/src/playground/Level4.java
  9. 38
      GameProject/src/playground/LevelMovingObjects.java
  10. 9
      GameProject/src/playground/package-info.java

1
.gitignore

@ -93,6 +93,7 @@ local.properties
*.metadata/
*.class
*.prefs
/GameProject/doc/
/GameProject/log/
/GameProject/log\\log4j.log

33
GameProject/src/base/MovingObjectsGame.java

@ -0,0 +1,33 @@
package base;
import java.io.IOException;
import playground.LevelMovingObjects;
/**
* main class to start a game with only one level {@link playground.LevelMovingObjects}.
*
*/
public class MovingObjectsGame extends GameLoop {
/**
* starts this game.
*
* @param args command line parameters (forwarded to {@link GameLoop#runGame(String[])}).
* @throws IOException if highscore.txt file cannot be written or accessed, the exception is
* thrown (and game ends).
*/
public static void main(String[] args) throws IOException {
GameLoop myGame = new MovingObjectsGame();
myGame.runGame(args);
}
/**
* adds only one level to play ({@link playground.LevelMovingObjects}).
*/
@Override
public void defineLevels() {
this.resetLevels();
this.addLevel(new LevelMovingObjects());
}
}

9
GameProject/src/collider/package-info.java

@ -0,0 +1,9 @@
/**
* The package contains classes implementing a 'bounding box' area around game objects. <br>
* The abstract base class {@link Collider} provides the abstract method {@link Collider#collidesWith(Collider)},
* which needs to be implemented by child classes to detect and decide whether or not an object with such instance really collides with the other.
* {@link Collider} instances are to be used for game objects ({@link gameobjects}); see constructors.<br>
*
* The benefit of seperating Colliders from visual representations is that the area for collisions can be smaller/bigger/other shape to improve game play experience.
*/
package collider;

15
GameProject/src/controller/EgoController.java

@ -165,23 +165,14 @@ public class EgoController extends ObjectController {
released = false;
}
/**
* Generelle Idee: Wenn eine Taste gedrückt wird wird sie gespeichert. wenn die zuvor
* gespeicherte Taste wieder losgelassen wird stoppt das Ego-Objekt. Falls vor dem Loslassen
* eine andere Taste gedrückt wird, wird diese gespeichert und die alte vergessen. Dh das
* loslassen der alten Taste stoppt das Objekt nicht. Spezialfall: space, das loslassen von
* space stoppt das Objekt nicht!
*/
if (pressed == true) {
lastPressedKey = pressedKey;
pressedKey = kc;
}
/**
* Nur eine losgelassene Taste die auch vorher gedrückt wurde stoppt das Objekt. Eine
* losgelassene Taste die nicht vorher gedrückt wurde bzw vergessen wurde stoppt das Objekt
* nicht
/*
* Only if the released key is the same as the before pressed one, it stops the ego object movement.
*/
if (released == true) {
if (pressedKey != null) {
@ -219,7 +210,7 @@ public class EgoController extends ObjectController {
// shot
if (kc == KeyEvent.VK_SPACE) {
// space is not registered! Releasing space does not stop the egoobject
// space is not registered! Releasing space does not stop the ego object
this.onSpace(e, ego);
}
}

2
GameProject/src/controller/ObjectController.java

@ -56,7 +56,7 @@ public abstract class ObjectController {
public void applySpeedVector() {
double ts = this.getPlayground().getTimestep();
this.setX(this.getX() + this.getVX() * ts);
gameObject.setY(this.getY() + this.getVY() * ts);
this.setY(this.getY() + this.getVY() * ts);
}

20
GameProject/src/controller/ReboundController.java

@ -0,0 +1,20 @@
package controller;
public class ReboundController extends ObjectController {
@Override
public void updateObject() {
if (this.getX() < 30 || this.getX() > 670) {
this.setVX(this.getVX()*(-1));
}
if (this.getY() < 30 || this.getY() > 670) {
this.setVY(this.getVY()*(-1));
}
this.applySpeedVector();
}
}

7
GameProject/src/gameobjects/package-info.java

@ -0,0 +1,7 @@
/**
* The package gameobjects contains all objects with a visual representation on screen.
* They can be combined to use controller instances for their behavior (subclasses of {@link controller.ObjectController}).
* The abstract base class is {@link GameObject}, which forces child-classes to implement the method
* {@link GameObject#updateObject()}.
*/
package gameobjects;

2
GameProject/src/playground/Level4.java

@ -10,7 +10,7 @@ import org.apache.logging.log4j.Logger;
/**
* extends {@link SpaceInvadersLevel}
* extends {@link SpaceInvadersLevel} with aliens that need two hits to be destroyed.
* <ul>
* <li>Hit aliens twice to kill them
* <li>they say AUA when not destroyed

38
GameProject/src/playground/LevelMovingObjects.java

@ -0,0 +1,38 @@
package playground;
import java.awt.Color;
import controller.ReboundController;
import gameobjects.RectObject;
/** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time.
*/
public class LevelMovingObjects extends SpaceInvadersLevel {
/** "Moving Objects Level!" is the message.
*
* @return String "Moving Objects Level!"
*/
@Override
protected String getStartupMessage() {
return "Moving Objects Level!";
}
@Override
public void prepareLevel(String id) {
super.prepareLevel(id);
RectObject ro = new RectObject("ro", this, 300, 300, 170, 70, 30, 30, Color.BLUE);
RectObject roTwo = new RectObject("roTwo", this, 200, 200, 50, 170, 30, 30, Color.GREEN);
ReboundController rc = new ReboundController();
ReboundController rcTwo = new ReboundController();
ro.addController(rc);
roTwo.addController(rcTwo);
this.addObject(ro);
this.addObject(roTwo);
}
}

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

@ -0,0 +1,9 @@
/**
* 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>
*
* Generally, the base class {@link Playground} supports totally different game types to be implemented.
*/
package playground;
Loading…
Cancel
Save