Hey, guys I need some help with my code. I Created a level with multiple box in it. The information of each box is stored into an array of records,but i truly have no idea how to check if the player has hit box one or box two without doing multiple if-statements.
Is there any way that i can check each box without having to do multiple if-statements.
Here is my cod so far.(only the if-statement for the first box, but they the code will look the same for the others)
struct crate
{
int id;
int x;
int y;
int Topid;
int Topx;
int Topy;
};
crate box[10];
void Initbox()
{
for(int i = 0; i < 2,i++)
{
box[i].id = i;
box[i].x = 420;
box[i].y = 414;
box[i].Topid = i + 2;
box[i].Topx = 420;
box[i].Topy = 411;
}
}
void Box()
{
if(dbSpriteCollision(play.id,box[1].id) == 1)
{
if(play.dir == 1)
{
play.Rmove = 0;
play.Lmove = 1;
}
else
{
play.Lmove = 0;
play.Rmove = 1;
}
}
else
{
play.Rmove = 1;
play.Lmove = 1;
}
if(dbSpriteCollision(play.id,box[1].Topid) == 1)
{
play.gravity = 0;
play.Gtouch = 1;
play.Ptouch = 1;
}
else
{
play.Ptouch = 0;
}
}