Good morning.
I'm developing a little Arcanoid game.
Now i have some problems with the ball. I've developed with success a system with which the ball when touch wall, it change direction. here is the algoritm
//PosPalla: current ball position
//SpostamentoPalla: the movement of the ball gained.
PosPalla.x += SpostamentoPalla.x;
PosPalla.y += SpostamentoPalla.y;
if (PosPalla.x > 34)
{
PosPalla.x = 34;
SpostamentoPalla.x = -SpostamentoPalla.x;
}
if (PosPalla.x < -4)
{
PosPalla.x = -4;
SpostamentoPalla.x= -SpostamentoPalla.x;
}
if (PosPalla.y < -20)
{
PosPalla.y = -20;
SpostamentoPalla.y = -SpostamentoPalla.y;
}
if (PosPalla.y > 20)
{
PosPalla.y = 20;
SpostamentoPalla.y = -SpostamentoPalla.y;
}
D3DXMATRIXA16 d3dmat;
D3DXMatrixIdentity(&d3dmat);
D3DXMatrixMultiply(&Sfera.WorldMatrix,&Sfera.WorldMatrix,D3DXMatrixTranslation(&d3dmat,SpostamentoPalla.x,SpostamentoPalla.y,0.0f));
As you can see when the ball touch wall it change x or y.
But now there is a problem:
I've to do collisions with pad: for the pad i've decided to do
if (Pospalla.y == 0) {//code for the pad}
But as you can see when ball touchs wall it change x or y. and then when i check if y = 0 i see that y is 0 when it is going up...it's a very big problem
Can you help me??