Añadido el degradado de fondo al archivo de mapa

This commit is contained in:
2022-08-23 19:00:09 +02:00
parent 2425ab5142
commit f2ea31a564
8 changed files with 109 additions and 67 deletions

View File

@@ -167,6 +167,30 @@ bool Map::setVars(std::string var, std::string value)
{
tileset_img = value;
}
else if (var == "bgColor1")
{
// Se introducen los valores separados por comas en un vector
std::stringstream ss(value);
std::string tmp;
getline(ss, tmp, ',');
bgColor1.r = std::stoi(tmp);
getline(ss, tmp, ',');
bgColor1.g = std::stoi(tmp);
getline(ss, tmp, ',');
bgColor1.b = std::stoi(tmp);
}
else if (var == "bgColor2")
{
// Se introducen los valores separados por comas en un vector
std::stringstream ss(value);
std::string tmp;
getline(ss, tmp, ',');
bgColor2.r = std::stoi(tmp);
getline(ss, tmp, ',');
bgColor2.g = std::stoi(tmp);
getline(ss, tmp, ',');
bgColor2.b = std::stoi(tmp);
}
else if (var == "room_up")
{
room_up = value;
@@ -270,17 +294,14 @@ void Map::fillMapTexture()
// Dibuja el degradado de fondo
const int num_lines = 208;
const color_t color1 = {234, 171, 159};
const color_t color2 = {144, 225, 231};
for (int i = 0; i < num_lines; i++)
{
float step = ((float)i / (float)num_lines);
int r = color1.r + ((color2.r - color1.r) * step);
int g = color1.g + ((color2.g - color1.g) * step);
int b = color1.b + ((color2.b - color1.b) * step);
int r = bgColor1.r + ((bgColor2.r - bgColor1.r) * step);
int g = bgColor1.g + ((bgColor2.g - bgColor1.g) * step);
int b = bgColor1.b + ((bgColor2.b - bgColor1.b) * step);
SDL_SetRenderDrawColor(renderer, r, g, b, 0xFF);
SDL_RenderDrawLine(renderer, 0, i, 320, i);
SDL_RenderDrawLine(renderer, 0, i, 319, i);
}
// Dibuja el mapeado de tiles
@@ -343,7 +364,7 @@ e_tile_map Map::getTile(SDL_Point p)
// Normalizamos los puntos para que no busque fuera del mapa
const int x = std::max(getPlayArea(b_left), (std::min(p.x, getPlayArea(b_right) - 1)));
const int y = std::max(getPlayArea(b_top), (std::min(p.y, getPlayArea(b_bottom) - 1)));
// Calcula el tile
const int tile = tilemap[((y / tile_size) * map_width) + (x / tile_size)];
const int png_width = 32;