Ya sube cuestas pero no las baja

This commit is contained in:
2022-09-05 23:22:49 +02:00
parent b6cfe45872
commit ce8a4a8050
7 changed files with 156 additions and 43 deletions

View File

@@ -28,6 +28,12 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset
// Establece el color del borde
screen->setBorderColor(borderColor);
// Inicializa variables
tileSize = 8;
mapWidth = 32;
mapHeight = 16;
tilesetWidth = 20;
}
// Destructor
@@ -499,29 +505,36 @@ std::string Room::getRoom(int border)
}
// Devuelve el tipo de tile que hay en ese pixel
int Room::getTile(SDL_Point point)
tile_e Room::getTile(SDL_Point point)
{
int pos = ((point.y / 8) * 32) + (point.x / 8);
int tile = TILE_EMPTY;
const int maxTile = mapWidth * mapHeight;
const int pos = ((point.y / tileSize) * mapWidth) + (point.x / tileSize);
tile_e tile = t_empty;
if (pos < 512)
if (pos < maxTile)
{
// Los tiles entre el 1 y el 80 son solidos
if ((tilemap[pos] > 0) && (tilemap[pos] < 201))
// Las filas 0-7 son de tiles t_wall
if ((tilemap[pos] > 0) && (tilemap[pos] < 8 * tilesetWidth))
{
return TILE_SOLID;
return t_wall;
}
// Los tiles mayores de 80 son atravesables
if ((tilemap[pos] > 200) && (tilemap[pos] < 381))
// La fila 8 es de tiles t_slope_r
else if ((tilemap[pos] >= 8 * tilesetWidth) && (tilemap[pos] < 9 * tilesetWidth))
{
return TILE_TRAVESSABLE;
return t_slope_r;
}
// Los tiles mayores de 80 son atravesables
if ((tilemap[pos] > 380) && (tilemap[pos] < 400))
// La fila 9 es de tiles t_slope_l
else if ((tilemap[pos] >= 9 * tilesetWidth) && (tilemap[pos] < 10 * tilesetWidth))
{
return TILE_KILL;
return t_slope_l;
}
// Las filas 10-14 son de tiles t_passable
if ((tilemap[pos] >= 10 * tilesetWidth) && (tilemap[pos] < 15 * tilesetWidth))
{
return t_passable;
}
}
@@ -581,4 +594,30 @@ void Room::reLoadTexture()
int Room::getTileSize()
{
return 8;
}
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{
// Calcula la base del tile
int base = ((p.y / tileSize) * tileSize) + tileSize;
printf("base %i\n", base);
// Calcula cuanto se ha entrado en el tile horizontalmente
const int pos = (p.x % tileSize); // esto da un valor entre 0 y 7
printf("pos %i\n", base);
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
if (slope == t_slope_r)
{
base -= pos+1;
printf("base_R %i\n", base);
}
else
{
base -= (tileSize - pos);
printf("base_L %i\n", base);
}
return base;
}