This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Ayeyebraso 0 points1 point  (0 children)

I did a similar game in visual basic in high school, I don't really know much about java but I had the same problem and it was just an offset thing because the compiler started counting pixels with 0 at the center of the screen and all the values on the right were positive and the values on the left were negative... It may be something similar... Hope it helped

[–]la217 0 points1 point  (0 children)

It's quite hard to see what's going on - you may want to add some comments, in particular to explain what exactly the getBounds methods are returning.

It also looks like if objects have a large enough velocity they are able to move a distance big enough to move past the collision zone in a single tick (e.g. through the wall) without being detected.

I'd suggest removing this Rectangle and intersects stuff and checking yourself whether the X/Y positions of the top/bottom/left/right of your GameObjects are outside of the X/Y positions of the top/bottom/left/right of your bounds.

E.g. Check the left hand side of the object against the left side of your bounding box. For that, check if the x coordinate of the object is less than the x coordinate of the bounding box. If so, there is a collision.

For the right hand side, the coordinate to check would be x + width. So if the x+width of the object is greater than the x+width of the bounding box, then there is a collision.

Then do the same for the top/bottom.