当前位置: 首页>>代码示例>>C++>>正文


C++ Sound::play方法代码示例

本文整理汇总了C++中sf::Sound::play方法的典型用法代码示例。如果您正苦于以下问题:C++ Sound::play方法的具体用法?C++ Sound::play怎么用?C++ Sound::play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::Sound的用法示例。


在下文中一共展示了Sound::play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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();
}
开发者ID:lupuchard,项目名称:gamebase,代码行数:12,代码来源:main.cpp

示例2: trip

	/**
	*	@brief 
	*/
	void trip() override {
		setTrip(true);

		m_first_trip = true;
		m_noise.play();
		m_current_state = TRIP;
		m_animator.playAnimation(TRIP);
	}
开发者ID:Joshmoo2009,项目名称:FYP_1516_JoshMooney,代码行数:11,代码来源:Checkpoint.hpp

示例3: 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();
 }
开发者ID:mnewhouse,项目名称:tselements,代码行数:11,代码来源:sound_playback_controller.cpp

示例4: 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);
	}
}
开发者ID:Crowmoore,项目名称:T.E.A.R,代码行数:13,代码来源:Player.cpp

示例5: 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);
	}
}
开发者ID:niyazm,项目名称:2DShooter,代码行数:12,代码来源:Enemy_1.cpp

示例6: 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);
	}
}
开发者ID:Crowmoore,项目名称:T.E.A.R,代码行数:23,代码来源:Player.cpp

示例7: 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;
}
开发者ID:niyazm,项目名称:2DShooter,代码行数:16,代码来源:Player.cpp

示例8: 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();


}
开发者ID:laurensvr,项目名称:TI3A-AI,代码行数:18,代码来源:Sound1.cpp

示例9: 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();
}
开发者ID:KIrill-ka,项目名称:ardupilot,代码行数:18,代码来源:ToneAlarm_SF.cpp

示例10: handleMouseKeypress

void handleMouseKeypress(int key, int state, int x, int y)
{
    switch (key) {
		case GLUT_LEFT_BUTTON:
            if (state == 0 && pause==FALSE){
                if (gun0.bullet_number > 0) {
					gun0.bullet_number--;
					pistola.pushAnimation(animation(locRot(0,0,0,10,0,-10),100,std::chrono::system_clock::now()));
					pistola.pushAnimation(animation(locRot(0,0,0,-10,0,10),100,std::chrono::system_clock::now()+std::chrono::milliseconds(100)));
                    collisionCurse();
                }
				else 
				{
					sound.setBuffer(sound_youreempty);
					sound.play();
				}
            }
            break;
    }
}
开发者ID:licnep,项目名称:RangoShooter,代码行数:20,代码来源:main.cpp

示例11: update

	virtual void update(){
		
		sf::Event event;
        while (window->pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
            
            {
                window->close();
                has_ended = true;
                }
             
             if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
             
             {
				// has_ended = true;
				 
			 }
             
             if (dt > select_switch && event.type == sf::Event::KeyReleased )
             
             {
				
			if (	 event.key.code == sf::Keyboard::Up)
			
			{
				
						if(selector[0].getColor() == sf::Color(0,127,127))
					
					{
						selector[0].setColor(sf::Color(255,255,255)) ;
						selector[3].setColor(sf::Color(0,127,127)) ;
						
					}
					
					else
					
					{
				
				
				for(int i =1;i<4;i++)
					{
						if(selector[i].getColor() == sf::Color(0,127,127))
						{
							selector[i].setColor(sf::Color(255,255,255)) ;
							selector[i-1].setColor(sf::Color(0,127,127)) ;
							break;
							
						}
						
					}
			
			}
				
				 blip.play();
				 dt=0;
				 timer.restart();
				
			}
			
			if (	 event.key.code == sf::Keyboard::Down)
				
				{
					
					if(selector[3].getColor() == sf::Color(0,127,127))
					
					{
						selector[3].setColor(sf::Color(255,255,255)) ;
						selector[0].setColor(sf::Color(0,127,127)) ;
						
					}
					
					else
					{
					
					for(int i =0;i<3;i++)
					{
						if(selector[i].getColor() == sf::Color(0,127,127))
						{
							selector[i].setColor(sf::Color(255,255,255)) ;
							selector[i+1].setColor(sf::Color(0,127,127)) ;
							break;
							
						}
						
					}
					
				}
					
				 blip.play();
				 dt=0;
				 timer.restart();
			}
				
            
                
			}
		
	
//.........这里部分代码省略.........
开发者ID:TarasJan,项目名称:Sleepwalker,代码行数:101,代码来源:menu.cpp

示例12: logic

void logic() {
	sf::Time newTime = mainClock.getElapsedTime();
	sf::Time diff = newTime - prevTime;
	prevTime = newTime;
	float difff = diff.asMicroseconds() / 1000000.f;

	player.slowTime -= difff;
	if (player.slowTime > 1) difff /= player.slowTime;
	player.feather -= difff;
	if (player.feather < 0.0f && player.hasFeather) {
		sf::Text txt("Lavawalk expired", renderer.getFont());
		txt.setColor(sf::Color(255, 255, 0, 255));
		txt.setCharacterSize(36);
		renderer.addStatusText(txt);
		player.hasFeather = false;
		alertSound.play();
	}
	float difff2 = (difff + diff.asMicroseconds() / 1000000.f) / 2;

	int z1 = std::floor(player.z + 1.3);
	int z2 = std::floor(player.z + 0.9);
	int x1 = std::floor(player.x + 2.1);
	int x2 = std::floor(player.x + 1.9);

	if (rockZ > tunnel.getLength() - 1 && tunnel.hasBrickWall()) {
		//destroy bricks
		for (float i = -2; i <= 2; i += 0.1f) {
			for (float j = -2; j <= 2; j += 0.1f) {
				renderer.addParticles(1, sf::Color(108, 7, 7), sf::Vector3f(i, j, tunnel.getLength()));
			}
		}
		tunnel.breakWall();
	}

	if (player.fallen) {
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) {
			resetGame();
		}
		feetSound.stop();
		player.zVel -= difff * 10;
		if (player.zVel < 0) player.zVel = 0;

		if (rockZ > player.z) {
			static float parts = 0;
			parts += difff * 20;
			while(parts > 0) {
				renderer.addParticles(1, sf::Color(100, 50, 10), sf::Vector3f(rand() / (float)RAND_MAX * 2 - 1, 2, rockZ + 2));
				parts--;
			}
		}
	} else if (rockZ > player.z) {
		player.fallen = true;
		fallingSound.play();
		musicSound.pause();
		renderer.addParticles(10, sf::Color(255, 0, 0), sf::Vector3f(player.x, 2, player.z));
		player.y = -100;
	} else if (!(player.feather > 0) && (player.y < 0.01 && (tunnel.get(z1, x1) == 1 && tunnel.get(z2, x1) == 1 && tunnel.get(z1, x2) == 1 && tunnel.get(z2, x2) == 1))) {
		player.fallen = true;
		fallingSound.play();
		musicSound.pause();
		renderer.addParticles(10, sf::Color(255, 127, 0), sf::Vector3f(player.x, 3, player.z));

		/*
		sf::Text txt("Fail!", renderer.getFont());
		txt.setColor(sf::Color(255, 0, 0, 255));
		txt.setCharacterSize(36);
		renderer.addStatusText(txt);
		*/
	} else {
		if (!player.fallen && player.y < 0.3 && (tunnel.get(z1, x1) > 1 && tunnel.get(z2, x1) > 1 && tunnel.get(z1, x2) > 1 && tunnel.get(z2, x2) > 1)) {
			int rok = tunnel.get(z1, x1);
			if (rok != 5) {
				if (rok == 2)
					player.zVel = 1.5;
				else if (rok == 3)
					player.zVel = 3.5f;
				else if (rok == 4)
					player.zVel = 0.0f;
				bumpSound.play();
				tunnel.set(z1, x1, 0);
				renderer.addParticles(10, sf::Color(100, 100, 100), sf::Vector3f(player.x, 2, player.z));
			}
		} else if (!player.fallen && player.y > 0.3 && (tunnel.get(z1, x1 + 5) >= 1 && tunnel.get(z2, x1 + 5) >= 1 && tunnel.get(z1, x2 + 5) >= 1 && tunnel.get(z2, x2 + 5) >= 1)) {
			int gem = tunnel.get(z1, x1 + 5);
			if (gem <= 3) {
				player.score += gem;
				gemSound.play();
				if (gem == 1) {
					renderer.addParticles(5, sf::Color(200, 0, 0), sf::Vector3f(player.x, .5, player.z + 1));

					sf::Text txt("Ruby: +1", renderer.getFont());
					txt.setColor(sf::Color(255, 0, 0, 255));
					txt.setCharacterSize(36);
					renderer.addStatusText(txt);
				} else if (gem == 2) {
					renderer.addParticles(5, sf::Color(0, 255, 0), sf::Vector3f(player.x, .5, player.z + 1));

					sf::Text txt("Emerald: +2", renderer.getFont());
					txt.setColor(sf::Color(0, 255, 0, 255));
					txt.setCharacterSize(36);
//.........这里部分代码省略.........
开发者ID:lupuchard,项目名称:gamebase,代码行数:101,代码来源:main.cpp

示例13: while

int screen_1::Run(sf::RenderWindow &App)
{
    hop.setBuffer(hopFile);
    trucked.setBuffer(truckedFile);
    dunked.setBuffer(dunkedFile);
    
    // Clock
    sf:: Clock clock;
    sf::Time time;
    sf::Time delay;
    
    // Plays Intro
    intro.play();
    delay = intro.getDuration();
    
    time = clock.getElapsedTime();
    // Music
    while ( clock.getElapsedTime() <= delay )
    {
        //cout << "NO";
    }
    froggerTheme.setVolume(50);
    froggerTheme.play();
    clock.restart();
    
    sf::Event Event;
    
    bool Running = true;
    int sum = 0;// for log testing purposes
    int sum2 = 0;
    int sum3 = 0;
    int sum4 = 0;
    int sum5 = 0;
    int sum6 = 0;
    int sum7 = 0;
    int sum8 = 0;
    int sum9 = 0;
    int sum10 = 0;
    
    while (Running)
    {
        // Timer Rect and Clock
        double time = clock.getElapsedTime().asSeconds();
        
        if(time >= 1.5)
        {
            timeRect.width = timeRect.width - 2.383;
            timer.setTextureRect(timeRect);
            clock.restart();
        }
        
        if(timeRect.width <= 0)
        {
            frogOnLily1 = false;
            frogOnLily2 = false;
            frogOnLily3 = false;
            frogOnLily4 = false;
            frogOnLily5 = false;
            mainPlayer.setNumLives(3);
            rectSource.width = 115;
            life.setTextureRect(rectSource);
            occupied1.setPosition(-100, -100);
            occupied2.setPosition(-100, -100);
            occupied3.setPosition(-100, -100);
            occupied4.setPosition(-100, -100);
            occupied5.setPosition(-100, -100);
            froggerTheme.pause();
            clock.restart();
            timeRect.width = 143;
            timer.setTextureRect(timeRect);
            frogger.setPosition(320, 605);
            
            return 2;
        }
        // *********************************************************************
        // Creating the objects of Object class for continuous movement
        //
        // Object(double posX, double posY, double speed)
        // *********************************************************************
        // Trucks
        Object t1(130, 420,0.2 );
        Object t2(550, 290, 0.2);
        // Cars
        Object c1(-50, 420, 0.3);
        Object c2(280, 289, 0.2);
        Object c3(0, 289, 0.2);
        // Short Logs
        Object sl1(0, 125, 0.2);
        Object sl2(200, 61, 0.3);
        Object sl3(300, 8, 0.4);
        // Long Logs
        Object l1(799, 8.3, 0.4);
        Object l2(500, 125, 0.2);
        
        // Sets object's direction
        t1.moveRight(truck);
        t2.moveLeft(truck2);
        c1.moveRight(car);
        c2.moveLeft(car2);
        c3.moveLeft(car3);
//.........这里部分代码省略.........
开发者ID:EmilyGarcia,项目名称:Frogger,代码行数:101,代码来源:screen_1.hpp

示例14: 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;
}
开发者ID:lupuchard,项目名称:gamebase,代码行数:71,代码来源:main.cpp

示例15: update

void update(sf::RectangleShape floor[], sf::RectangleShape road[], int floorWidth, int floorHeightPosition, sf::Sprite& rrSprite, double &pos, bool &jumpStatus,
     bool& isoverlap, std::stringstream &ss, sf::Clock &clock, sf::Text &textTime, sf::Music& roadrunnerMusic, sf::Music& sanicMusic, sf::Sound& squawkSound, 
     bool& deathStatus, sf::Sprite& sanicSprite, sf::Sprite& sanicPowerupSprite, bool& sanicPowerupStatus, int& globalSpeed, sf::Time& sanicTime, bool& powerupSpawnStatus, 
     sf::Time& powerupSpawnTimer, sf::Sprite arrayOfObjectSprite[], bool& boulderSpawnStatus, int numObject, int objStop, sf::Sound& jumpSound, sf::RectangleShape backgroundbox[])
{
	//game timer
     if (!isoverlap)
	{
		sf::Time time1 = clock.getElapsedTime();
		ss.str(std::string());
		ss << setprecision(2) << fixed << static_cast<double>(time1.asSeconds());
		textTime.setString(ss.str().c_str());
	}

     // Return to roadrunner character
     if (clock.getElapsedTime() >= sanicTime && sanicPowerupStatus)
     {
          sanicMusic.pause();
          roadrunnerMusic.play();
          sanicPowerupStatus = false;
     }

     // How fast everything moves
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))         //sanic run speed
          globalSpeed = 100;
     else
          globalSpeed = 15;                                                                    //roadrunner run speed

     // Powerup spawner, checks every 10 seconds
     if (clock.getElapsedTime() >= powerupSpawnTimer)
     {
          powerupSpawnTimer += sf::seconds(10);                       //time to spawn for every consecutive powerup after the first
          powerupSpawnStatus = true;
     }

     // Powerup spawn chance
     if (powerupSpawnStatus)
     {
          if (rand() % 100 <= 33)                                 // 33% chance to spawn
          {
               sanicPowerupSprite.setScale(0.05, 0.05);
               sanicPowerupSprite.setPosition(floorWidth, 250);
          }
          powerupSpawnStatus = false;
     }

     // Sanicpowerup movement, how fast the icon moves
     if (sanicPowerupSprite.getPosition().x >= objStop)
          sanicPowerupSprite.move(-globalSpeed, 0);

     // Roadrunner and sanicpowerup collision
     if (overlap(rrSprite, sanicPowerupSprite) && !sanicPowerupStatus)
     {
          roadrunnerMusic.pause();
          sanicMusic.play();
          sanicPowerupStatus = true;
          sanicTime = clock.getElapsedTime() + sf::seconds(10);
          sanicPowerupSprite.setScale(0, 0);
     }

     //Infinite floor/road
     floor[0].move(-globalSpeed, 0);
     floor[1].move(-globalSpeed, 0);

     road[0].move(-globalSpeed, 0);
     road[1].move(-globalSpeed, 0);
     
     if (floor[0].getPosition().x <= -floorWidth)
	{
		floor[0].setPosition(0, floorHeightPosition);
		floor[1].setPosition(floorWidth, floorHeightPosition);

          road[0].setPosition(0, floorHeightPosition);
          road[1].setPosition(floorWidth, floorHeightPosition);
	}

     //backgroundbox, movement, infinite background
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))
     {
          backgroundbox[0].move(-globalSpeed / 2 + 10, 0);
          backgroundbox[1].move(-globalSpeed / 2 + 10, 0);
     }
     else
     {
          backgroundbox[0].move(-globalSpeed + 10, 0);
          backgroundbox[1].move(-globalSpeed + 10, 0);
     }

     if (backgroundbox[0].getPosition().x <= -floorWidth)
     {
          backgroundbox[0].setPosition(0, -100);
          backgroundbox[1].setPosition(floorWidth, -100);
     }
     
    
	// Roadrunner jump
     if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && rrSprite.getPosition().y >= 505)
	{
		jumpStatus = true;
          jumpSound.play();
//.........这里部分代码省略.........
开发者ID:DevelopersGuild,项目名称:bird-squad,代码行数:101,代码来源:main.cpp


注:本文中的sf::Sound::play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。