I am trying to make a brick game like this one http://www.youtube.com/watch?v=K1Ih5IyoydQ&feature=related
I have created all the bricks with this code
// creates all the bricks
int spriteID = 14;
for(int i = 0; i < 80; i += 20)
{
for(int j = 0; j < 640; j += 80)
{
dbSprite(spriteID, j, i, imgID);
spriteID++;
}
}
The problem, however, is with my collision function. It checks one brick at a time to see if a brick is being hit by the ball. it only works if you hit the brick it happens to be checking. this is my function, i haven't finished it. how can i make it check all bricks at all times or should i be doing this completely differently?
int bricks::collision()
{
//int spriteID = 14;
for(int spriteID = 14; dbSpriteExist(spriteID); spriteID++)
{
if(spriteID > 48)
{
spriteID = 14;
}
for(int i = 0; i < 80; i += 20)
{
// if the ball hits a brick
if(dbSpriteCollision(spriteID, 4) == 1)
{
// if the ball hits the bottom of the brick
if(dbSpriteHeight(spriteID) + dbSpriteY(spriteID) <= dbSpriteY(4) && dbSpriteX(4) + 10 >= dbSpriteX(spriteID) && dbSpriteX(4) + 10 <= dbSpriteX(spriteID) + dbSpriteWidth(spriteID))
{
if(dbSpriteAngle(4) == 315)
{
dbRotateSprite(4, 225);
}
if(dbSpriteAngle(4) == 45)
{
dbRotateSprite(4, 135);
}
dbDeleteSprite (spriteID);
}
// if the ball hits the top of the brick
if(dbSpriteHeight(spriteID) >= dbSpriteHeight(4) + dbSpriteY(4) && dbSpriteX(4) + 10 >= dbSpriteX(spriteID) && dbSpriteX(4) + 10 <= dbSpriteX(spriteID) + dbSpriteWidth(spriteID))
{
if(dbSpriteAngle(4) == 225)
{
dbRotateSprite(4, 315);
}
if(dbSpriteAngle(4) == 135)
{
dbRotateSprite(4, 45);
}
dbDeleteSprite (spriteID);
}
}
}
}
return 0;
}