Actually, mine works. BUT i want it to erase the old sqaure forever. How?
I do like this and it erases every time the sXl is 400 and pXr is 400.
My function:
Code:
//Check if there is a collision
int check_coll( int sX, int sY, int pX, int pY )
{
//Square's position
int sXl = sX;
int sXr = sX + 29;
int sYl = sY;
int sYr = sY + 29;
//Piece's position
int pXl = pX;
int pXr = pX + 75;
int pYl = pY;
int pYr = pY + 148;
if (sXl == 400)
{
if (sXl == pXr)
{
SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) );
apply_surface( 0, 0, background, screen );
piece = load_image( "piece.png" );
apply_surface( pXl, pYl, piece, screen );
sXl = 100;
//Apply the square
apply_surface( sXl, sYl, square, screen );
}
if (sXl == pXr)
{
sXl = 100;
//Apply the square
apply_surface( sXl, sYl, square, screen );
}
}
if (sXl == 100)
{
if (sXl == pXr)
{
sXl = 340;
//Apply the square
apply_surface( sXl, sYl, square, screen );
}
if (sXl == pXr)
{
sXl = 340;
//Apply the square
apply_surface( sXl, sYl, square, screen );
}
}
}
Soe code in main:
Code:
//Apply the square
apply_surface( sX, sY, square, screen );
//Check collision and move the square
check_coll(sX, sY, x, y);