Añadido el sonido de coger objetos

This commit is contained in:
2022-08-31 20:59:52 +02:00
parent c18a13ec83
commit 0087815ced
5 changed files with 23 additions and 4 deletions

BIN
media/sound/item.ogg Normal file

Binary file not shown.

BIN
media/sound/item.wav Normal file

Binary file not shown.

View File

@@ -185,6 +185,8 @@ bool Director::setFileList()
asset->add("/media/items/items.png", bitmap); asset->add("/media/items/items.png", bitmap);
asset->add("/media/music/jd.ogg", music); asset->add("/media/music/jd.ogg", music);
asset->add("/media/sound/item.wav", sound);
return asset->check(); return asset->check();
} }

View File

@@ -15,6 +15,7 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTrac
texture = new LTexture(); texture = new LTexture();
load(file_path); load(file_path);
loadTextureFromFile(texture, asset->get(tileset), renderer); 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 // 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); mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
@@ -33,6 +34,8 @@ Room::~Room()
delete texture; delete texture;
texture = nullptr; texture = nullptr;
JA_DeleteSound(itemSound);
SDL_DestroyTexture(mapTexture); SDL_DestroyTexture(mapTexture);
mapTexture = nullptr; mapTexture = nullptr;
@@ -540,15 +543,27 @@ bool Room::enemyCollision(SDL_Rect &rect)
bool Room::itemCollision(SDL_Rect &rect) bool Room::itemCollision(SDL_Rect &rect)
{ {
bool collision = false; bool collision = false;
for (auto item : items) for (int i =0;i<items.size();i++)
{ {
if (checkCollision(rect, item->getCollider())) if (checkCollision(rect, items[i]->getCollider()))
{ {
item->pick(); itemTracker->addItem(name, items[i]->getPos());
itemTracker->addItem(name, item->getPos()); delete items[i];
items.erase(items.begin()+i);
JA_PlaySound(itemSound);
collision = true; 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; return collision;
} }

View File

@@ -7,6 +7,7 @@
#include "item.h" #include "item.h"
#include "item_tracker.h" #include "item_tracker.h"
#include "const.h" #include "const.h"
#include "jail_audio.h"
#include <string> #include <string>
#include <vector> #include <vector>
@@ -51,6 +52,7 @@ private:
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación 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 // Carga las variables desde un fichero
bool load(std::string file_path); bool load(std::string file_path);