Cambios en animaciones y tiles

This commit is contained in:
2022-09-24 17:26:29 +02:00
parent 911061899d
commit 8bdb2fdf29
7 changed files with 43 additions and 73 deletions

View File

@@ -1,5 +1,5 @@
fullScreenMode=0
windowSize=2
windowSize=3
filter=FILTER_NEAREST
vSync=true
integerScale=true

BIN
data/map/surface.aseprite Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

@@ -17,14 +17,14 @@ frames=14,15,16,17,18,19,20,21,22,23,24
[animation]
name=jump
speed=4
speed=2
loop=-1
frames=28,29,30,31,32,33,34,35,36,37,38,39,40,41
[/animation]
[animation]
name=death
speed=10
speed=8
loop=-1
frames=42,43,44,45,46,47,48,49,50,51,52,52,52,52,52,52,52,52
frames=42,43,44,45,46,47,48,49,50,51,52,52,52,52,52,52,52
[/animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -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;
}

View File

@@ -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);