You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
961 B
35 lines
961 B
package controller;
|
|
|
|
/** Controller to let Objects bounce from the outer level limits back and forth.
|
|
*
|
|
*/
|
|
public class ReboundController2 extends ObjectController {
|
|
|
|
/** inverts the x y direction speeds if the outer limits are reached.
|
|
*
|
|
*/
|
|
@Override
|
|
public void updateObject() {
|
|
double sizeX = this.getPlayground().preferredSizeX();
|
|
double sizeY = this.getPlayground().preferredSizeY();
|
|
double objSizeX = 30;
|
|
double objSizeY = 30;
|
|
|
|
if (this.getX() < objSizeX) {
|
|
this.setVX(this.getVX() * -1);
|
|
this.setX(objSizeX);
|
|
} else if (this.getX() > sizeX - objSizeX) {
|
|
this.setVX(this.getVX() * -1);
|
|
this.setX(sizeX - objSizeX);
|
|
}
|
|
if (this.getY() < objSizeY) {
|
|
this.setVY(this.getVY() * -1);
|
|
this.setY(objSizeY);
|
|
} else if (this.getY() > sizeY - objSizeY) {
|
|
this.setVY(this.getVY() * -1);
|
|
this.setY(sizeY - objSizeY);
|
|
}
|
|
this.applySpeedVector();
|
|
}
|
|
|
|
}
|