Results 1 to 2 of 2
  1. #1
    thegreatzo is offline Member
    Join Date
    Aug 2012
    Rep Power

    Default Collision statement between squares


    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.

    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;
    Any push in the right direction would be great, thank you.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default 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.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Basic - Confusion with collision detection between squares
    By damienrenner in forum New To Java
    Replies: 2
    Last Post: 04-25-2012, 04:22 PM
  2. help with magic squares
    By grandmastertheory in forum New To Java
    Replies: 2
    Last Post: 01-18-2012, 01:06 AM
  3. Help with recursive squares
    By luke in forum New To Java
    Replies: 1
    Last Post: 04-19-2011, 12:47 AM
  4. help with perfect squares
    By AmplifiedKid in forum New To Java
    Replies: 1
    Last Post: 09-19-2009, 08:44 PM
  5. Perfect Squares
    By divyachaparala in forum New To Java
    Replies: 4
    Last Post: 02-05-2008, 10:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts