67 lines
1.2 KiB
C++
67 lines
1.2 KiB
C++
#include "item_tracker.h"
|
|
|
|
// Constructor
|
|
Item_tracker::Item_tracker()
|
|
{
|
|
}
|
|
|
|
// Destructor
|
|
Item_tracker::~Item_tracker()
|
|
{
|
|
}
|
|
|
|
// Comprueba si el objeto ya ha sido cogido
|
|
bool Item_tracker::hasBeenPicked(std::string name, SDL_Point pos)
|
|
{
|
|
}
|
|
|
|
// Añade el objeto a la lista de objetos cogidos
|
|
void Item_tracker::addItem(std::string name, SDL_Point pos)
|
|
{
|
|
// Primero busca si ya hay una entrada con ese nombre
|
|
const int index = findByName(name);
|
|
if (index != -1)
|
|
{
|
|
}
|
|
|
|
// En caso contrario crea la entrada
|
|
else
|
|
{
|
|
item_tracker_t item;
|
|
item.name = name;
|
|
item.pos.push_back(pos);
|
|
list.push_back(item);
|
|
}
|
|
}
|
|
|
|
// Busca una entrada en la lista por nombre
|
|
int Item_tracker::findByName(std::string name)
|
|
{
|
|
const int c = -1;
|
|
|
|
for (int i = 0; i < list.size(); i++)
|
|
{
|
|
if (list[i].name == name)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
// Busca una entrada en la lista por posición
|
|
int Item_tracker::findByPos(int index, SDL_Point pos)
|
|
{
|
|
const int c = -1;
|
|
|
|
for (int i = 0; i < list[index].pos.size(); i++)
|
|
{
|
|
if ((list[index].pos[i].x == pos.x) && (list[index].pos[i].y == pos.y))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return c;
|
|
} |