Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I came across the following code in a game book but I can't get it, does it check if a point ( left,top) in a rectangle?

bool CheckCollision(float left, float top,  float SpriteX, float SpriteWidth, float SpriteY, float SpriteHeight)
{
    return !((left >SpriteX + SpriteWidth) ||
            (top > SpriteY + SpriteHeight) ||
            (SpriteX > left + SpriteWidth) ||
            (SpriteY> top +SpriteHeight));

}
share|improve this question
    
Yes, that's what it seems to be doing. Do you have any specific questions about how it does this? It seems really trivial to me, but on the other hand I have no idea of how much you know about C++, so I wouldn't know where to begin my explanation. –  Philipp Feb 5 at 21:28
    
Just a visual figure is enough. So the above function is different than Rect to Rect collision ? –  andre Feb 5 at 21:36

1 Answer 1

up vote 1 down vote accepted

I don't have enough reputation to comment, so I will post this as an answer.

To get the most out of this exercise, I suggest you take a piece of paper, draw a rectangle and then try to map out each check on the paper.

For example: if the left coordinate of my actor is bigger than the wall, it will look like so.

Hopefully you understand what I mean, it's hard to explain with words. :P

share|improve this answer
    
+1 for taking a piece of paper and drawing it. –  Krom Stern Feb 6 at 12:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.