Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Collision Detection
 Post Posted: October 27th, 2017, 9:53 pm 
 

Joined: October 27th, 2017, 9:51 pm
Posts: 1
Code:
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


Top 
 Profile  
Reply with quote  
 Post subject: Re: Collision Detection
 Post Posted: October 27th, 2017, 11:04 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 517
Location: Idiot from northern Europe
Code:
int playerTop = playerX + playerWidth;

this makes no sense. Player top should be just playerY
playerX + playerWidth should give you the players right side.

Code:
int playerBottom = ;

y + height since y is the top

Code:
  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

Code:
int playerRight = ;

x + width since x is left.


Image

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

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post subject: Re: Collision Detection
 Post Posted: October 28th, 2017, 5:11 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2962
Location: Oklahoma, United States
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


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 3 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron