1
0
Fork 0

BreakOut 5 - reset direction

This commit is contained in:
rxbn_ 2020-02-04 21:24:35 +01:00
parent 5a5d661719
commit 2a27f74846
2 changed files with 13 additions and 4 deletions

View File

@ -49,8 +49,9 @@ public class Ball implements IBall {
*/ */
public Ball() { public Ball() {
this.position = new Position(0, 0); this.position = new Position(0, 0);
this.direction = new Vector2D(Constants.BALL_SPEED, Constants.BALL_SPEED);
this.direction.rescale(); // reset direction
resetDirection();
// reset position to bottom-center // reset position to bottom-center
resetPosition(); resetPosition();
@ -97,8 +98,7 @@ public class Ball implements IBall {
Random random = new Random(); Random random = new Random();
// random hue without blue colors to prevent ghosting // random hue without blue colors to prevent ghosting
// 65 <~ 170/255 float hue = (random.nextInt(200)+50) / 360f;
float hue = (random.nextInt(65)) / 100f;
// saturation between 0.5 and 0.7 // saturation between 0.5 and 0.7
float saturation = (random.nextInt(2000) + 5000) / 10000f; float saturation = (random.nextInt(2000) + 5000) / 10000f;
@ -396,4 +396,12 @@ public class Ball implements IBall {
position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER - Constants.PADDLE_HEIGHT); position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER - Constants.PADDLE_HEIGHT);
} }
/**
* resets balls direction
*/
public void resetDirection() {
direction = new Vector2D(Constants.BALL_SPEED, Constants.BALL_SPEED);
direction.rescale();
}
} }

View File

@ -296,6 +296,7 @@ public class Level extends Thread implements ILevel {
if(lifeCounter > 0) { if(lifeCounter > 0) {
resetPaddles(); resetPaddles();
getBall().resetPosition(); getBall().resetPosition();
getBall().resetDirection();
getBall().setLost(false); getBall().setLost(false);
stopBall(); stopBall();
// level failed // level failed