Compare commits

..

No commits in common. "0a071e40d2146ae1131ca82ab5a78a8361d8c28f" and "5756c9077cd700d2a9472d4bd04e9ebecf6cf575" have entirely different histories.

4 changed files with 12 additions and 32 deletions

View File

@ -45,12 +45,12 @@ public class BrickBuster extends ApplicationAdapter {
Gdx.gl.glClearColor(0.5f,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ball.render();
paddle.render();
for (Block block : blocks) {
block.render();
}
ball.render();
paddle.render();
}
public void update(float dt) {

View File

@ -1,6 +1,5 @@
package com.me.brickbuster;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
public class Utils {
@ -10,11 +9,4 @@ public class Utils {
return incoming.sub(normal.scl(normal.dot(incoming) * 2));
}
public static Vector2 nearestPoint(Vector2 linep1, Vector2 lineDir, Vector2 p1) {
float lineLen = lineDir.len();
lineDir.nor();
Vector2 ballDir = p1.sub(linep1);
return linep1.add(lineDir.nor().scl(MathUtils.clamp(ballDir.dot(lineDir), 0, lineLen)));
}
}

View File

@ -6,7 +6,6 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.me.brickbuster.BrickBuster;
import com.me.brickbuster.Utils;
import net.dermetfan.utils.Pair;
public class Ball extends Entity {
@ -34,8 +33,8 @@ public class Ball extends Entity {
return;
}
float newX = getX() + (direction.x * speed);
float newY = getY() + (direction.y * speed);
int newX = getX() + (int) (direction.x * speed);
int newY = getY() + (int) (direction.y * speed);
if (newX + RADIUS > BrickBuster.WIDTH || newX - RADIUS < 0) {
Utils.reflect(direction, BrickBuster.VERTICAL_EDGE);
@ -45,19 +44,8 @@ public class Ball extends Entity {
reset();
}
if (direction.y < 0) {
Pair<Vector2, Vector2> paddle = getBrickBuster().getPaddle().getTopEdge();
Vector2 ball = new Vector2(newX, newY);
Vector2 lineDir = paddle.getValue().sub(paddle.getKey());
Vector2 nearest = Utils.nearestPoint(paddle.getKey().cpy(), lineDir, ball.cpy());
if (nearest.dst(newX, newY) < RADIUS) {
Utils.reflect(direction, lineDir.nor());
}
}
setX(getX() + (direction.x * speed));
setY(getY() + (direction.y * speed));
setX(getX() + (int) (direction.x * speed));
setY(getY() + (int) (direction.y * speed));
}
public void launch() {

View File

@ -7,7 +7,7 @@ public abstract class Entity {
private ShapeRenderer shapeRenderer;
private BrickBuster brickBuster;
private float x, y;
private int x, y;
public Entity(BrickBuster brickBuster, int x, int y) {
this.shapeRenderer = new ShapeRenderer();
@ -28,19 +28,19 @@ public abstract class Entity {
return shapeRenderer;
}
public float getX() {
public int getX() {
return x;
}
public void setX(float x) {
public void setX(int x) {
this.x = x;
}
public float getY() {
public int getY() {
return y;
}
public void setY(float y) {
public void setY(int y) {
this.y = y;
}