1
0
Fork 0

BreakOut 5 - reset direction

master A5.1
rxbn_ 3 years ago
parent 5a5d661719
commit 2a27f74846

@ -49,8 +49,9 @@ public class Ball implements IBall {
*/
public Ball() {
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
resetPosition();
@ -97,8 +98,7 @@ public class Ball implements IBall {
Random random = new Random();
// random hue without blue colors to prevent ghosting
// 65 <~ 170/255
float hue = (random.nextInt(65)) / 100f;
float hue = (random.nextInt(200)+50) / 360f;
// saturation between 0.5 and 0.7
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);
}
/**
* resets balls direction
*/
public void resetDirection() {
direction = new Vector2D(Constants.BALL_SPEED, Constants.BALL_SPEED);
direction.rescale();
}
}

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

Loading…
Cancel
Save