Keep speed of ball when hitting sticky paddle
This commit is contained in:
parent
a736229c18
commit
88428fded9
@ -36,7 +36,7 @@ public class Ball extends Entity {
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
if (!getBrickBuster().isPlaying()) {
|
||||
if (!getBrickBuster().isPlaying() || isStuck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,6 +82,9 @@ public class Ball extends Entity {
|
||||
|
||||
if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) {
|
||||
paddleCollision();
|
||||
if (getBrickBuster().getPaddle().isSticky()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,18 +101,17 @@ public class Ball extends Entity {
|
||||
public void launch() {
|
||||
if (getBrickBuster().getPaddle().isSticky()) {
|
||||
direction = paddleReflectAngle();
|
||||
isStuck = false;
|
||||
} else {
|
||||
float angle = MathUtils.random(MathUtils.PI/2) + MathUtils.PI/4;
|
||||
direction = new Vector2(MathUtils.cos(angle), MathUtils.sin(angle));
|
||||
speed = DEFAULT_SPEED;
|
||||
}
|
||||
isStuck = false;
|
||||
}
|
||||
|
||||
public void paddleCollision() {
|
||||
Paddle paddle = getBrickBuster().getPaddle();
|
||||
if (paddle.isSticky()) {
|
||||
speed = 0;
|
||||
isStuck = true;
|
||||
setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user