This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Game Development and the fly likes Collision Detection Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Collision Detection Help" Watch "Collision Detection Help" New topic
Author

Collision Detection Help

Justin Blackwell
Greenhorn

Joined: Nov 28, 2012
Posts: 1
Hello,
I'm programming a 2D sidescroller/platformer written on Java using Slick2D. The past couple weeks, I've had a lot of trouble with collision detection/response.

Detection & Response I'm Looking For
Rectangle-on-rectangle collision detection, with the response being to move the involved sprites away from each other. If one or both sprites are defined as static (represented by isStatic), don't move that sprite.

Code
Here's my code relating to it in my Sprite class:


The Problem
My problem is when either sprite in the collision is not perfectly square. How could I modify this code to work with non-square rectangles?
If I'm way off course with this code, if someone else has better, working code, I'd accept that too.

Thanks in advance!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Collision Detection Help
 
Similar Threads
Why does a char value also have an integer value?
First Java Game - Help REALLY appreciated
Offsetting X/Y
Can't find bug in my Rectangle class. Think it might be the fault of my setup.
Sprite / Window Collision