Thanks.
Now this what Ive come to. when I set it up as a 7x8 array I had to raise the integer variable iSprite to 101. I tinkered with it long enough to find that raising this number so it would show all the blocks in the array because all the lower numbers would have 3-5 blocks randomly missing. As I raised the number and tested it, it seemed to shift the missing blocks over one place. I incremented until 101 showed them all. This is the function for the blocks:
void blocksSpawn (void)
{
// reset variables
blocksDeadCount = 0;
// delete any sprites - "dead" enemies have been swapped to a different image and so loose their "animImage" capability, so we can delete and remake them to turn them back
for (int i = 9; i < 36; i++)
{
if (dbSpriteExist(i))
dbDeleteSprite(i);
}
// Delete the image we loaded automatically with dbLoadImage, because we are going to make them again
if (dbImageExist(4))
dbDeleteImage(4);
// setup the enemies, load the images and sprites
blocksSetup();
// set the initial position of all enemy sprites
// loop through the 5 rows of enemies, 5 in each row
int iSprite = 101;
for (int iY = 0; iY < 7; iY++)
{
for (int iX = 0; iX < 8; iX++)
{
dbSprite (iSprite, iX*100+55, iY*21+120, 4);
iSprite++;
// set each enemy to "alive"
blocksAlive[iX][iY] = true;
}
}
This is the entire function for the collision between the ball and block, which I had to set them to fit the array.
void ballCheckHitBlocks ( void )
{
int ballX = dbSpriteX(2);
int ballY = dbSpriteY(2);
int blockX;
int blockY;
//int blockSprite = 9;
//// check ball against all blocks
//for ( int iY = 0 ; iY < 6 ; iY++ )
//{
// for ( int iX = 0; iX < 6 ; iX++ )
// {
int blockSprite = 101;
// check ball against all blocks
for ( int iY = 0 ; iY < 7 ; iY++ )
{
for ( int iX = 0; iX < 8 ; iX++ )
{
blockSprite++;
if ( blocksAlive[iX][iY] == false )
continue;
blockX = dbSpriteX ( blockSprite );
blockY = dbSpriteY ( blockSprite );
// have we scored a hit?
if ( ( ballX > blockX && ballX < blockX + dbSpriteWidth ( blockSprite ) ) || ( ballX > blockX && ballX + 8 < blockX + dbSpriteWidth ( blockSprite ) ) )
{
if ( ( ballY > blockY && ballY < blockY + dbSpriteHeight ( blockSprite ) ) || ( ballY > blockY && ballY + 8 < blockY + dbSpriteHeight ( blockSprite ) ) )
{
db
blocksDeadCount++;
// if 25 enemies (5 rows of 5) have all been killed, the level is completed
if ( blocksDeadCount == 54 )
{
playerWin = true;
}
//// yes! we have hit an enemy, lets increase the score and blow that enemy up
//dbPlaySound ( 3 );
// delete the sprite
dbDeleteSprite ( blockSprite );
blocksAlive[iX][iY] = false;
// add and display the new score
playerScore += 25;
paddleUpdateScore();
return;
}
}
}
}
}
The problem Im having is, of course, the bounce response with collision. The other thing is that the ball starts the game moving to the upper left screen. When it hits the first set of blocks in the lower left part it causes the first and second blocks of the array to disapear too before they were even touched.
"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo