Trabajando en las colisiones

This commit is contained in:
2022-08-16 13:54:22 +02:00
parent 77980a4d70
commit a941f72208
7 changed files with 140 additions and 20 deletions

View File

@@ -21,6 +21,11 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset)
// Pinta el mapa de la habitación en la textura
fillMapTexture();
// Inicializa variables
tile_width = 16;
map_width = 20;
map_height = 13;
}
// Destructor
@@ -185,7 +190,7 @@ void Map::fillMapTexture()
SDL_RenderClear(renderer);
// Dibuja la textura de fondo
SDL_Rect clip = {0, 0, 320, 240-32};
SDL_Rect clip = {0, 0, 320, 240 - 32};
texture_bg->render(renderer, 0, 0, &clip);
// Dibuja el mapeado de tiles
@@ -195,7 +200,7 @@ void Map::fillMapTexture()
const int map_height_in_tiles = 13;
clip = {0, 0, tile_size, tile_size};
for (int y = 0; y < map_height_in_tiles; y++)
for (int x = 0; x < map_width_in_tiles; x++)
{
@@ -213,4 +218,23 @@ void Map::render()
// Dibuja la textura con el mapa en pantalla
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
SDL_RenderCopy(renderer, map_texture, &rect, NULL);
}
// Devuelve el tipo de tile que hay en un punto
t_tile_map Map::getTile(SDL_Point p)
{
const int tile = tilemap[((p.y / tile_width) * map_width) + (p.x / tile_width)];
if (tile > 0 && tile < 4 * map_width * tile_width)
{
return nothing;
}
else if (tile > (4 * map_width * tile_width) && tile < 8 * map_width * tile_width)
{
return wall;
}
else
{
return travessable;
}
}