Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This example program is created by thecplusplusuy for demonstration purposes. It's a simple mario like side-scroller game:
- //http://www.youtube.com/user/thecplusplusguy
- //Free source, modify if you want, LGPL licence (I guess), I would be happy, if you would not delete the link
- //so other people can see the tutorial
- //this file is base.cpp
- #include "base.h"
- //just make the collision function
- bool baseclass::collision(SDL_Rect* rec1,SDL_Rect* rec2)
- {
- if(rec1->y >= rec2->y + rec2->h) //if rec2 is upper than rec1 there is no way to be a collision
- return 0; //so return 0
- if(rec1->x >= rec2->x + rec2->w) //if rec2 is more to the left than there is no way to be a collision
- return 0;
- if(rec1->y + rec1->h <= rec2->y) //if rec2 is under rec1 no collision
- return 0;
- if(rec1->x + rec1->w <= rec2->x) //if rec2 is righter then rec1 there is no way for collision
- return 0;
- return 1; //if all fails, we have a collision
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement