The Partridge Family were neither partridges nor a family. Discuss.
-
immy
- Posts: 1
- Joined: October 27th, 2017, 9:51 pm
Post
by immy » October 27th, 2017, 9:53 pm
Code: Select all
bool Game::Collision(int playerX, int playerY, int playerWidth, int playerHeight, int objectX, int objectY, int objectWidth, int objectHeight)
{
//draws images at the top left corner (0,0)
int playerTop = playerX + playerWidth;
int playerBottom = ;
int playerLeft= playerY + playerHeight;
int playerRight = ;
int objectTop = objectX + objectWidth;
int objectBottom = objectY;
int objectLeft = objectY + objectHeight;
int objectRight = ;
/*if(playerWidth >= objectTop || <= objectBottom
&& )*/
}
I am trying to find all sides of the two rectangles. I do not know how to calculate the bottom and right side of each rectangle...can somebody please assist me?
Thanks
-
Yumtard
- Posts: 575
- Joined: January 19th, 2017, 10:28 pm
- Location: Idiot from northern Europe
Post
by Yumtard » October 27th, 2017, 11:04 pm
Code: Select all
int playerTop = playerX + playerWidth;
this makes no sense. Player top should be just playerY
playerX + playerWidth should give you the players right side.
y + height since y is the top
Code: Select all
int playerLeft= playerY + playerHeight;
this also doesn't make sense to me. playerLeft should just be playerX
playerY + playerHeight should give you the players bottom like I metioned above
x + width since x is left.
here's how the coordinate system looks like.
black arrow points to the position of the rect. top left corner since that's where it's being drawn from.
meaning:
x = left
x + width = right
y = top
y + height = bottom
-
albinopapa
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Post
by albinopapa » October 28th, 2017, 5:11 am
Or in code:
left = x;
top = y;
right = left + width;
bottom = top + height;
As Yumtard mentioned, the screen coordinates positive directions are right and down, so adding to X moves to the right and adding to Y moves downward.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com