The challenge to you if you chose to take it is tile cillision! Yep, its pretty much the same as my last post! See how im prolly annoying!!!!!!
This is the drawng function:
Code: Select all
void draw_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect clip = NULL ) //same as Lazy Foo's function
{
SDL_Rect pos
{
pos.x = x;
pos.y = y;
}
SDL_BlitSurface( source, clip, destination, &pos );
}
Code: Select all
bool check_collision( SDL_Rect A, SDL_Rect B ) //yup again, same as Lazy Foo's bounding box collision
{
//The sides of the rectangles
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
//Calculate the sides of rect A
leftA = A.x;
rightA = A.x + A.w;
topA = A.y;
bottomA = A.y + A.h;
//Calculate the sides of rect B
leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;
//If any of the sides from A are outside of B
if( bottomA <= topB )
{
return false;
}
if( topA >= bottomB )
{
return false;
}
if( rightA <= leftB )
{
return false;
}
if( leftA >= rightB )
{
return false;
}
//If none of the sides from A are outside B
return true;
}
Code: Select all
int map[5][5] = {
{ 0, 0, 0, 1, 0 }
{ 0, 1, 2, 1, 1 }
{ 0, 0, 0, 0, 0 }
{ 0, 1, 1, 1, 1 }
{ 0, 0, 0, 2, 0 }
}
for( int x = 0; x < 5; x++ )
{
for( int y = 0; y < 5; y++ )
{
if( map[x][y] == 0 )
{
draw_surface( x * 32, y * 32, grass, screen );
}
else if( map[x][y] == 1 )
{
draw_surface( x * 32, y * 32, water, screen );
}
}
}
//same for each number in array