Now, if it loads the same map over and over, it clears and loads them fine, but if I change it to load a different map than the start map it crashes at the ThinkAll function,(Which calls the think function of every entity in the Entitys vector)
This is the entire function for loading a map, it's used at the start of the game to load the beginning map and anywhere else.
It loads blocks into vectors, and then at the end creates a test warp and then the player.
ALL collision Blocks (soldtile, jumptile) are in the entity vector, and in their respective vectors. The player, warps and normal tiles are in the entity vector.
Code: Select all
void Map::Load(string filename, int start_x, int start_y )
{
SolidTile::SolidTiles.clear();
for (int i = 0; i < SolidTile::SolidTiles.size(); i++)
{
SolidTile::SolidTiles.at(i) = NULL;
}
JumpTile::JumpTiles.clear();
for (int i = 0; i < JumpTile::JumpTiles.size(); i++)
{
JumpTile::JumpTiles.at(i) = NULL;
}
Entity::Entitys.clear();
for (int i = 0; i < Entity::Entitys.size(); i++)
{
Entity::Entitys.at(i) = NULL;
}
string line, filepath, filepathfile, filepathprop;
filepath = "Data/Maps/" + filename;
filepathfile = filepath + "/" + filename + "_prop";
cout << "Loading Map properties from file: " << filepathfile << "\n";
ifstream myfile (filepathfile.c_str());
getline(myfile,line);
width = atoi(line.c_str());
getline(myfile,line);
height = atoi(line.c_str());
myfile.close();
cout << "Map Width: " << width << "\n";
cout << "Map Height: " << height << "\n";
filepathfile = filepath + "/" + filename + "_layer0";
cout << "Loading Map collision layer from file: " << filepathfile << "\n";
myfile.open (filepathfile.c_str());
for (int i =0; i<height/32; i++)
{
for (int r = 0; r<width/32; r++)
{
getline (myfile,line);
if (atoi( line.c_str() ) == 1)
{
new SolidTile( r*32, i*32);
}
if (atoi( line.c_str() ) == 2)
{
new JumpTile( r*32, i*32);
}
}
}
myfile.close();
filepathfile = filepath + "/" + filename + "_layer2";
cout << "Loading Map tile 2 layer from file: " << filepathfile << "\n";
myfile.open (filepathfile.c_str());
int tile_x, tile_y;
for (int i =0; i<height/32; i++)
{
for (int r = 0; r<width/32; r++)
{
getline (myfile,line);
tile_x = atoi(line.c_str());
getline (myfile,line);
tile_y = atoi(line.c_str());
if (tile_x!=-1 && tile_y!=-1)
{
new Tile( r*32, i*32, tile_x, tile_y );
}
}
}
myfile.close();
filepathfile = filepath + "/" + filename + "_layer1";
cout << "Loading Map tile layer from file: " << filepathfile << "\n";
myfile.open (filepathfile.c_str());
for (int i =0; i<height/32; i++)
{
for (int r = 0; r<width/32; r++)
{
getline (myfile,line);
tile_x = atoi(line.c_str());
getline (myfile,line);
tile_y = atoi(line.c_str());
if (tile_x!=-1 && tile_y!=-1)
{
new Tile( r*32, i*32, tile_x, tile_y );
}
}
}
myfile.close();
new Warp( 512-32, 64, "small", 64, 64, 1 );
Player::GetInterface()->SetNull();
Player::GetInterface()->Spawn( start_x, start_y );
}