Advertisement
thecplusplusguy

Simple sidescroller game - base.cpp

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