diff --git a/GameProject/src/base/MovingObjectsGame.java b/GameProject/src/base/MovingObjectsGame.java
index 93ec2ad..bb991a7 100644
--- a/GameProject/src/base/MovingObjectsGame.java
+++ b/GameProject/src/base/MovingObjectsGame.java
@@ -20,6 +20,7 @@ public class MovingObjectsGame extends GameLoop {
* @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 {
logger.info("Starting Game Program...let's play and don't get hit!");
GameLoop myGame = new MovingObjectsGame();
diff --git a/GameProject/src/base/MultiLevelGame.java b/GameProject/src/base/MultiLevelGame.java
index 25a9cd4..e49bfde 100644
--- a/GameProject/src/base/MultiLevelGame.java
+++ b/GameProject/src/base/MultiLevelGame.java
@@ -2,14 +2,9 @@
import java.io.IOException;
-import playground.Level1;
-import playground.Level3;
-import playground.Level5;
-import playground.Level6;
-import playground.Level7;
-import playground.LevelBoss;
-import playground.LevelHitTwice;
-import playground.LevelWithBox;
+
+import playground.LevelMovingHitObjects;
+
public class MultiLevelGame extends GameLoop {
@@ -17,10 +12,9 @@ public class MultiLevelGame extends GameLoop {
@Override
void defineLevels() {
- this.addLevel(new LevelWithBox());
- this.addLevel(new Level5());
- this.addLevel(new Level6());
- this.addLevel(new Level7());
+
+
+ this.addLevel(new LevelMovingHitObjects());
}
diff --git a/GameProject/src/controller/ReboundController.java b/GameProject/src/controller/ReboundController.java
new file mode 100644
index 0000000..0fe3cbe
--- /dev/null
+++ b/GameProject/src/controller/ReboundController.java
@@ -0,0 +1,24 @@
+package controller;
+
+public class ReboundController extends ObjectController{
+
+ @Override
+
+ public void updateObject() {
+
+ if (this.getX() < 30 || this.getX() > 670 ) {
+
+ setVX(getVX() * -1) ;
+ }
+
+ if (getY() < 30 || getY() > 670 ) {
+
+ setVY(getVY() * -1) ;
+ }
+ super.applySpeedVector();
+ }
+
+
+
+
+}
diff --git a/GameProject/src/log4j2.xml b/GameProject/src/log4j2.xml
index f21f70a..29c88f1 100644
--- a/GameProject/src/log4j2.xml
+++ b/GameProject/src/log4j2.xml
@@ -20,10 +20,8 @@
-
-
-
+
diff --git a/GameProject/src/playground/LevelMovingHitObjects.java b/GameProject/src/playground/LevelMovingHitObjects.java
index 533b41a..5725ba5 100644
--- a/GameProject/src/playground/LevelMovingHitObjects.java
+++ b/GameProject/src/playground/LevelMovingHitObjects.java
@@ -1,28 +1,71 @@
package playground;
+import java.awt.Color;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import collider.RectCollider;
+import controller.ReboundController;
+import gameobjects.GameObject;
+import gameobjects.RectObject;
/**
* 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
+ public class LevelMovingHitObjects extends SpaceInvadersLevel {
-
- //FIXME add your method overrides here
+ private static Logger logger = LogManager.getLogger(LevelMovingHitObjects.class);
+ @Override
+
+ public void prepareLevel(String id) {
+
+ super.prepareLevel(id);
+ GameObject a = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40 , 40 , Color.blue);
+ this.addObject(a);
+ logger.info("Object added");
+ a.addController(new ReboundController());
+ GameObject b = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40 , 40 , Color.green);
+ this.addObject(b);
+ b.addController(new ReboundController());
+ logger.info("collider added");
+ a.addCollider(new RectCollider("fly_enemy1", a, 40, 40));
+ b.addCollider(new RectCollider("fly_enemy2", b, 40, 40));
+
+ }
+
+ void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
+
+ logger.info("the id contines :eneym:");
+ if (enemy.id.equals("fly_enemy1") || enemy.id.equals("fly_enemy2")) {
+ int NoLives = 0;
+
+ Playground.setGlobalFlag("egoLives", NoLives);
+ logger.info("the game ends");
+ this.lost = true;
+
+ } else {
+
+ super.actionIfEgoCollidesWithEnemy(enemy, ego);
+ }
+ }
+
+
/**
* "Moving Hitting Objects Level!" is the message.
*
* @return String "Moving & Hitting Objects Level!"
*/
+
@Override
+
protected String getStartupMessage() {
return "Moving & Hitting Objects Level!";
}
-
+
}
diff --git a/GameProject/src/playground/LevelMovingObjects.java b/GameProject/src/playground/LevelMovingObjects.java
index dd93acf..6d78406 100644
--- a/GameProject/src/playground/LevelMovingObjects.java
+++ b/GameProject/src/playground/LevelMovingObjects.java
@@ -1,19 +1,36 @@
package playground;
+import java.awt.Color;
+import controller.ReboundController;
+import gameobjects.GameObject;
+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 {
- // TODO your code here
-
+
+ @Override
+
+ public void prepareLevel(String id) {
+ super.prepareLevel(id);
+ GameObject o = new RectObject("blue", this, 300, 300, 170, 70, 30 , 30 , Color.blue);
+ this.addObject(o);
+ o.addController(new ReboundController());
+
+ }
+
+
+
/** "Moving Objects Level!" is the message.
*
* @return String "Moving Objects Level!"
*/
+
@Override
+
protected String getStartupMessage() {
return "Moving Objects Level!";
}