Keep speed of ball when hitting sticky paddle

This commit is contained in:
Matt Low 2018-11-12 11:18:26 +04:00
parent a736229c18
commit 88428fded9

View File

@ -36,7 +36,7 @@ public class Ball extends Entity {
@Override @Override
public void update(float dt) { public void update(float dt) {
if (!getBrickBuster().isPlaying()) { if (!getBrickBuster().isPlaying() || isStuck()) {
return; return;
} }
@ -82,6 +82,9 @@ public class Ball extends Entity {
if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) { if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) {
paddleCollision(); paddleCollision();
if (getBrickBuster().getPaddle().isSticky()) {
return;
}
} }
} }
@ -98,18 +101,17 @@ public class Ball extends Entity {
public void launch() { public void launch() {
if (getBrickBuster().getPaddle().isSticky()) { if (getBrickBuster().getPaddle().isSticky()) {
direction = paddleReflectAngle(); direction = paddleReflectAngle();
isStuck = false;
} else { } else {
float angle = MathUtils.random(MathUtils.PI/2) + MathUtils.PI/4; float angle = MathUtils.random(MathUtils.PI/2) + MathUtils.PI/4;
direction = new Vector2(MathUtils.cos(angle), MathUtils.sin(angle)); direction = new Vector2(MathUtils.cos(angle), MathUtils.sin(angle));
speed = DEFAULT_SPEED; speed = DEFAULT_SPEED;
} }
isStuck = false;
} }
public void paddleCollision() { public void paddleCollision() {
Paddle paddle = getBrickBuster().getPaddle(); Paddle paddle = getBrickBuster().getPaddle();
if (paddle.isSticky()) { if (paddle.isSticky()) {
speed = 0;
isStuck = true; isStuck = true;
setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS); setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS);
return; return;