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