Still same problem..
Code:
Code:
//Check if there is a collision
bool 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;
//Check if you hit the square
if ((pXr >= sXl && pXr < sXr) || (pXl <= sXr && pXl > sXl) || (sXl >= pXl && sXl <= pXr) || (sXr <= pXr && sXr >= pXl))
{
return true;
}
else
{
return false;
}
}
//Move square if there is a collision
void move_and_show_square( int sX, int sY, int pX, int pY )
{
//Variables
int sXl;
sXl = 400;
//If there is a collision
if (check_coll( sX, sY, pX, pY ) == true)
{
//New position for the square
sXl = 50;
//Make the square move
SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) );
apply_surface( 0, 0, background, screen );
piece = load_image( "piece.png" );
apply_surface( pX, pY, piece, screen );
}
//Apply the square
apply_surface( sXl, 300, square, screen );
}