Browse Source

aktualisierung konertversion

konertversion
fdai7222 2 years ago
parent
commit
059c032bee
  1. 7
      spaceinvaders/GameProject/.classpath
  2. 4
      spaceinvaders/GameProject/src/base/GameLoop.java
  3. 33
      spaceinvaders/GameProject/src/base/MovingObjectsGame.java
  4. 9
      spaceinvaders/GameProject/src/collider/package-info.java
  5. 14
      spaceinvaders/GameProject/src/controller/CollisionAwareEgoController.java
  6. 46
      spaceinvaders/GameProject/src/controller/EgoController.java
  7. 2
      spaceinvaders/GameProject/src/controller/ObjectController.java
  8. 7
      spaceinvaders/GameProject/src/gameobjects/package-info.java
  9. 2
      spaceinvaders/GameProject/src/log4j2.xml
  10. 2
      spaceinvaders/GameProject/src/playground/Level2.java
  11. 4
      spaceinvaders/GameProject/src/playground/Level4.java
  12. 21
      spaceinvaders/GameProject/src/playground/LevelMovingObjects.java
  13. 2
      spaceinvaders/GameProject/src/playground/SpaceInvadersLevel.java
  14. 9
      spaceinvaders/GameProject/src/playground/package-info.java

7
spaceinvaders/GameProject/.classpath

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/apache-log4j-2.13.3-bin/log4j-1.2-api-2.13.3.jar"/>
<classpathentry kind="lib" path="lib/apache-log4j-2.13.3-bin/log4j-api-2.13.3.jar"/>
<classpathentry kind="lib" path="lib/apache-log4j-2.13.3-bin/log4j-core-2.13.3.jar"/>

4
spaceinvaders/GameProject/src/base/GameLoop.java

@ -217,8 +217,8 @@ public class GameLoop {
/**
* main to start the whole application.
* initializes the {@link #levels} ArrayList of Playground instances (levels) to be played with one level {@link SpaceInvadersLevel} in constructor of {@link #GameLoop}.
* main to start the whole application. It calls. {@link #runGame(String[])}.
* (levels are automatically added/loaded by constructor of {@link #GameLoop}).
*
* @param args Java default command line args, forwarded to {@link #runGame(String[])}
* @throws IOException in case highscore.txt cannot be written.

33
spaceinvaders/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
spaceinvaders/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;

14
spaceinvaders/GameProject/src/controller/CollisionAwareEgoController.java

@ -37,6 +37,9 @@ public class CollisionAwareEgoController extends EgoController {
this.shot = soundOnShot;
}
/**
* Copies current values of x,y position and speed vx,vy into attributes. These can be restored by call to {@link #restoreDynamicState()}.
*/
public void saveDynamicState() {
this.savex = this.getX();
this.savey = this.getY();
@ -45,6 +48,10 @@ public class CollisionAwareEgoController extends EgoController {
}
/**
* Restores formally saved values of x,y position and speed vx,vy from attributes back to the ego object.
* These values should have been stored before by a call to {@link #saveDynamicState()}, otherwise all values will be 0.00.
*/
public void restoreDynamicState() {
this.setX(savex);
this.setY(savey);
@ -53,6 +60,10 @@ public class CollisionAwareEgoController extends EgoController {
}
/**
* extends parent class implementation by a check whether or not the ego object collides with any other "obstacle" object.
* If yes, the position stays fixed (by using {@link #saveDynamicState()} and {@link #restoreDynamicState()}.
*/
public boolean stopObject() {
boolean s = super.stopObject();
@ -73,6 +84,9 @@ public class CollisionAwareEgoController extends EgoController {
return s;
}
/**
* calls superclass {@link EgoController#onSpace(KeyEvent, GameObject)} only, if the time elapsed since last pressing of space is above 0.1 ms.
*/
public void onSpace(KeyEvent e, GameObject ego) {
double cgt = ego.getGameTime();
if ((cgt - this.lastSpaceAt) > 0.1) {

46
spaceinvaders/GameProject/src/controller/EgoController.java

@ -42,26 +42,51 @@ public class EgoController extends ObjectController {
}
/**
* moves ego up by {@link SpaceInvadersLevel#EGOSPEED}.
* @param kc KeyEvent to process (ignored)
* @param ego the ego object
*/
public void onUp(KeyEvent kc, GameObject ego) {
ego.setVX(0.0);
ego.setVY(-SpaceInvadersLevel.EGOSPEED);
}
/**
* moves ego down by {@link SpaceInvadersLevel#EGOSPEED}.
* @param kc KeyEvent to process (ignored)
* @param ego the ego object
*/
public void onDown(KeyEvent kc, GameObject ego) {
ego.setVX(0.0);
ego.setVY(SpaceInvadersLevel.EGOSPEED);
}
/**
* moves ego left by {@link SpaceInvadersLevel#EGOSPEED}.
* @param kc KeyEvent to process (ignored)
* @param ego the ego object
*/
public void onLeft(KeyEvent kc, GameObject ego) {
ego.setVY(0.0);
ego.setVX(-SpaceInvadersLevel.EGOSPEED);
}
/**
* moves ego right by {@link SpaceInvadersLevel#EGOSPEED}.
* @param kc KeyEvent to process (ignored)
* @param ego the ego object
*/
public void onRight(KeyEvent kc, GameObject ego) {
ego.setVY(0.0);
ego.setVX(SpaceInvadersLevel.EGOSPEED);
}
/**
* sets speed to 0.0
* @param kc KeyEvent to process (ignored)
* @param ego the ego object
*/
public void onStop(KeyEvent kc, GameObject ego) {
ego.setVY(0.0);
ego.setVX(0.0);
@ -72,7 +97,7 @@ public class EgoController extends ObjectController {
/** checks the position and respects level boundaries and own radius or width/height set on constructor.
*
* @return true if the object reached the boundaries of the level, false otherwise
* @return true if the object reached the boundaries of the level, false otherwise.
*/
public boolean stopObject() {
// check whether ego object is at level boundaries
@ -93,7 +118,7 @@ public class EgoController extends ObjectController {
}
/** behavior for shooting on key space
/** behavior for shooting on key space. Creates a new shot using {#link SimpleShotController} with a {@link RectObject}.
*
* @param e KeyEvent of the space key
* @param ego EgoObject instance (used to determine position of shot object's start)
@ -119,7 +144,7 @@ public class EgoController extends ObjectController {
/**
* updates position based on key events (mouse currently ignored)
* updates position based on key events (mouse currently ignored).
*/
public void updateObject() {
@ -140,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) {
@ -194,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
spaceinvaders/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);
}

7
spaceinvaders/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
spaceinvaders/GameProject/src/log4j2.xml

@ -7,7 +7,7 @@
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" />
</Console>
<File name="File" fileName="log\log4j.log">
<File name="File" fileName="log/log4j.log">
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" />
</File>

2
spaceinvaders/GameProject/src/playground/Level2.java

@ -3,7 +3,7 @@ package playground;
/**
* extends extends {@link SpaceInvadersLevel} with a different startup message.
* extends {@link SpaceInvadersLevel} with a different startup message.
*/
public class Level2 extends SpaceInvadersLevel {

4
spaceinvaders/GameProject/src/playground/Level4.java

@ -10,14 +10,14 @@ import org.apache.logging.log4j.Logger;
/**
* extends 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
* </ul>
*/
public class Level4 extends SpaceInvadersLevel {
/** constant defining the number of shots needed to destroy an enemy */
public static final int MAX_HITS = 2;

21
spaceinvaders/GameProject/src/playground/LevelMovingObjects.java

@ -0,0 +1,21 @@
package playground;
/** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time.
*/
public class LevelMovingObjects extends SpaceInvadersLevel {
// TODO your code here
/** "Moving Objects Level!" is the message.
*
* @return String "Moving Objects Level!"
*/
@Override
protected String getStartupMessage() {
return "Moving Objects Level!";
}
}

2
spaceinvaders/GameProject/src/playground/SpaceInvadersLevel.java

@ -78,7 +78,7 @@ public class SpaceInvadersLevel extends Playground {
protected Animation enemyAnim = null;
protected Animation heartAnim = null;
protected static Logger logger = LogManager.getLogger(SpaceInvadersLevel.class);
private static Logger logger = LogManager.getLogger(SpaceInvadersLevel.class);
public SpaceInvadersLevel() {
super();

9
spaceinvaders/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