Creadas las colisiones con los enemigos

This commit is contained in:
2022-07-11 14:18:30 +02:00
parent 4d41ef53f1
commit 4f6a99f670
14 changed files with 97 additions and 22 deletions

View File

@@ -84,13 +84,13 @@ bool Room::load(std::string _file_path)
// Si la linea contiene el texto [tilemap] se realiza el proceso de carga del fichero tmx
else if (line == "[tilemap]")
{
//printf("Loading tilemap...\n");
// printf("Loading tilemap...\n");
do
{
std::getline(file, line);
if (line.find(".tmx") != std::string::npos)
{
//printf("Reading file %s\n", asset->get(line).c_str());
// printf("Reading file %s\n", asset->get(line).c_str());
std::ifstream file2(asset->get(line)); // Abre el fichero tmx
if (file2.good())
{
@@ -103,10 +103,10 @@ bool Room::load(std::string _file_path)
do
{
std::getline(file2, line);
//printf("parsing: %s\n", line.c_str());
// printf("parsing: %s\n", line.c_str());
pos = line.find("data encoding");
//printf("pos: %i\n", pos);
// printf("pos: %i\n", pos);
} while (pos == std::string::npos);
@@ -116,12 +116,12 @@ bool Room::load(std::string _file_path)
std::getline(file2, line);
if (line != "</data>")
{
//printf("data: %s\n", line.c_str());
// printf("data: %s\n", line.c_str());
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
//printf("tile: %s\n", tmp.c_str());
// printf("tile: %s\n", tmp.c_str());
tilemap.push_back(std::stoi(tmp));
}
}
@@ -411,3 +411,16 @@ int Room::getTile(SDL_Point point)
return tile;
}
// Indica si hay colision con un enemigo a partir de un rectangulo
bool Room::enemyCollision(SDL_Rect &rect)
{
bool collision = false;
for (auto enemy : enemy_list)
{
collision |= checkCollision(rect, enemy->getCollider());
}
return collision;
}