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();
 }
Exemplo n.º 2
0
//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);
	}
}
Exemplo n.º 3
0
// 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;
}