-
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 );
}
-
Only 2 weeks left to my girlfriends anniversary. Please help me out with this one and i'll help you so much i can. PLEASE! I BEG YOU! Actually, i don't wanna do this bump, but i must! I can't dissapoint here, seriously i can't.
-
Oh dear
Code:
//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;*/ //What is that for? Want to change sX to either 400 or 50?
sX = 400;
//If there is a collision
if (check_coll( sX, sY, pX, pY ) == true)
{
//New position for the square
sX = 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" ); //do you remember to unload this? or why you keep loading it
apply_surface( pX, pY, piece, screen );
}
//Apply the square
apply_surface( sX, 300, square, screen );
}
These are just guesses. There are global stuff around and magical values, so I can really only guess what this function is meant to achieve.
-
If there aint a collision, i want the square to stay at it's position.
-
In that case don't change sX to 400. That's what your original code does.