diff --git a/GameProject/src/controller/ReboundController.java b/GameProject/src/controller/ReboundController.java index fcbae09..36113e1 100644 --- a/GameProject/src/controller/ReboundController.java +++ b/GameProject/src/controller/ReboundController.java @@ -4,15 +4,12 @@ public class ReboundController extends ObjectController{ @Override public void updateObject() { - if(this.gameObject.getX() < 30 && this.gameObject.getX() > 670) { - double vx = this.gameObject.getX(); - this.gameObject.setVX(vx * -1); - } else if (this.gameObject.getY() < 30 && this.gameObject.getY() > 670) { - double vy = this.gameObject.getX(); - this.gameObject.setVX(vy * -1); + if(this.gameObject.getX() < 30 || this.gameObject.getX() > 670) { + this.gameObject.setVX(getVX() * -1); + } else if (this.gameObject.getY() < 30 || this.gameObject.getY() > 670) { + this.gameObject.setVY(getVY() * -1); } - - + applySpeedVector(); } } diff --git a/GameProject/src/playground/LevelMovingObjects.java b/GameProject/src/playground/LevelMovingObjects.java index 9783e96..21c003b 100644 --- a/GameProject/src/playground/LevelMovingObjects.java +++ b/GameProject/src/playground/LevelMovingObjects.java @@ -2,6 +2,8 @@ package playground; import java.awt.Color; +import controller.ObjectController; +import controller.ReboundController; import gameobjects.RectObject; /** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time. @@ -11,8 +13,10 @@ public class LevelMovingObjects extends SpaceInvadersLevel { public void prepareLevel(String id) { super.prepareLevel(id); LevelMovingObjects ml = this; - RectObject object2 = new RectObject(id +"Bluebox",ml,300,300,170,70,30,30,Color.BLUE); - this.addObject(object2); + RectObject blueBox = new RectObject(id +"Bluebox",ml,300,300,170,70,30,30,Color.BLUE); + this.addObject(blueBox); + ObjectController rb = new ReboundController(); + blueBox.addController(rb); }