Browse Source

Hausaufgabe 5

main
Manu 2 years ago
parent
commit
b105f7d19e
  1. 13
      GameProject/src/controller/ReboundController.java
  2. 8
      GameProject/src/playground/LevelMovingObjects.java

13
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();
}
}

8
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);
}

Loading…
Cancel
Save