diff --git a/data/config/config.txt b/data/config/config.txt index 8074f6a..56c3ec4 100644 --- a/data/config/config.txt +++ b/data/config/config.txt @@ -1,5 +1,5 @@ fullScreenMode=0 -windowSize=2 +windowSize=3 filter=FILTER_NEAREST vSync=true integerScale=true diff --git a/data/map/surface.aseprite b/data/map/surface.aseprite new file mode 100644 index 0000000..cab6098 Binary files /dev/null and b/data/map/surface.aseprite differ diff --git a/data/map/surface.png b/data/map/surface.png index cb5bee1..511c49e 100644 Binary files a/data/map/surface.png and b/data/map/surface.png differ diff --git a/data/player/player.ani b/data/player/player.ani index 317d7b8..f38e6b6 100644 --- a/data/player/player.ani +++ b/data/player/player.ani @@ -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] \ No newline at end of file diff --git a/data/player/player.png b/data/player/player.png index b0ebc7e..3feab34 100644 Binary files a/data/player/player.png and b/data/player/player.png differ diff --git a/source/map.cpp b/source/map.cpp index fc66219..05e234d 100644 --- a/source/map.cpp +++ b/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 Map::readTilesFromFile(std::ifstream &file) +{ + std::vector tilemap; + std::string line; + + // Salta una linea y lee la siguiente + std::getline(file, line); + std::getline(file, line); + while (line != "") + { // 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 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 != "") - { // 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 != "") - { // 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 != "") - { // 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 != "") - { // 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; } diff --git a/source/map.h b/source/map.h index 06710c3..b749071 100644 --- a/source/map.h +++ b/source/map.h @@ -80,6 +80,9 @@ private: // Pinta el mapa de tiles en la textura void fillMapTexture(SDL_Texture &layer, std::vector tilemap, bool clean); + // Lee la matriz de tiles desde un fichero tmx a un vector + std::vector readTilesFromFile(std::ifstream &file); + public: // Constructor Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker);