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;

View File

@@ -44,6 +44,8 @@ private:
LTexture *texture_tile; // Textura con los graficos de los tiles habitación
SDL_Texture *map_texture; // Textura para dibujar el mapa de la habitación
std::vector<Enemy *> enemy_list; // Listado con los enemigos de la habitación
color_t bgColor1; // Color superior del degradado de fondo
color_t bgColor2; // Color inferior del degradado de fondo
int tile_size; // Ancho del tile en pixels
int map_width; // Ancho del mapa en tiles

View File

@@ -16,7 +16,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
sprite = new AnimatedSprite(texture, renderer, asset->get("intro.ani"));
sprite->setCurrentAnimation("menu");
text = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
music = JA_LoadMusic(asset->get("music_title.ogg").c_str());
music = JA_LoadMusic(asset->get("music_title.ogg").c_str());
// Inicializa variables
section = {SECTION_PROG_TITLE, 0};
@@ -44,7 +44,7 @@ Title::~Title()
delete text;
text = nullptr;
JA_DeleteMusic(music);
JA_DeleteMusic(music);
}
// Actualiza las variables
@@ -88,9 +88,7 @@ void Title::render()
// Dibuja los objetos
sprite->render();
//text->writeCentered(160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1);
const color_t color = {179,83,71};
text->writeDX(TXT_CENTER|TXT_COLOR,160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, 160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1, {255, 93, 4});
// Vuelca el contenido del renderizador en pantalla
screen->blit();
@@ -99,8 +97,8 @@ void Title::render()
// Bucle principal
section_t Title::run()
{
JA_PlayMusic(music);
JA_PlayMusic(music);
while (section.name == SECTION_PROG_TITLE)
{
update();
@@ -109,5 +107,5 @@ section_t Title::run()
return section;
JA_StopMusic();
JA_StopMusic();
}