Results 1 to 2 of 2
- 08-22-2012, 02:36 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 5
- Rep Power
- 0
Collision statement between squares
Heya,
I have a program with predefined objects(squares) playerObject & stillObject; that have methods to get their x,y coordinates called getX() & getY().
playerObject: moves with the arrow keys of the keyboard via an already provided game engine.
stillObject: is set in a location on the screen.
Both objects have measurements of 100x100.
My problem is I'm having trouble defining a collision detection statement, which needs to account for the stillObject changing positions in debugging tests, so it can't be hard-coded.
So far what I have covers collisions between the top and left sides of the stillObject against playerObject by minusing the distance between them and if it's bigger than 0 than the objects have collided and the same for -200, which should be the other side of stillObject(which is what I thought), but it doesn't seem to be working that way for me.
Any push in the right direction would be great, thank you.Java Code:if ((((stillObject.getX() + 100) - playerObject.getX()) > 0) && ((stillObject.getY() + 100) - playerObject.getY()) > 0) { collide = true; } if ((((stillObject.getX() - 100) + playerObject.getX()) < -200) && ((stillObject.getY() - 100) + playerObject.getY()) < -200) { collide = true; }
- 08-22-2012, 03:42 PM #2
Re: Collision statement between squares
Cross posted
Collision Detection Between Two Squares
Norm is going to love how much you value his help and advice. Not.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Basic - Confusion with collision detection between squares
By damienrenner in forum New To JavaReplies: 2Last Post: 04-25-2012, 03:22 PM -
help with magic squares
By grandmastertheory in forum New To JavaReplies: 2Last Post: 01-18-2012, 12:06 AM -
Help with recursive squares
By luke in forum New To JavaReplies: 1Last Post: 04-18-2011, 11:47 PM -
help with perfect squares
By AmplifiedKid in forum New To JavaReplies: 1Last Post: 09-19-2009, 07:44 PM -
Perfect Squares
By divyachaparala in forum New To JavaReplies: 4Last Post: 02-05-2008, 09:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks