Proper paddle collision, and slowed down the paddle
This commit is contained in:
parent
0a071e40d2
commit
053ec9829f
@ -52,7 +52,7 @@ public class Ball extends Entity {
|
|||||||
Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, ball.cpy());
|
Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, ball.cpy());
|
||||||
|
|
||||||
if (nearest.dst(newX, newY) < RADIUS) {
|
if (nearest.dst(newX, newY) < RADIUS) {
|
||||||
Utils.reflect(direction, lineDir.nor());
|
paddleCollision();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +66,13 @@ public class Ball extends Entity {
|
|||||||
speed = 5;
|
speed = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void paddleCollision() {
|
||||||
|
float paddleCenter = getBrickBuster().getPaddle().getX() + Paddle.PADDLE_WIDTH/2;
|
||||||
|
float rel = (getX() - paddleCenter) + 50;
|
||||||
|
float newAngle = MathUtils.PI - (MathUtils.PI * (rel/100));
|
||||||
|
direction = new Vector2(MathUtils.cos(newAngle), MathUtils.sin(newAngle));
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
setX(getBrickBuster().getPaddle().getX() + Paddle.PADDLE_WIDTH/2);
|
setX(getBrickBuster().getPaddle().getX() + Paddle.PADDLE_WIDTH/2);
|
||||||
setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS);
|
setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS);
|
||||||
|
@ -14,7 +14,7 @@ public class Paddle extends Entity {
|
|||||||
public static final int PADDLE_WIDTH = 100;
|
public static final int PADDLE_WIDTH = 100;
|
||||||
public static final int PADDLE_HEIGHT = 10;
|
public static final int PADDLE_HEIGHT = 10;
|
||||||
public static final int PADDLE_Y = 15;
|
public static final int PADDLE_Y = 15;
|
||||||
public static final int PADDLE_SPEED = 10;
|
public static final int PADDLE_SPEED = 6;
|
||||||
|
|
||||||
public Paddle(BrickBuster brickBuster) {
|
public Paddle(BrickBuster brickBuster) {
|
||||||
super(brickBuster, BrickBuster.WIDTH / 2 - PADDLE_WIDTH / 2, PADDLE_Y);
|
super(brickBuster, BrickBuster.WIDTH / 2 - PADDLE_WIDTH / 2, PADDLE_Y);
|
||||||
|
Loading…
Reference in New Issue
Block a user