I nested a lot of functions, while I'm not lost with what I did, I am confused about why the last nested function is giving me problems with the function arguments. Here is some code from the second nested function to the last in spefic order.
bool touches_wall( SDL_Rect box, SDL_Rect ys, Tile *tiles[], SideTile *walls[] )
2#
In this function I call check_collision_region
bool touches_wall( SDL_Rect box, SDL_Rect ys, Tile *tiles[], SideTile *walls[] )
{
int count = 0;
//Go through the tiles
for( int t = 0; t < TOTAL_TILES; t++ )
{
//If the tile is a wall type tile
if( ( tiles[ t ]->get_type() >= TILE_CENTER ) && ( tiles[ t ]->get_type() <= TILE_TOPLEFT ) )
{
//If the collision box touches the wall tile
if( check_collision( box, tiles[ t ]->get_box() ) == true )
{
return true;
}
}
}
for( int s = 0; s < TOTAL_TILES_WALL; s++ )
{
//If the tile is a wall type tile
if( walls[ s ]->get_type() == TILE_RED_WALLs )
{
//If the collision box touches the wall tile
if( check_collision_region( box, walls[s]->get_base_box(), ys, walls[s]->get_box() ) == true )
{
return true;
}
}
}
//If no wall tiles were touched
return false;
}
3# in this function I call check_collision_topside
bool check_collision_region(SDL_Rect A, SDL_Rect B, SDL_Rect C, SDL_Rect D )
{
//The sides of the rectangles
int leftA, leftB, leftC, leftD;
int rightA, rightB, rightC, rightD;
int topA, topB, topC, topD;
int bottomA, bottomB, bottomC, bottomD;
bool regionTop;
bool regionBottom;
bool regionNone;
//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.x;
//Calculate the sides of rect C
leftC = C.x;
rightC = C.x + C.w;
topC = C.y;
bottomC = C.y + C.h;
//Calculate the sides of rect D
leftD = D.x;
rightD = D.x + D.w;
topD = D.y;
bottomD = D.y + D.x;
//Test
//If any of the sides from A are inside of B
if(( bottomA >= topB ) && ( bottomA <= topB + TILE_WALLs_HEIGHT/2 ) && (rightA >= leftB) &&(leftA <= rightB))
{
if (check_collision_topside( SDL_Rect A, SDL_Rect B, SDL_Rect C, SDL_Rect D) == true)
{
return true;
}
}
//Second function
/* if(( bottomA <= bottomB) && (bottomA >= bottomB - TILE_WALLs_HEIGHT/2 ) )
{
if((rightA >= leftB) &&(leftA <= rightB))
{
//regionBottom = true;
if (check_collision_bottomside( SDL_Rect A, SDL_RECT B, ,SDL_Rect C, SDL_Rect D) == true)
{
return true
}
}
} */
return false;
}
4# I haven't really worked on the forth yet it's kinda generic but I will fine tune it if I can get the 3# to work.
bool check_collision_topside( SDL_Rect A, SDL_Rect B, SDL_Rect C, SDL_Rect D)
{
//The sides of the rectangles
int leftA, leftB, leftC, leftD;
int rightA, rightB, rightC, rightD;
int topA, topB, topC, topD;
int bottomA, bottomB, bottomC, bottomD;
int top;
//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;
//Calculate the sides of rect C
leftC = C.x;
rightC = C.x + C.w;
topC = C.y;
bottomC = C.y + C.h;
//Calculate the sides of rect D
leftD = D.x;
rightD = D.x + D.w;
topD = D.y;
bottomD = D.y + D.x;
//the top collision only
top = bottomA - topB;
//If any of the sides from A are outside of B
if( bottomC <= topB + top )
{
return false;
}
if( bottomC >= topB + TILE_WALLs_HEIGHT/2 )
{
return false;
}
if( rightA <= leftB )
{
return false;
}
if( leftA >= rightB )
{
return false;
}
//If none of the sides from A are outside B
return true;
}