diff --git a/media/sound/item.ogg b/media/sound/item.ogg new file mode 100644 index 0000000..9da2832 Binary files /dev/null and b/media/sound/item.ogg differ diff --git a/media/sound/item.wav b/media/sound/item.wav new file mode 100644 index 0000000..b01c68f Binary files /dev/null and b/media/sound/item.wav differ diff --git a/source/director.cpp b/source/director.cpp index 6a2e4ba..5f5c158 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -185,6 +185,8 @@ bool Director::setFileList() asset->add("/media/items/items.png", bitmap); asset->add("/media/music/jd.ogg", music); + + asset->add("/media/sound/item.wav", sound); return asset->check(); } diff --git a/source/room.cpp b/source/room.cpp index deacbfc..0304c11 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -15,6 +15,7 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTrac texture = new LTexture(); load(file_path); loadTextureFromFile(texture, asset->get(tileset), renderer); + itemSound = JA_LoadSound(asset->get("item.wav").c_str()); // Crea la textura para el mapa de tiles de la habitación mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); @@ -33,6 +34,8 @@ Room::~Room() delete texture; texture = nullptr; + JA_DeleteSound(itemSound); + SDL_DestroyTexture(mapTexture); mapTexture = nullptr; @@ -540,15 +543,27 @@ bool Room::enemyCollision(SDL_Rect &rect) bool Room::itemCollision(SDL_Rect &rect) { bool collision = false; - for (auto item : items) + for (int i =0;igetCollider())) + if (checkCollision(rect, items[i]->getCollider())) { - item->pick(); - itemTracker->addItem(name, item->getPos()); + itemTracker->addItem(name, items[i]->getPos()); + delete items[i]; + items.erase(items.begin()+i); + JA_PlaySound(itemSound); collision = true; } } + //for (auto item : items) + //{ + // if (checkCollision(rect, item->getCollider())) + // { + // itemTracker->addItem(name, item->getPos()); + // item->pick(); + // JA_PlaySound(itemSound); + // collision = true; + // } + //} return collision; } \ No newline at end of file diff --git a/source/room.h b/source/room.h index 25cdb97..dcd0f89 100644 --- a/source/room.h +++ b/source/room.h @@ -7,6 +7,7 @@ #include "item.h" #include "item_tracker.h" #include "const.h" +#include "jail_audio.h" #include #include @@ -51,6 +52,7 @@ private: ItemTracker *itemTracker; // Lleva el control de los objetos recogidos SDL_Renderer *renderer; // El renderizador de la ventana SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación + JA_Sound itemSound; // Sonido producido al coger un objeto // Carga las variables desde un fichero bool load(std::string file_path);