From 78d0a7221781348d18d3afdd00575ce0d2d17799 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 11 Nov 2018 21:25:09 +0400 Subject: [PATCH] Rename ball -> new_pos Fix paddle reset --- core/src/com/me/brickbuster/entity/Ball.java | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index b616fad..9768613 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -26,7 +26,7 @@ public class Ball extends Entity { public void render() { getShapeRenderer().begin(ShapeType.Filled); getShapeRenderer().setColor(BALL_COLOR); - getShapeRenderer().circle(getX(), getY(), RADIUS); + getShapeRenderer().circle(getPos().x, getPos().y, RADIUS); getShapeRenderer().end(); } @@ -36,7 +36,7 @@ public class Ball extends Entity { return; } - Vector2 ball = getPos().cpy().add(direction.cpy().scl(speed)); + Vector2 new_pos = getPos().cpy().add(direction.cpy().scl(speed)); boolean brick_collision = false; Iterator brickIterator = getBrickBuster().getBricks().iterator(); @@ -47,9 +47,9 @@ public class Ball extends Entity { Vector2 v1 = vertices[i]; Vector2 v2 = vertices[i+1 < vertices.length? i+1 : 0]; Vector2 segment = v2.cpy().sub(v1); - Vector2 nearest = Utils.nearestPoint(v1.cpy(), segment, ball.cpy()); + Vector2 nearest = Utils.nearestPoint(v1.cpy(), segment, new_pos.cpy()); - if (nearest.dst(ball.x, ball.y) <= RADIUS) { + if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) { brickIterator.remove(); Utils.reflect(direction, segment.nor()); brick_collision = true; @@ -58,25 +58,26 @@ public class Ball extends Entity { } } - if (ball.x + RADIUS > BrickBuster.WIDTH || ball.x - RADIUS < 0) { + if (new_pos.x + RADIUS > BrickBuster.WIDTH || new_pos.x - RADIUS < 0) { Utils.reflect(direction, BrickBuster.VERTICAL_EDGE); - } else if (ball.y + RADIUS > BrickBuster.HEIGHT) { + } else if (new_pos.y + RADIUS > BrickBuster.HEIGHT) { Utils.reflect(direction, BrickBuster.HORIZONTAL_EDGE); - } else if (ball.y - RADIUS < 0) { + } else if (new_pos.y - RADIUS < 0) { reset(); + return; } if (direction.y < 0) { Pair paddle = getBrickBuster().getPaddle().getTopEdge(); Vector2 lineDir = paddle.getValue().sub(paddle.getKey()); - Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, ball.cpy()); + Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, new_pos.cpy()); - if (nearest.dst(ball.x, ball.y) <= RADIUS) { + if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) { paddleCollision(); } } - setPos(ball); + getPos().add(direction.cpy().scl(speed)); } public void launch() {