Proper paddle collision, and slowed down the paddle

This commit is contained in:
BlueNutterfly 2018-11-11 18:44:43 +04:00
parent 0a071e40d2
commit 053ec9829f
2 changed files with 9 additions and 2 deletions

View File

@ -52,7 +52,7 @@ public class Ball extends Entity {
Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, ball.cpy());
if (nearest.dst(newX, newY) < RADIUS) {
Utils.reflect(direction, lineDir.nor());
paddleCollision();
}
}
@ -66,6 +66,13 @@ public class Ball extends Entity {
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() {
setX(getBrickBuster().getPaddle().getX() + Paddle.PADDLE_WIDTH/2);
setY(Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS);

View File

@ -14,7 +14,7 @@ public class Paddle extends Entity {
public static final int PADDLE_WIDTH = 100;
public static final int PADDLE_HEIGHT = 10;
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) {
super(brickBuster, BrickBuster.WIDTH / 2 - PADDLE_WIDTH / 2, PADDLE_Y);