Ejemplo n.º 1
0
PulseAudioSystem::~PulseAudioSystem() {
	bRunning = false;
	if (bAttenuating) {
		qmWait.lock();
		bAttenuating = false;
		setVolumes();
		bool success = qwcWait.wait(&qmWait, 1000);
		if (! success) {
			qWarning("PulseAudio: Shutdown timeout when attempting to restore volumes.");
		}
		qmWait.unlock();
	}
	pa_threaded_mainloop_stop(pam);
	pa_context_disconnect(pacContext);
	pa_context_unref(pacContext);
	pa_threaded_mainloop_free(pam);
}
Ejemplo n.º 2
0
int Game::run() {

	getConfig();

	mainMenu.title = "";
	mainMenu.items = {
        "Play",
		"Options",
		"Exit"
	};

	pauseMenu.title = "";
	pauseMenu.items = {
        "Resume",
		"Options",
		"Exit"
	};

	optionsMenu.title = "options";
	optionsMenu.items = {
		"Key Mappings",
		"Music Volume",
		"SFX Volume",
		"Exit"
	};

	keysMenu.title = "";
	keysMenu.items = {
		"up",
		"down",
		"left",
		"right",
		"reload"
	};

	if(!mainMenu_texture.loadFromFile("Mainmenu.png")){
        exit (1);
	}

    if(!pauseMenu_texture.loadFromFile("Pausemenu.png")){
        exit (1);
	}

	if (!font.loadFromFile("sans.ttf")) {
		std::cerr << "Could not load font" << std::endl;
		return 1;
	}
	text.setFont(font);
	text.setCharacterSize(24);
	text.setFillColor(sf::Color::Black);

	textures.push_back(sf::Texture());
	textures[0].loadFromFile("enemy1.png");

	textures.push_back(sf::Texture());
	textures[1].loadFromFile("he_grenade.png");

	textures.push_back(sf::Texture());
	textures[2].loadFromFile("knife.png");

	textures.push_back(sf::Texture());
	textures[3].loadFromFile("magazine.png");

	loadMap(map_n);

	player.position = spawn_pos;

	if (!Gameover_texture.loadFromFile("GameOver.png")) {
        exit(1);
	}
	Gameover_picture.setTexture(Gameover_texture);
	Gameover_picture.setOrigin(400,300);

	if (!Victory_texture.loadFromFile("Victoryscreen.png")) {
        exit(1);
	}
	Victory_picture.setTexture(Victory_texture);
	Victory_picture.setOrigin(400,300);

	if (!crosshair_texture.loadFromFile("crosshair.png")) {
		exit(1);
	}

	if (!gunshot_sample.loadFromFile("pistol.wav")) {
		exit(1);
	}
	gunshot_sound.setBuffer(gunshot_sample);

	if (!reload_sample.loadFromFile("reload.wav")) {
		exit(1);
	}
	reload_sound.setBuffer(reload_sample);

	if (!knife_sample.loadFromFile("knife.wav")) {
		exit(1);
	}
	knife_sound.setBuffer(knife_sample);

	if (!zombies_sample.loadFromFile("zombies.wav")) {
        exit(1);
    }
    zombies_sound.setBuffer(zombies_sample);

	if (!game_over_sample.loadFromFile("game_over.wav")) {
		exit(1);
	}
	game_over_sound.setBuffer(game_over_sample);

    if (!menu_choose_sample.loadFromFile("menu_choose.wav")) {
        exit(1);
    }
    menu_choose_sound.setBuffer(menu_choose_sample);

    if (!hurt_sample.loadFromFile("hurt.wav")) {
        exit (1);
    }
    hurt_sound.setBuffer(hurt_sample);

    if (!death_scream_sample.loadFromFile("death_scream.wav")) {
        exit (1);
    }
    death_scream_sound.setBuffer(death_scream_sample);

    if (!zombie_death_sample.loadFromFile("zombie_death.wav")) {
        exit (1);
    }
    zombie_death_sound.setBuffer(zombie_death_sample);

	//if(!mainMenu_music.openFromFile("re_your_brains.ogg")) {
    //    exit (1);
    //}
    //mainMenu_music.setLoop(true);
	setVolumes();
    //mainMenu_music.play();


	if (!music.openFromFile("music.ogg")) {
        exit(1);
    }
	music.setLoop(true);

    if (!gameOver_music.openFromFile("death_music.ogg")) {
        exit(1);
    }

    if (!victory_music.openFromFile("victory_song.ogg")) {
        exit(1);
    }

	crosshair.setTexture(crosshair_texture);
	sf::Vector2u crosshair_size = crosshair_texture.getSize();
	crosshair.setOrigin(crosshair_size.x/2, crosshair_size.y/2);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) {
                window.close();
			} else {
				switch (game_state) {
					case Playing:
						playingHandleEvent(event);
						break;
					case KeysMenu:
						keysMenuHandleEvent(event);
						break;
					case MapEditor:
						mapEditorHandleEvent(event);
						break;
                    case MainMenu:
                        mainMenuHandleEvent(event);
                        break;
                    case PauseMenu:
                        pauseMenuHandleEvent(event);
                        break;
                    case GameOver:
                        gameOverHandleEvent(event);
                        break;
                    case OptionsMenu:
                        optionsMenuHandleEvent(event);
                        break;
					default:
						std::cerr << "error: game state not found" << std::endl;
						window.close();
				}
			}
        }
		if (game_state != next_game_state) {
			for (auto &enemy : enemies) {
				enemy.pause();
			}
		}
		game_state = next_game_state;

		switch (game_state) {
			case Playing:
			    mainMenu_music.stop();
				playingLoop();
				break;
			case KeysMenu:
				keysMenuLoop();
				break;
			case MapEditor:
				mapEditorLoop();
				break;
            case MainMenu:
                mainMenuLoop();
                break;
            case PauseMenu:
                pauseMenuLoop();
                break;
			case GameOver:
				gameOverLoop();
				//mainMenu_music.play();
				break;
            case OptionsMenu:
                optionsMenuLoop();
                break;
			default:
				std::cerr << "error: game state not found" << std::endl;
				window.close();
		}

        window.display();

		fps_count += 1;
		if (clock.getElapsedTime() > second_timer) {
			const float sample_rate = 2;
			last_fps_count = fps_count * sample_rate;
			//std::cout << last_fps_count << std::endl;
			fps_count = 0;
			second_timer = clock.getElapsedTime() + sf::milliseconds(1000/sample_rate);
			last_spent_in_a = spent_in_a;
			last_spent_in_b = spent_in_b;
			spent_in_a = sf::Time();
			spent_in_b = sf::Time();
		}
    }
	saveConfig();

	return 0;
}
Ejemplo n.º 3
0
void VolumeFader::setVolume(float theTargetVolume, unsigned theFadeDurationFrames) {
    std::vector<float> targetVolumes(_myCurrentVolumes.size(), theTargetVolume);
    setVolumes(targetVolumes, theFadeDurationFrames);
}