Separados los elementos de la pantalla en diferentes texturas
This commit is contained in:
@@ -22,11 +22,11 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *it
|
||||
tileset_width = texture_tile->getWidth() / tile_size;
|
||||
|
||||
// Crea las texturas para dibujar el mapa
|
||||
map_layer0 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
map_layer0 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
if (map_layer0 == NULL)
|
||||
printf("Error: map_layer0 could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
|
||||
map_layer1 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
map_layer1 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
if (map_layer1 == NULL)
|
||||
printf("Error: map_layer1 could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
|
||||
@@ -428,7 +428,7 @@ void Map::fillMapTexture()
|
||||
// con lo que esta pintando desde fuera de la textura
|
||||
clip.x = ((tilemap_l0[(y * map_width) + x] - 1) % tileset_width) * tile_size;
|
||||
clip.y = ((tilemap_l0[(y * map_width) + x] - 1) / tileset_width) * tile_size;
|
||||
texture_tile->render(renderer, x * tile_size, (y * tile_size) + PLAY_AREA_TOP, &clip);
|
||||
texture_tile->render(renderer, x * tile_size, y * tile_size, &clip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ void Map::fillMapTexture()
|
||||
// con lo que esta pintando desde fuera de la textura
|
||||
clip.x = ((tilemap_l1[(y * map_width) + x] - 1) % tileset_width) * tile_size;
|
||||
clip.y = ((tilemap_l1[(y * map_width) + x] - 1) / tileset_width) * tile_size;
|
||||
texture_tile->render(renderer, x * tile_size, (y * tile_size) + PLAY_AREA_TOP, &clip);
|
||||
texture_tile->render(renderer, x * tile_size, y * tile_size, &clip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,14 +456,33 @@ void Map::fillMapTexture()
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Dibuja el mapa en pantalla
|
||||
// Dibuja todos los elementos del mapa
|
||||
void Map::render()
|
||||
{
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||
SDL_RenderCopy(renderer, map_layer0, &rect, NULL);
|
||||
SDL_RenderCopy(renderer, map_layer1, &rect, NULL);
|
||||
renderLayer0();
|
||||
renderLayer1();
|
||||
renderActors();
|
||||
}
|
||||
|
||||
// Dibuja la capa 0
|
||||
void Map::renderLayer0()
|
||||
{
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
|
||||
SDL_RenderCopy(renderer, map_layer0, NULL, &rect);
|
||||
}
|
||||
|
||||
// Dibuja la capa 1
|
||||
void Map::renderLayer1()
|
||||
{
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_Rect rect = {PLAY_AREA_X, PLAY_AREA_Y, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
|
||||
SDL_RenderCopy(renderer, map_layer1, NULL, &rect);
|
||||
}
|
||||
|
||||
// Dibuja los actores
|
||||
void Map::renderActors()
|
||||
{
|
||||
for (auto actor : actors)
|
||||
{
|
||||
actor->render();
|
||||
@@ -487,7 +506,7 @@ e_tile_map Map::getTile(SDL_Point p)
|
||||
const int y = std::max(getPlayArea(b_top), (std::min(p.y, getPlayArea(b_bottom) - 1)));
|
||||
|
||||
// Calcula el tile
|
||||
const int tile = collisionmap[(((y + PLAY_AREA_TOP) / tile_size) * map_width) + (x / tile_size)];
|
||||
const int tile = collisionmap[((y / tile_size) * map_width) + (x / tile_size)];
|
||||
|
||||
// Las 8 primeras filas son tiles de fondo
|
||||
if (tile == 0)
|
||||
|
||||
Reference in New Issue
Block a user