Ya se pueden pillar los items. Falta llevar el control de los iterms conseguidos

This commit is contained in:
2022-07-12 19:33:09 +02:00
parent f8db0e3a90
commit 6152dc4255
12 changed files with 140 additions and 51 deletions

View File

@@ -259,11 +259,11 @@ bool Room::setEnemy(enemy_t *enemy, std::string _var, std::string _value)
}
else if (_var == "x")
{
enemy->x = std::stof(_value);
enemy->x = std::stof(_value) * BLOCK;
}
else if (_var == "y")
{
enemy->y = std::stof(_value);
enemy->y = std::stof(_value) * BLOCK;
}
else if (_var == "vx")
{
@@ -275,19 +275,19 @@ bool Room::setEnemy(enemy_t *enemy, std::string _var, std::string _value)
}
else if (_var == "x1")
{
enemy->x1 = std::stoi(_value);
enemy->x1 = std::stoi(_value) * BLOCK;
}
else if (_var == "x2")
{
enemy->x2 = std::stoi(_value);
enemy->x2 = std::stoi(_value) * BLOCK;
}
else if (_var == "y1")
{
enemy->y1 = std::stoi(_value);
enemy->y1 = std::stoi(_value) * BLOCK;
}
else if (_var == "y2")
{
enemy->y2 = std::stoi(_value);
enemy->y2 = std::stoi(_value) * BLOCK;
}
else if (_var == "color")
{
@@ -407,6 +407,11 @@ void Room::update()
{
enemy->update();
}
for (auto item : item_list)
{
item->update();
}
}
// Devuelve la cadena del fichero de la habitación contigua segun el borde
@@ -470,5 +475,22 @@ bool Room::enemyCollision(SDL_Rect &rect)
collision |= checkCollision(rect, enemy->getCollider());
}
return collision;
}
// Indica si hay colision con un objeto a partir de un rectangulo
bool Room::itemCollision(SDL_Rect &rect)
{
bool collision = false;
for (auto item : item_list)
{
collision |= checkCollision(rect, item->getCollider());
if (collision)
{
item->pick();
}
}
return collision;
}