Here is a bit more detail on what I'm trying to do. I would post all of my code but that could be problematic. Do you see where I declared my variable at the top of this function? The variables are of int type. My main problem is trying to alter the value of the variables but the only variables that are being altered are int x & y. These variables are being used to control where I place my tiles and their respected collision detected. There are 2 for loops. 1 for the floor and the other for the wall/ elevated platforms. In the for loop for elevated platform my conditional statement do not change the values of my data types other wise my tile x & y would not be place at the coordinate 0,0.
SDL_Rect has 4 values. x, y, h, w. It would be declared like this
SDL_Rect Wall;
Wall.x = ?;
Wall.y = ?;
Wall.h = ?;
Wall.w = ?;
I need to learn why the variables are not being edited. If I can figure this out I will gain full control over where I place my tiles.
bool set_tiles( Tile *tiles[], Tile *walls[] )
{
//The tile offsets
int x = 0, y = 0;
int a = 0, b = 0;
int p = 0, q = 0;
//Open the map
std::ifstream map( "lazy.map" );
std::ifstream map2( "Zrender.map" );
std::ifstream coords ("Coords.map");
//If the map couldn't be loaded
if( map == NULL )
{
return false;
}
if( map2 == NULL )
{
return false;
}
//Initialize the tiles
for( int t = 0; t < TOTAL_TILES; t++ )
{
//Determines what kind of tile will be made
int tileType = -1;
//Read tile from map file
map >> tileType;
//If the was a problem in reading the map
if( map.fail() == true )
{
//Stop loading map
map.close();
return false;
}
//If the number is a valid tile number
if( ( tileType >= 0 ) && ( tileType < TILE_SPRITES ) )
{
tiles[ t ] = new Tile(NULL, NULL, NULL , NULL, x, y, tileType );
//Move to next tile spot
x += TILE_WIDTH;
}
//If we don't recognize the tile type
else
{
//Stop loading map
map.close();
return false;
}
//If we've gone too far
if( x >= LEVEL_WIDTH )
{
//Move back
x = 0;
//Move to the next row
y += TILE_HEIGHT;
}
}
//Ending of for loop.
for( int tz = 0; tz < TOTAL_TILES_WALL; tz++ )
{
//Determines what kind of tile will be made
int tileTypeWall = -1;
int Position = -1;
//Read tile from map file
map2 >> tileTypeWall;
coords >> Position;
//If the was a problem in reading the map
if( map2.fail() == true )
{
//Stop loading map
map2.close();
return false;
}
if (Position == 0)
{
p += TILE_WIDTH;
}
//If the number is a valid tile number
if ( tileTypeWall == TILE_RED_WALLf )
{
walls[ tz ] = new Tile( NULL, NULL, p , q, NULL, NULL, tileTypeWall );
}
}
//Close the file
map.close();
//If the map was loaded fine
return true;
}
bool touches_wall( SDL_Rect box, Tile *tiles[] )
{
//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;
}
}
}
//If no wall tiles were touched
return false;
}