From 353afe1cee8d0d5dd72d12c786b55d856125a6d4 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 11 Nov 2018 21:53:18 +0400 Subject: [PATCH] Update velocity based on time delta --- core/src/com/me/brickbuster/entity/Ball.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index c2c721c..a074fa8 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -16,7 +16,7 @@ public class Ball extends Entity { public static final Color BALL_COLOR = Color.CHARTREUSE; public Vector2 direction; - public float speed; + public float speed = 300; public Ball(BrickBuster brickBuster) { super(brickBuster,BrickBuster.WIDTH/2, Paddle.PADDLE_Y + Paddle.PADDLE_HEIGHT + RADIUS); @@ -36,7 +36,7 @@ public class Ball extends Entity { return; } - Vector2 new_pos = getPos().cpy().add(direction.cpy().scl(speed)); + Vector2 new_pos = getPos().cpy().add(direction.cpy().scl(speed * dt)); boolean brick_collision = false; Iterator brickIterator = getBrickBuster().getBricks().iterator(); @@ -52,7 +52,7 @@ public class Ball extends Entity { if (nearest.dst(new_pos.x, new_pos.y) <= RADIUS) { brickIterator.remove(); if (getBrickBuster().getBricks().size() <= 39) { - speed = 8; + speed = 450; } Utils.reflect(direction, segment.nor()); brick_collision = true; @@ -80,13 +80,12 @@ public class Ball extends Entity { } } - getPos().add(direction.cpy().scl(speed)); + getPos().add(direction.cpy().scl(speed * dt)); } public void launch() { float angle = MathUtils.random(MathUtils.PI/2) + MathUtils.PI/4; direction = new Vector2(MathUtils.cos(angle), MathUtils.sin(angle)); - speed = 5; } public void paddleCollision() {