From 2a27f7484646991e1d9877bda6e50d8fdacf0780 Mon Sep 17 00:00:00 2001 From: rxbn_ Date: Tue, 4 Feb 2020 21:24:35 +0100 Subject: [PATCH] BreakOut 5 - reset direction --- src/break_out/model/Ball.java | 16 ++++++++++++---- src/break_out/model/Level.java | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/break_out/model/Ball.java b/src/break_out/model/Ball.java index 913fc39..de7dd6f 100644 --- a/src/break_out/model/Ball.java +++ b/src/break_out/model/Ball.java @@ -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(); + } + } diff --git a/src/break_out/model/Level.java b/src/break_out/model/Level.java index 8687fae..ef78201 100644 --- a/src/break_out/model/Level.java +++ b/src/break_out/model/Level.java @@ -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