我已经研究了几个小时,但无济于事。基本上我有
struct rectangle {
int x, y, w, h;
};
rectangle player::RegionCoordinates() // Region Coord
{
rectangle temp;
temp.x = colRegion.x + coordinates.x;
temp.w = colRegion.w;
temp.y = colRegion.y + coordinates.y;
temp.h = colRegion.h;
return temp;
}
// Collision detect function
bool IsCollision (rectangle * r1, rectangle * r2)
{
if (r1->x < r2->x + r2->w &&
r1->x + r1->w > r2->x &&
r1->y < r2->y + r2->h &&
r1->y + r1->h > r2->y)
{
return true;
}
return false;
}
//blah blah main while loop
if (IsCollision(&player1.RegionCoordinates(), &stick1.RegionCoordinates())) //ERROR
{
player1.score+=10;
stick1.x = rand() % 600+1;
stick1.y = rand() % 400+1;
play_sample(pickup,128,128,1000,false);
}
有任何想法吗?我敢肯定这是很明显的事情,但对于我的生活,我无法弄清楚。