Browse Source

Added MovingObjectsGame with LevelMovingObjects. Two Mowing Boxes inserted into Game.

master
fdai7303 3 years ago
parent
commit
f622b8991f
  1. 16
      GameProject/src/controller/ReboundController.java
  2. 19
      GameProject/src/playground/LevelMovingObjects.java

16
GameProject/src/controller/ReboundController.java

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

19
GameProject/src/playground/LevelMovingObjects.java

@ -1,6 +1,8 @@
package playground; package playground;
import java.awt.Color;
import gameobjects.RectObject;
/** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time. /** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time.
*/ */
@ -17,5 +19,22 @@ public class LevelMovingObjects extends SpaceInvadersLevel {
protected String getStartupMessage() { protected String getStartupMessage() {
return "Moving Objects Level!"; return "Moving Objects Level!";
} }
/** Prepares Level for LevelMovingObjects.
* Adds a BlueBox & PinkBox in Level.
*
* @param String id LevelID
*/
@Override
public void prepareLevel(String id) {
super.prepareLevel(id);
RectObject BlueBox = new RectObject("BlueBox", this, 300, 300, 170, 70, 30, 30, Color.BLUE);
this.addObject(BlueBox);
BlueBox.addController(new controller.ReboundController());
RectObject PinkBox = new RectObject("PinkBox", this, 200, 200, 50, 170, 30, 30, Color.PINK);
this.addObject(PinkBox);
PinkBox.addController(new controller.ReboundController());
}
} }
Loading…
Cancel
Save