I am using a game engine from Beginning Android Games and making a breakout game from scratch. I have the paddle/ball/bricks working but right now I am working out the bugs. Randomly, my pong will hit any wall and it will just stick to it and vibrate left and right and kind of just fly off the screen. Another example is sometimes the pong hits the paddle in such a way that instead of bouncing off of it, it goes through it and then proceeds to change direction after it goes through it, I feel like its not obeying my bounds. I am testing on a nexus 7 here is the pong class
public class Pong {
public float x, y;
public int speedX, speedY;
public static final int LEFT = 0;
public static final int RIGHT = 0;
public static final int WIDTH = 32;
public static final int HEIGHT = 32;
public static final int DIAMETER = 15;
public int direction;
public boolean inBounds;
public Pong(int x, int y) {
this.x = x;
this.y = y;
speedX = 500;
speedY = 500;
inBounds = true;
}
public void stop() {
speedX = 0;
speedY = 0;
}
public void update(float deltaTime) {
if (inBounds) {
x += speedX * deltaTime;
y += speedY * deltaTime;
if (x + WIDTH >= 800) {
speedX *= -1;
}
if (x <= 0) {
speedX *= -1;
}
if (y >= 1280) {
// inBounds = false;
speedY *= -1;
}
if (y <= 0) {
speedY *= -1;
}
}
}
public void reverse() {
speedY *= -1;
}
}
my paddle class
public class Paddle {
public static final int LEFT = 0;
public static final int RIGHT = 1;
public static final int NEUTRAL = 2;
public static final int WIDTH = 192;
public static final int HEIGHT = 32;
public float x;
public int y;
public int speed;
public int direction;
public Paddle(int x, int y) {
this.x = x;
this.y = y;
}
public void turnLeft() {
speed = 500;
direction = LEFT;
}
public void turnRight() {
speed = 500;
direction = RIGHT;
}
public void stop() {
speed = 0;
}
public void update(float deltaTime) {
if (direction == LEFT && x > 0) {
x -= speed * deltaTime;
} else if (direction == RIGHT && x + WIDTH < 800) {
x += speed * deltaTime;
} else if (direction == NEUTRAL) {
stop();
}
}
}
and the collision detection I made which is probably wrong
private boolean paddleCollision(Paddle paddle, Pong pong) {
if (pong.x <= paddle.x + Paddle.WIDTH) {
if (pong.x >= paddle.x) {
if (pong.y + Pong.HEIGHT >= paddle.y) {
return true;
}
}
}
return false;
}
private boolean tileCollision(Tile tile, Pong pong) {
if (tile == null) {
return false;
}
if (pong.x <= tile.x + Tile.WIDTH) {
if (pong.x >= tile.x) {
if (pong.y <= tile.y + Tile.HEIGHT) {
if (pong.y + Pong.HEIGHT >= tile.y) {
return true;
}
}
}
}
return false;
}