#include "Cplayer.h"
#include "mainengine.h"
short int CPlayer::CollisionCheck(BlockInfo &object1, BlockInfo &object2)
{
// We check whether 2 sprite objects overlap each other,
// using the so-called reduced rectangles that are 80% of
// the original ones.
// We store the coordinates of our reduced rectangles here
double left1, left2;
double right1, right2;
double top1, top2;
double bottom1, bottom2;
// (this is our sprite)
// |---sprite width---|
// A******************* <-|-height*0.1
// **B...............** <-\
// **................** <-\
// **................** <-\
// **................** <-\
// **|---width*0.8--|** <-\
// **................** <-\
// **................** <-\
// **...............C** <---height*0.9
// *******************D
// ^^ width*0.1
// ^^^^^^^^^^^^^^^^^^ width*0.9
// What we do now is store the coordinates of our
// shrunken rectangle inside some variables.
// We make 'left' and 'top' equal the position B on our sprite
// (look at the "drawing") and 'right' and 'bottom' equal the
// position C. (Remember, left1, top1, etc contain the coordinates
// of the first sprite's reduced rectangle and left2, top2 contain
// the coordinated of the second sprite's reduced rectangle)
left1 = object1.getx()+object1.getw()*0.1;
left2 = object2.getx()+object2.getw()*0.1;
top1 = object1.gety()+object1.geth()*0.1;
top2 = object2.gety()+object2.geth()*0.1;
right1 = object1.getx()+object1.getw()*0.9;
right2 = object2.getx()+object2.getw()*0.9;
bottom1 = object1.gety()+object1.geth()*0.9;
bottom2 = object2.gety()+object2.geth()*0.9;
// We now do some little comparing and return 0 if the rectangles
// aren't colliding and 1 if they are.
if (bottom1 < top2) return 0;
if (top1 > bottom2) return 0;
if (right1 < left2) return 0;
if (left1 > right2) return 0;
return 1;
}
void CPlayer::MovePlayer(int movex, int movey)
{
x += movex;
y += movey;
}