Cambios en animaciones y tiles
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
fullScreenMode=0
|
fullScreenMode=0
|
||||||
windowSize=2
|
windowSize=3
|
||||||
filter=FILTER_NEAREST
|
filter=FILTER_NEAREST
|
||||||
vSync=true
|
vSync=true
|
||||||
integerScale=true
|
integerScale=true
|
||||||
|
|||||||
BIN
data/map/surface.aseprite
Normal file
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 |
@@ -17,14 +17,14 @@ frames=14,15,16,17,18,19,20,21,22,23,24
|
|||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=jump
|
name=jump
|
||||||
speed=4
|
speed=2
|
||||||
loop=-1
|
loop=-1
|
||||||
frames=28,29,30,31,32,33,34,35,36,37,38,39,40,41
|
frames=28,29,30,31,32,33,34,35,36,37,38,39,40,41
|
||||||
[/animation]
|
[/animation]
|
||||||
|
|
||||||
[animation]
|
[animation]
|
||||||
name=death
|
name=death
|
||||||
speed=10
|
speed=8
|
||||||
loop=-1
|
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]
|
[/animation]
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
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());
|
printf("Error: map_layer0 could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
SDL_SetTextureBlendMode(map_layer0, SDL_BLENDMODE_BLEND);
|
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);
|
map_layer1 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||||
if (map_layer1 == NULL)
|
if (map_layer1 == NULL)
|
||||||
@@ -184,12 +185,37 @@ bool Map::loadMapFile(std::string file_path)
|
|||||||
return success;
|
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
|
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||||
bool Map::loadMapTileFile(std::string file_path)
|
bool Map::loadMapTileFile(std::string file_path)
|
||||||
{
|
{
|
||||||
std::vector<int> tilemap;
|
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::string line;
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
|
|
||||||
@@ -203,88 +229,29 @@ bool Map::loadMapTileFile(std::string file_path)
|
|||||||
{ // Lee el fichero linea a linea
|
{ // Lee el fichero linea a linea
|
||||||
if (line.find("name=\"estatico\"") != std::string::npos)
|
if (line.find("name=\"estatico\"") != std::string::npos)
|
||||||
{
|
{
|
||||||
// Salta una linea y lee la siguiente
|
tilemap = readTilesFromFile(file);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
fillGradientTexture(*map_layerBG);
|
fillGradientTexture(*map_layerBG);
|
||||||
fillMapTexture(*map_layerBG, tilemap, false);
|
fillMapTexture(*map_layerBG, tilemap, false);
|
||||||
tilemap.clear();
|
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
|
tilemap = readTilesFromFile(file);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
fillMapTexture(*map_layer0, tilemap, true);
|
fillMapTexture(*map_layer0, tilemap, true);
|
||||||
tilemap.clear();
|
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
|
tilemap = readTilesFromFile(file);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
fillMapTexture(*map_layer1, tilemap, true);
|
fillMapTexture(*map_layer1, tilemap, true);
|
||||||
tilemap.clear();
|
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
|
collisionmap = readTilesFromFile(file);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,9 +259,9 @@ bool Map::loadMapTileFile(std::string file_path)
|
|||||||
printf("Closing file %s\n\n", filename.c_str());
|
printf("Closing file %s\n\n", filename.c_str());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
// El fichero no se puede abrir
|
|
||||||
else
|
else
|
||||||
{
|
{ // El fichero no se puede abrir
|
||||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ private:
|
|||||||
// Pinta el mapa de tiles en la textura
|
// Pinta el mapa de tiles en la textura
|
||||||
void fillMapTexture(SDL_Texture &layer, std::vector<int> tilemap, bool clean);
|
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:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker);
|
Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker);
|
||||||
|
|||||||
Reference in New Issue
Block a user