Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Block/Ball collision

Author
Message
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 18th Jun 2010 00:30
So Ive been having some issues with collision. One has led me in the right direction to getting my paddle and ball bouncing off properly. I created at function that should delete the blocks when making contact with the ball. The score tallies up, but the blocks wont disapear. Basically, it appears the dbDeleteSprite() doesnt work. I have the right ID connected to the dbDeleteSprite() function so that it will delete the block sprites. Another little problem is that all the blocks respond to the score increment except the first cell. Here is my function...

[void pBlockHit (void)
{
int iBallX = dbSpriteX (2);
int iBallY = dbSpriteY (2);

int iBlocksSprite = 3;

// check if the ball touched the blocks
for (int iY = 0 ; iY < 6 ; iY++)
{
for (int iX = 0; iX < 6 ; iX++)
{
iBlocksSprite++;

if (g_bBlocksAlive[iX][iY] == false)
continue;

int iBlocksX = dbSpriteX (iBlocksSprite);
int iBlocksY = dbSpriteY (iBlocksSprite);

// have we scored a hit?
if ((iBallX > iBlocksX && iBallX < iBlocksX + dbSpriteWidth(iBlocksSprite)) || (iBallX > iBlocksX && iBallX < iBlocksX + dbSpriteWidth(iBlocksSprite)))
{
if ((iBallY > iBlocksY && iBallY < iBlocksY + dbSpriteHeight(iBlocksSprite)) || (iBallY > iBlocksY && iBallY < iBlocksY + dbSpriteHeight(iBlocksSprite)))
{
//// yes! we have hit an enemy, lets increase the score and blow that enemy up
//dbPlaySound ( 3 );

// delete the sprite
dbDeleteSprite (iBlocksSprite);

iBallY -= iBallSpeedY;
iBallSpeedY = -1;

g_bBlocksAlive[iX][iY] = false;

// Update score
g_iPlayerScore += 100;
playerUpdateScore();
return;
}
}
}
}
}]

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 18th Jun 2010 06:33
Quote: "Another little problem is that all the blocks respond to the score increment except the first cell. Here is my function...
"


This can be solved by changing the 3 to a 2 in the following line:



The reason why is that the first instruction within the 2nd for...loop says to increment the counter by 1 - which is fine except that this results in completely bypassing the first block (assuming that your first block starts at ID 3).

Quote: "The score tallies up, but the blocks wont disapear"


In this case, I would call dbHideSprite() before calling dbDeleteSprite() - although it would seem that dbDeleteSprite() should hide it since it's no-longer valid. Since I don't deal with sprites, I can't say with any certainty that this will solve the problem - but it's worth a try...

Regards,
JTK

Login to post a reply

Server time is: 2024-11-19 20:54:43
Your offset time is: 2024-11-19 20:54:43