Rename ball -> new_pos
Fix paddle reset
This commit is contained in:
		@ -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<Brick> 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<Vector2, Vector2> 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() {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user