Ya recuerda los items recogidos

This commit is contained in:
2022-08-27 16:39:44 +02:00
parent ce33b4e10c
commit 17b10a8fef
6 changed files with 47 additions and 22 deletions

View File

@@ -1,17 +1,19 @@
#include "map.h"
// Constructor
Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset)
Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, Item_tracker *itemTracker)
{
// Inicializa variables
tile_size = 8;
map_width = 40;
map_height = 26;
tileset_width = 32;
name = file.substr(file.find_last_of("\\/") + 1);
// Copia los punteros a objetos
this->asset = asset;
this->renderer = renderer;
this->itemTracker = itemTracker;
// Crea los objetos
texture_tile = new LTexture();
@@ -165,8 +167,12 @@ bool Map::load(std::string file_path)
} while (line != "[/diamond]");
printf("** actor diamond loaded\n\n");
actors.push_back(new ActorDiamond(actor));
// Comprueba si el actor no ha sido recogido previamente
if (!itemTracker->hasBeenPicked(name, {(int)actor.x, (int)actor.y}))
{
printf("** actor diamond loaded\n\n");
actors.push_back(new ActorDiamond(actor));
}
}
} while (line != "[/actors]");
@@ -578,4 +584,11 @@ bool Map::deleteActor(int index)
actors.erase(actors.begin() + index);
return success;
}
// Coge un item
void Map::getItem(int index)
{
const SDL_Rect r = getActorCollider(index);
itemTracker->addItem(name, {r.x, r.y});
}