From 053ec9829f7608784d903bba11ef0053091a717d Mon Sep 17 00:00:00 2001 From: BlueNutterfly Date: Sun, 11 Nov 2018 18:44:43 +0400 Subject: [PATCH] Proper paddle collision, and slowed down the paddle --- core/src/com/me/brickbuster/entity/Ball.java | 9 ++++++++- core/src/com/me/brickbuster/entity/Paddle.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index 56a0c94..7a5f2d7 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -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); diff --git a/core/src/com/me/brickbuster/entity/Paddle.java b/core/src/com/me/brickbuster/entity/Paddle.java index 52b6585..5b1a923 100644 --- a/core/src/com/me/brickbuster/entity/Paddle.java +++ b/core/src/com/me/brickbuster/entity/Paddle.java @@ -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);