forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya lleva la cuenta de los objetos recogidos
This commit is contained in:
@@ -4,11 +4,15 @@
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
Room::Room(std::string _file_path, SDL_Renderer *_renderer, Asset *_asset)
|
||||
Room::Room(std::string _file_path, SDL_Renderer *_renderer, Asset *_asset, Item_tracker *_item_tracker)
|
||||
{
|
||||
texture = new LTexture();
|
||||
// Copia los punteros a objetos
|
||||
asset = _asset;
|
||||
renderer = _renderer;
|
||||
item_tracker = _item_tracker;
|
||||
|
||||
// Crea los objetos
|
||||
texture = new LTexture();
|
||||
load(_file_path);
|
||||
loadTextureFromFile(texture, asset->get(tileset), renderer);
|
||||
|
||||
@@ -161,7 +165,11 @@ bool Room::load(std::string _file_path)
|
||||
} while (line != "[item-end]");
|
||||
|
||||
// Añade el item al vector de items
|
||||
item_list.push_back(new Item(item));
|
||||
const SDL_Point itemPos = {item.x, item.y};
|
||||
if (!item_tracker->hasBeenPicked(name, itemPos))
|
||||
{
|
||||
item_list.push_back(new Item(item));
|
||||
}
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
@@ -479,17 +487,18 @@ bool Room::enemyCollision(SDL_Rect &rect)
|
||||
}
|
||||
|
||||
// Indica si hay colision con un objeto a partir de un rectangulo
|
||||
SDL_Point Room::itemCollision(SDL_Rect &rect)
|
||||
bool Room::itemCollision(SDL_Rect &rect)
|
||||
{
|
||||
SDL_Point p = {-1, -1};
|
||||
bool collision = false;
|
||||
for (auto item : item_list)
|
||||
{
|
||||
if (checkCollision(rect, item->getCollider()))
|
||||
{
|
||||
item->pick();
|
||||
p = item->getPos();
|
||||
item_tracker->addItem(name, item->getPos());
|
||||
collision = true;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
return collision;
|
||||
}
|
||||
Reference in New Issue
Block a user