OK, so i have created a colition detector using bounding boxes. It gets the blocks below the player, one on the right, one on the left, or if the player is completely perfect on the block, the center one. It then creates bounding boxes, but it isnt working for some reason. IM only going to show some of it, but youll get the idea.
bool testForCollision(const boundingbox& a, const boundingbox& b) {
if (a.lry < b.uly) return false; // top of a is below bottom of b
if (a.uly > b.lry) return false; // bottom of a is above top of b
if (a.lrx < b.ulx) return false; // right of a is more right than left of b
if (a.ulx > b.lrx) return false; // left of a is more left than right of b
return true; // otherwise, they must be colliding somewhere
}
bool check_colition_down(int speed)
{
int tempx=mainplayer.x; int tempy=mainplayer.y+speed;
int tempblockx1=ceil(tempx/32); int tempblocky1=floor((tempy+mainplayer.height)/32);
int tempblockx2=ceil(tempx/32); int tempblocky2=ceil((tempy+mainplayer.height)/32);
boundingbox blockbelow; blockbelow.setposition(tempblockx1*32,tempblocky1*32,tempblockx1*32+32, tempblocky1*32+32);
boundingbox blockbelow2; blockbelow2.setposition(tempblockx2*32,tempblocky2*32,tempblockx2*32+32,tempblocky2*32+32);
if(testForCollision(blockbelow2,mainplayer.colition))
{
if(testForCollision(blockbelow,mainplayer.colition))
{
if(!blocklist[mainmap.getblock(tempblockx1,tempblocky1)].walkable)
{
if(!blocklist[mainmap.getblock(tempblockx2,tempblocky2)].walkable)
return false;
}
}
}
return true;
}