diff --git a/GameProject/src/base/MovingObjectsGame.java b/GameProject/src/base/MovingObjectsGame.java index ab52fec..2c274fa 100644 --- a/GameProject/src/base/MovingObjectsGame.java +++ b/GameProject/src/base/MovingObjectsGame.java @@ -1,4 +1,4 @@ -package base; + package base; import java.io.IOException; import playground.LevelMovingObjects; diff --git a/GameProject/src/controller/ReboundController.java b/GameProject/src/controller/ReboundController.java new file mode 100644 index 0000000..332b248 --- /dev/null +++ b/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(); + + + } + +} diff --git a/GameProject/src/playground/LevelMovingObjects.java b/GameProject/src/playground/LevelMovingObjects.java index dd93acf..82fcfbd 100644 --- a/GameProject/src/playground/LevelMovingObjects.java +++ b/GameProject/src/playground/LevelMovingObjects.java @@ -1,13 +1,14 @@ 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 { - // TODO your code here - /** "Moving Objects Level!" is the message. * @@ -17,5 +18,21 @@ public class LevelMovingObjects extends SpaceInvadersLevel { 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); + } + + + + }