forked from jaildesigner-jailgames/jaildoctors_dilemma
Clase item creada. Ya dibuja items en pantalla
This commit is contained in:
@@ -37,6 +37,12 @@ Room::~Room()
|
||||
delete enemy;
|
||||
}
|
||||
enemy_list.clear();
|
||||
|
||||
for (auto item : item_list)
|
||||
{
|
||||
delete item;
|
||||
}
|
||||
item_list.clear();
|
||||
}
|
||||
|
||||
// Carga las variables desde un fichero
|
||||
@@ -136,9 +142,9 @@ bool Room::load(std::string _file_path)
|
||||
// Si la linea contiene el texto [item] se realiza el proceso de carga de un item
|
||||
else if (line == "[item]")
|
||||
{
|
||||
// enemy_t enemy;
|
||||
// enemy.asset = asset;
|
||||
// enemy.renderer = renderer;
|
||||
item_t item;
|
||||
item.asset = asset;
|
||||
item.renderer = renderer;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -147,15 +153,15 @@ bool Room::load(std::string _file_path)
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
// Procesa las dos subcadenas
|
||||
// if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
//{
|
||||
// printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
// success = false;
|
||||
//}
|
||||
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
} while (line != "[item-end]");
|
||||
|
||||
// Añade el enemigo al vector de enemigos
|
||||
// enemy_list.push_back(new Enemy(enemy));
|
||||
// Añade el item al vector de items
|
||||
item_list.push_back(new Item(item));
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
@@ -298,6 +304,39 @@ bool Room::setEnemy(enemy_t *enemy, std::string _var, std::string _value)
|
||||
return success;
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura item_t
|
||||
bool Room::setItem(item_t *item, std::string _var, std::string _value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
if (_var == "tileset")
|
||||
{
|
||||
item->tileset = _value;
|
||||
}
|
||||
else if (_var == "x")
|
||||
{
|
||||
item->x = std::stof(_value) * BLOCK;
|
||||
}
|
||||
else if (_var == "y")
|
||||
{
|
||||
item->y = std::stof(_value) * BLOCK;
|
||||
}
|
||||
else if (_var == "tile")
|
||||
{
|
||||
item->tile = std::stof(_value);
|
||||
}
|
||||
else if (_var == "[item-end]")
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Devuelve el nombre de la habitación
|
||||
std::string Room::getName()
|
||||
{
|
||||
@@ -352,6 +391,15 @@ void Room::drawEnemies()
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja los objetos en pantalla
|
||||
void Room::drawItems()
|
||||
{
|
||||
for (auto item : item_list)
|
||||
{
|
||||
item->draw();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables y objetos de la habitación
|
||||
void Room::update()
|
||||
{
|
||||
@@ -416,11 +464,11 @@ int Room::getTile(SDL_Point point)
|
||||
bool Room::enemyCollision(SDL_Rect &rect)
|
||||
{
|
||||
bool collision = false;
|
||||
|
||||
|
||||
for (auto enemy : enemy_list)
|
||||
{
|
||||
collision |= checkCollision(rect, enemy->getCollider());
|
||||
}
|
||||
|
||||
|
||||
return collision;
|
||||
}
|
||||
Reference in New Issue
Block a user