I want to do really simple collision detection in a pong like game. The ball is a square and the paddle (bats) is rectangles.
I have two entities coming in where I can get the current X and Y position, and the bitmap height and width. Which is the simplest way to do this?
I have this code:
public void getCollision(Entity enitityOne, Entity enitityTwo){
double eventCoordX = (enitityOne.getCenterX() - (enitityTwo.getBitmapWidth() / 2));
double eventCoordY = (enitityOne.getCenterY() - (enitityTwo.getBitmapHeight() / 2));
double X = Math.abs(enitityTwo.getxPos() - eventCoordX);
double Y = Math.abs(enitityTwo.getyPos() - eventCoordY);
if(X <= (enitityTwo.getBitmapWidth()) && Y <= (enitityTwo.getBitmapHeight())){
enitityOne.collision();
enitityTwo.collision();
}
}
But I'm pretty blind, this only works in the middle of the paddle not on the sides. The problem is I can't see where the code is wrong. Anybody? Anybody have a better idea?