Convertido el juego a mapas con tiles de 8x8

This commit is contained in:
2022-08-18 21:18:15 +02:00
parent c848a8b234
commit 6a5f0b3b46
6 changed files with 77 additions and 21 deletions

View File

@@ -23,9 +23,9 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset)
fillMapTexture();
// Inicializa variables
tile_width = 16;
map_width = 20;
map_height = 13;
tile_width = 16/2;
map_width = 20*2;
map_height = 13*2;
}
// Destructor
@@ -194,10 +194,10 @@ void Map::fillMapTexture()
texture_bg->render(renderer, 0, 0, &clip);
// Dibuja el mapeado de tiles
const int tile_size = 16;
const int tileset_width_in_tiles = 16;
const int map_width_in_tiles = 20;
const int map_height_in_tiles = 13;
const int tile_size = 16/2;
const int tileset_width_in_tiles = 16*2;
const int map_width_in_tiles = 20*2;
const int map_height_in_tiles = 13*2;
clip = {0, 0, tile_size, tile_size};
@@ -240,13 +240,13 @@ void Map::render()
t_tile_map Map::getTile(SDL_Point p)
{
const int tile = tilemap[((p.y / tile_width) * map_width) + (p.x / tile_width)];
const int png_width = 16;
const int png_width = 16*2;
if (tile >= 0 && tile < 4 * png_width)
if (tile >= 0 && tile < 4*2 * png_width)
{
return nothing;
}
else if (tile >= (4 * png_width) && tile < 8 * png_width)
else if (tile >= (4*2 * png_width) && tile < 8*2 * png_width)
{
return wall;
}