Cambios en animaciones y tiles
This commit is contained in:
105
source/map.cpp
105
source/map.cpp
@@ -32,6 +32,7 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *it
|
||||
printf("Error: map_layer0 could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
SDL_SetTextureBlendMode(map_layer0, SDL_BLENDMODE_BLEND);
|
||||
// SDL_SetTextureAlphaMod(map_layer0, 128);
|
||||
|
||||
map_layer1 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
if (map_layer1 == NULL)
|
||||
@@ -184,12 +185,37 @@ bool Map::loadMapFile(std::string file_path)
|
||||
return success;
|
||||
}
|
||||
|
||||
// Lee la matriz de tiles desde un fichero tmx a un vector
|
||||
std::vector<int> Map::readTilesFromFile(std::ifstream &file)
|
||||
{
|
||||
std::vector<int> tilemap;
|
||||
std::string line;
|
||||
|
||||
// Salta una linea y lee la siguiente
|
||||
std::getline(file, line);
|
||||
std::getline(file, line);
|
||||
while (line != "</data>")
|
||||
{ // Procesa lineas mientras haya
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
tilemap.push_back(std::stoi(tmp));
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
}
|
||||
|
||||
return tilemap;
|
||||
}
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
bool Map::loadMapTileFile(std::string file_path)
|
||||
{
|
||||
std::vector<int> tilemap;
|
||||
|
||||
std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::string line;
|
||||
std::ifstream file(file_path);
|
||||
|
||||
@@ -203,88 +229,29 @@ bool Map::loadMapTileFile(std::string file_path)
|
||||
{ // Lee el fichero linea a linea
|
||||
if (line.find("name=\"estatico\"") != std::string::npos)
|
||||
{
|
||||
// Salta una linea y lee la siguiente
|
||||
std::getline(file, line);
|
||||
std::getline(file, line);
|
||||
while (line != "</data>")
|
||||
{ // Procesa lineas mientras haya
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
tilemap.push_back(std::stoi(tmp));
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
}
|
||||
|
||||
tilemap = readTilesFromFile(file);
|
||||
fillGradientTexture(*map_layerBG);
|
||||
fillMapTexture(*map_layerBG, tilemap, false);
|
||||
tilemap.clear();
|
||||
}
|
||||
|
||||
if (line.find("name=\"fondo\"") != std::string::npos)
|
||||
else if (line.find("name=\"fondo\"") != std::string::npos)
|
||||
{
|
||||
// Salta una linea y lee la siguiente
|
||||
std::getline(file, line);
|
||||
std::getline(file, line);
|
||||
while (line != "</data>")
|
||||
{ // Procesa lineas mientras haya
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
tilemap.push_back(std::stoi(tmp));
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
}
|
||||
|
||||
tilemap = readTilesFromFile(file);
|
||||
fillMapTexture(*map_layer0, tilemap, true);
|
||||
tilemap.clear();
|
||||
}
|
||||
|
||||
if (line.find("name=\"mapa\"") != std::string::npos)
|
||||
else if (line.find("name=\"mapa\"") != std::string::npos)
|
||||
{
|
||||
// Salta una linea y lee la siguiente
|
||||
std::getline(file, line);
|
||||
std::getline(file, line);
|
||||
while (line != "</data>")
|
||||
{ // Procesa lineas mientras haya
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
tilemap.push_back(std::stoi(tmp));
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
}
|
||||
|
||||
tilemap = readTilesFromFile(file);
|
||||
fillMapTexture(*map_layer1, tilemap, true);
|
||||
tilemap.clear();
|
||||
}
|
||||
|
||||
if (line.find("name=\"colisiones\"") != std::string::npos)
|
||||
else if (line.find("name=\"colisiones\"") != std::string::npos)
|
||||
{
|
||||
// Salta una linea y lee la siguiente
|
||||
std::getline(file, line);
|
||||
std::getline(file, line);
|
||||
while (line != "</data>")
|
||||
{ // Procesa lineas mientras haya
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
collisionmap.push_back(std::stoi(tmp));
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
}
|
||||
collisionmap = readTilesFromFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,9 +259,9 @@ bool Map::loadMapTileFile(std::string file_path)
|
||||
printf("Closing file %s\n\n", filename.c_str());
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
|
||||
else
|
||||
{
|
||||
{ // El fichero no se puede abrir
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ private:
|
||||
// Pinta el mapa de tiles en la textura
|
||||
void fillMapTexture(SDL_Texture &layer, std::vector<int> tilemap, bool clean);
|
||||
|
||||
// Lee la matriz de tiles desde un fichero tmx a un vector
|
||||
std::vector<int> readTilesFromFile(std::ifstream &file);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker);
|
||||
|
||||
Reference in New Issue
Block a user