I need to detect collision between one ball(oval) and many blocks(rectangles). In class Block which represent block in the game, I have following code to detect collision (its short version, just for show example):
if(ballYPos <= blockYPos
&& ballYPos >= blockYPos
&& ballXPos >= blockXPos
&& ballXPos+ballWidth <= blockXPos+blockWidth) {
collision
}
collisions are not good, because of oval, but generally, I want to ask if there is something in java(swing) to detect collisions, I mean something like if rectangle is not fully showed on Canvas which means the ball is overlapping a block coordinates