How to intersect a oval and a rect ?

How to intersect a oval and a rect ?

I am making a pong game , and have got it to work.
But to detect collision im using

private boolean collision() {
return game.racquet.getBounds().intersects(getBounds());
}

public Rectangle getBounds() {
    return new Rectangle(x, y, DIAMETER, DIAMETER);
}

As you can see by the getBounds() the ball is made into a rectangle.
This means that sometime it looks like the ball will miss the paddle but it actuly hits because its a rectangle.
Is there anyway around this?

If your paddles are not rotated, a square hitting a square is fine. Square hitting a square will never miss.

Its quite the opposite - the ball will sometimes intersect too soon then it should.

This will result in a collision

http://s9.postimg.org/md6ng1k8v/collision.png

But i want that to be a gameover();

So do it.

I didn’t quite get you o-o

http://www.java-gaming.org/topics/vectors-what-s-the-point/24307/msg/225743/view.html#msg225743

I sensed a Disturbance in the force.



http://www.java-gaming.org/index.php/topic,10265.

It is easy.

Just use if-else condition.

Actually I made a game like this before while I am learning how to make a game through the help of tutorial.
http://zetcode.com/tutorials/javagamestutorial/

I want to tell the ball if what part of the block it hitted. If it is the top, bottom, left or right side, so that I can command the ball if where it will bounce.

for example:


height = 10;
width = 50;
diameter = 20;

if (hitted) {
   if (oval.x + diameter == rectangle.x && oval.y + diameter < rectangle.y)
      left
   else if (oval.x == rectangle.x + width && oval.y + diameter < rectangle.y)
      right
}

With this you already know that the ball hitted the sides.
And you wanted it to be “game over”;

Then you can write:


if (left || right)
   game over

It is easy, right?
But this is not a runnable code.
It is only an Algorithm.

I hope it will help you.

Then just call gameover();

if(collision())
{
     gameover();
}

I cant call game over on collision , then the ball wont bounce

So the have a rectangle at the ends of the field behind the paddles. If the ball collides with those then call game over.

Here is a simply example. The ball bounces of the corners of the rectangle at the correct angle.
http://pastebin.com/ez8VWAj2

Come over to the dark side. We do stuff the easy way.