本文整理汇总了C++中sf::Sound类的典型用法代码示例。如果您正苦于以下问题:C++ Sound类的具体用法?C++ Sound怎么用?C++ Sound使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
sf::Sound * SoundsManager::createMusic(sf::Uint8 ID)
{
music.setBuffer(buffers[ID]);
music.setVolume(buffers[ID].defaultVolume * static_cast<float>(musicVolume) / 100.f);
return &music;
}
示例2: resetGame
void resetGame() {
std::cout << player.z << " " << tunnel.getLength() - 1 << std::endl;
if (player.z > tunnel.getLength() - 2 && player.score >= 5) difficulty++;
tunnel.reset((difficulty + 2) * 100, difficulty);
player.reset();
renderer.reset();
rockZ = ROCK_START_Z;
rockVel = ROCK_START_VEL;
musicSound.setPlayingOffset(sf::Time::Zero);
musicSound.play();
feetSound.play();
}
示例3: checkHealth
//Check player's health and start playing the heartbeat sound if bellow 20. If at 0 or below, player is dead and it's velocity is set to 0.
void Player::checkHealth(sf::Sound &heartbeat) {
if (this->health <= 20 && this->isDying == false) {
heartbeat.setLoop(true);
heartbeat.play();
this->isDying = true;
}
if (this->health <= 0) {
this->health = 0;
this->alive = false;
this->velocity = sf::Vector2f(0, 0);
}
}
示例4: init
void init() {
m_first_trip = false;
m_current_state = IDLE;
getBody()->GetFixtureList()->SetUserData("Checkpoint");
getBody()->SetUserData(this);
//Load Texture
s_texture = "Assets/Game/cp_ps.png";
m_text_size = sf::Vector2u(42, 94);
m_sprite.setTexture(ResourceManager<sf::Texture>::instance()->get(s_texture));
m_sprite.setOrigin(m_text_size.x / 2, m_text_size.y / 2);
m_sprite.setPosition(vHelper::toSF(getBody()->GetPosition()));
addFrames(frame_idle, 0, 0, 1, 42, 94, 1.0f);
addFrames(frame_trip, 1, 0, 5, 42, 94, 1.0f);
addFrames(frame_active, 2, 0, 3, 42, 94, 1.0f);
m_animator.addAnimation(IDLE, frame_idle, sf::seconds(1.0f));
m_animator.addAnimation(TRIP, frame_trip, sf::seconds(0.4f));
m_animator.addAnimation(ACTIVE, frame_active, sf::seconds(0.3f));
//Load Audio
s_noise = "Assets/Audio/Game/cp.wav";
m_noise.setBuffer(ResourceManager<sf::SoundBuffer>::instance()->get(s_noise));
}
示例5: width
Textbox::Textbox(std::map<std::string, sf::Sprite>& faceMap, const sf::Font& font, sf::Sound& bleep, int width_box, int height_box, bool block, int font_size, int padding) :
faceMap(faceMap), width(width_box), height(height_box), bleep(bleep), block_draw(block), padding(padding) {
displayText.setFont(font);
displayText.setCharacterSize(font_size);
displayText.setColor(sf::Color::White);
bleep.setPitch(2);
if (!block_draw)
{
faceSprite.setTextureRect(sf::IntRect(0, 0, faceSprite.getLocalBounds().width, faceSprite.getLocalBounds().height));
faceSprite.setOrigin(faceSprite.getLocalBounds().width*.5, faceSprite.getLocalBounds().height*.5);
faceSprite2.setTextureRect(sf::IntRect(0, 0, faceSprite2.getLocalBounds().width, faceSprite2.getLocalBounds().height));
faceSprite2.setOrigin(faceSprite2.getLocalBounds().width*.5, faceSprite2.getLocalBounds().height*.5);
rectText.setSize(sf::Vector2f(width - padding, height*.3));
rectText.setOrigin((width - padding)*.5, height*.5);
rectText.setFillColor(sf::Color::Black);
rectText.setOutlineColor(sf::Color::White);
rectText.setOutlineThickness(2);
actorName.setColor(sf::Color::Yellow);
actorName.setFont(font);
}
else {
rectText.setSize(sf::Vector2f(width, height));
rectText.setOrigin(width*.5, height*.5);
}
}
示例6: set_buzzer_tone
void ToneAlarm_SF::set_buzzer_tone(float frequency, float volume, float duration_ms)
{
if (frequency <= 0) {
return;
}
Synth::sTone tone;
tone.waveType = Synth::OSC_SQUARE;
tone.dStartFrequency = frequency;
tone.dEndFrequency = frequency;
tone.dAmplitude = 1;
envelope.dSustainTime = duration_ms/1000.0f;
Synth::generate(&soundBuffer, envelope, tone, 20000, 44100);
demoSound.setBuffer(soundBuffer);
demoSound.play();
}
示例7: playStream
void rawGenerator::playStream()
{
if (sw == 0){
if (!Buffer.loadFromSamples(waveOut, SAMPLES, 1, 44100)) {
std::cerr << "Loading failed!" << std::endl;
//return 1;
}
std::cout << "Sound 1" << std::endl;
sw = 0;
}
Sound.setBuffer(Buffer);
//Sound.setLoop(true);
Sound.play();
}
示例8: play_sound
void play_sound(sf::Sound& sound, const SoundSample& sample, const PlaybackProperties& properties, bool looped)
{
sound.setBuffer(sample);
sound.setPitch(properties.pitch);
sound.setAttenuation(properties.attenuation);
sound.setLoop(looped);
sound.setRelativeToListener(properties.relative_to_listener);
sound.setMinDistance(properties.min_distance);
sound.setVolume(properties.volume * 100.0f);
sound.play();
}
示例9: isdead
void Enemy::isdead(Enemy &foe,sf::Sound &death)
{
if (foe.health <= 0)
{
if (active == true)
{
death.play();
}
active = false;
foe.enemy.setPosition(-900, -100);
}
}
示例10: shoot
//Check the player's ammoDescription, create and initialize bullets accordinly. Push the created bullet to the bullets vector.
void Player::shoot(sf::RenderWindow &window, vector <Bullet *> &bullets, sf::Sound &laser) {
if(this->ammoDescription == "Red Rays of Happiness") {
Bullet *bullet = new Bullet(this->getPosition(), (sf::Vector2f) (window.mapPixelToCoords(sf::Mouse::getPosition(window))), sf::Color::Red, "player");
bullet->setDamage(this->damage);
bullet->setVelocity(sf::Vector2f(12, 12));
bullet->setScale(0.3, 0.3);
bullet->calculateRotation(window);
bullet->calculateDirection(window);
laser.play();
bullets.push_back(bullet);
}
if (this->ammoDescription == "Green Beams of Hurting") {
Bullet *bullet = new Bullet(this->getPosition(), (sf::Vector2f) (window.mapPixelToCoords(sf::Mouse::getPosition(window))), sf::Color::Green, "player");
bullet->setDamage(this->damage);
bullet->setVelocity(sf::Vector2f(14, 14));
bullet->setScale(0.4, 0.4);
bullet->calculateRotation(window);
bullet->calculateDirection(window);
laser.play();
bullets.push_back(bullet);
}
}
示例11: Entity
Entity(sf::Texture& sTexture, EntityType type, Collidable::Type colType, sf::SoundBuffer& soundBuf1, sf::SoundBuffer& soundBuf2)
: Collidable(colType)
, mSprite(sTexture)
, mDeathSound(soundBuf1)
, mLaserSound(soundBuf2)
, mType(type)
, mCollected(0)
, mFireProjectile(false)
, mFireCountdown(sf::Time::Zero)
{
sf::FloatRect bounds = mSprite.getLocalBounds();
mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
switch(type)
{
case EntityType::Player: mHitPoints = PlayerHitPoints; break;
case EntityType::Enemy: mHitPoints = EnemyHitPoints; break;
default: break;
}
mLaserSound.setVolume(75.f);
mDeathSound.setVolume(75.f);
};
示例12: Collision
void Collision(sf::RenderWindow &Window, sf::Sound &collision, sf::Shape player, sf::Shape &object)
{
if(player.GetPosition().x + PLAYERWIDTH < object.GetPosition().x ||
player.GetPosition().x > object.GetPosition().x + OBJECTWIDTH ||
player.GetPosition().y + PLAYERHEIGHT < object.GetPosition().y ||
player.GetPosition().y > object.GetPosition().y + OBJECTHEIGHT)
{
// No Collision
}
else
{
collision.Play();
object.SetPosition(rand() % (ScreenWidth - OBJECTWIDTH), rand() % (ScreenHeight - OBJECTHEIGHT));
}
}
示例13: isdead
bool Player::isdead(Player &character,sf::Sound &death, sf::RectangleShape &Lifebar)
{
deadimg.loadFromFile(resourcePath() + "deadplayer.png");
if(character.health <= 0)
{
if(character.active == true)
{
death.play();
}
character.player.setTexture(deadimg);
character.active = false;
Lifebar.setSize(sf::Vector2f(0,0));
}
return character.active;
}
示例14: Kolizja
void Kolizja(Swoj &player, Obcy &wrog, sf::Sound &kolizja, int &punkty, int &zycia){
if((player.pobierzX() < wrog.pobierzX() + SZEROBIEKTU &&
player.pobierzX() > wrog.pobierzX() &&
player.pobierzY() + WYSGRACZ/2 > wrog.pobierzY() &&
player.pobierzY() + WYSGRACZ/2 < wrog.pobierzY() + WYSOOBIEKTU)
||
(player.pobierzX() + SZERGRACZ > wrog.pobierzX() &&
player.pobierzX() + SZERGRACZ < wrog.pobierzX() + SZEROBIEKTU &&
player.pobierzY() + WYSGRACZ/2 > wrog.pobierzY() &&
player.pobierzY() + WYSGRACZ/2 < wrog.pobierzY() + WYSOOBIEKTU)
||
(player.pobierzX() + SZERGRACZ/2 > wrog.pobierzX() &&
player.pobierzX() + SZERGRACZ/2 < wrog.pobierzX() + SZEROBIEKTU &&
player.pobierzY() > wrog.pobierzY() &&
player.pobierzY() + WYSGRACZ < wrog.pobierzY() + WYSOOBIEKTU))
{
kolizja.Play();
player.x = player.startX;
player.y = player.startY;
--zycia;
} else {
if(player.pobierzX() + SZERGRACZ/2 > wrog.pobierzX() - 5 &&
player.pobierzX() + SZERGRACZ/2 < wrog.pobierzX() + SZEROBIEKTU + 5 &&
player.pobierzY() + WYSGRACZ > wrog.pobierzY() &&
player.pobierzY() < wrog.pobierzY() + WYSOOBIEKTU)
{
player.ZmusDoSkoku();
if(typeid(wrog) == typeid (Wrog)){
++punkty;
} else if(typeid(wrog) == typeid (Wrog_Lewy)){
punkty +=5;
} else
punkty +=10;
}
}
}
示例15: main
// Program entry point
int main(int argc, char ** argv) {
titleImg.loadFromFile("assets/title.png");
sf::SoundBuffer sb;
sb.loadFromFile("assets/avalanche.ogg");
boulderSound.setBuffer(sb);
boulderSound.setLoop(true);
boulderSound.play();
sf::SoundBuffer sb2;
sb2.loadFromFile("assets/death.ogg");
fallingSound.setBuffer(sb2);
fallingSound.setRelativeToListener(true);
sf::SoundBuffer sb3;
sb3.loadFromFile("assets/jump.wav");
jumpingSound.setBuffer(sb3);
jumpingSound.setRelativeToListener(true);
sf::SoundBuffer sb4;
sb4.loadFromFile("assets/POL-flash-run-short.wav");
musicSound.setBuffer(sb4);
musicSound.setRelativeToListener(true);
musicSound.setVolume(15.f);
musicSound.setLoop(true);
musicSound.play();
sf::SoundBuffer sb5;
sb5.loadFromFile("assets/footsteps.ogg");
feetSound.setRelativeToListener(true);
feetSound.setBuffer(sb5);
feetSound.setLoop(true);
feetSound.setVolume(50);
feetSound.play();
sf::SoundBuffer sb6;
sb6.loadFromFile("assets/bump.ogg");
bumpSound.setRelativeToListener(true);
bumpSound.setBuffer(sb6);
bumpSound.setVolume(40);
sf::SoundBuffer sb7;
sb7.loadFromFile("assets/gem.ogg");
gemSound.setRelativeToListener(true);
gemSound.setBuffer(sb7);
gemSound.setVolume(60);
sf::SoundBuffer sb8;
sb8.loadFromFile("assets/Powerup3.wav");
powerSound.setRelativeToListener(true);
powerSound.setBuffer(sb8);
powerSound.setVolume(80);
sf::SoundBuffer sb9;
sb9.loadFromFile("assets/alert.ogg");
alertSound.setRelativeToListener(true);
alertSound.setBuffer(sb9);
//powerSound.setVolume(80);
// Create the SFML window
window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "A Bolder Escape");
while (window.isOpen()) {
events();
if (!menu) logic();
render();
}
return 0;
}