Hi all,
I'm almost done with the beta version of my game and just need a few things ironed out. I'm having problems getting collision detection working with my game. In my game the objects have getBounds() methods as so:
1
| public Rectangle getBounds() { return (new Rectangle(getX(), getY(), getWidth(), getHeight())); } |
Then inside my game loop i call:
1 2 3 4 5
| public void run() { ... checkCollisions(); } |
of which the body of the method is:
1 2 3 4 5 6 7 8 9
| public final void checkCollisions() { if(ball.getBounds().contains(paddle.getX(), paddle.getY())) { ball.setY(50);
ball.setVY(-ball.getVY()); } } |
What's weirder is the collision detection seems to return random values as sometimes the ball will collide with the paddle, and sometimes it will just go through it. The source code for the game can be obtained
here Any assistance in this matter would be greatly appreciated.
Sincerely,
8BitOoze