void Sound::playSfx(const std::string &path, int x, int y) { if (!mInstalled || path.empty() || !mPlayBattle) return; std::string tmpPath; if (!path.compare(0, 4, "sfx/")) tmpPath = path; else tmpPath = paths.getValue("sfx", "sfx/") + path; ResourceManager *resman = ResourceManager::getInstance(); SoundEffect *sample = resman->getSoundEffect(tmpPath); if (sample) { logger->log("Sound::playSfx() Playing: %s", path.c_str()); int vol = 120; if (player_node && (x > 0 || y > 0)) { int dx = player_node->getTileX() - x; int dy = player_node->getTileY() - y; if (dx < 0) dx = -dx; if (dy < 0) dy = -dy; int dist = dx > dy ? dx : dy; if (dist * 8 > vol) return; vol -= dist * 8; } sample->play(0, vol); } }
void Sound::playSfx(const std::string &path) { if (!mInstalled || path.empty()) return; ResourceManager *resman = ResourceManager::getInstance(); SoundEffect *sample = resman->getSoundEffect( paths.getStringValue("sfx") + path); if (sample) { logger->log("Sound::playSfx() Playing: %s", path.c_str()); sample->play(0, 120); } }
void Sound::playGuiSfx(const std::string &path) { if (!mInstalled || path.empty() || !mPlayGui) return; std::string tmpPath; if (!path.compare(0, 4, "sfx/")) tmpPath = path; else tmpPath = paths.getValue("sfx", "sfx/") + path; ResourceManager *resman = ResourceManager::getInstance(); SoundEffect *sample = resman->getSoundEffect(tmpPath); if (sample) { logger->log("Sound::playGuiSfx() Playing: %s", path.c_str()); int ret = sample->play(0, 120, mGuiChannel); if (ret != -1) mGuiChannel = ret; } }