jkonert
3 years ago
4 changed files with 71 additions and 3 deletions
-
9GameProject/src/base/MovingObjectsGame.java
-
35GameProject/src/controller/ReboundController2.java
-
28GameProject/src/playground/LevelMovingHitObjects.java
@ -0,0 +1,35 @@ |
|||
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(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package playground; |
|||
|
|||
|
|||
/** |
|||
* Level that creates two RectObjects moving around and if ego is hit by them game is directly lost |
|||
* (lives = 0). |
|||
* |
|||
*/ |
|||
public class LevelMovingHitObjects extends SpaceInvadersLevel { |
|||
|
|||
// FIXME add logger here |
|||
|
|||
|
|||
//FIXME add your method overrides here |
|||
|
|||
|
|||
|
|||
/** |
|||
* "Moving Hitting Objects Level!" is the message. |
|||
* |
|||
* @return String "Moving & Hitting Objects Level!" |
|||
*/ |
|||
@Override |
|||
protected String getStartupMessage() { |
|||
return "Moving & Hitting Objects Level!"; |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue