public void playMusic() { music.setVolume(1); music.setLooping(true); if (music != null && !music.isPlaying()) { music.play(); } }
private void randomizeMusic() { int random; // If its not the first time randomizing if (currentMusic != -1) { random = rand.nextInt(musicFileNames.length - 1); // To make sure the same music dosen't play twice if (currentMusic <= random) { random++; } } else { random = rand.nextInt(musicFileNames.length); } if (music != null) { music.stop(); music.dispose(); } currentMusic = random; music = Gdx.audio.newMusic(Gdx.files.internal("audio/" + musicFileNames[random])); music.play(); music.setVolume(1); music.setOnCompletionListener( new OnCompletionListener() { @Override public void onCompletion(Music music) { randomizeMusic(); music.dispose(); } }); }
private void initMusic() { music = AssetsLoader.getMusic(); boolean musicOn = preferences.getBoolean("musicOn", true); float musicVolume = preferences.getFloat("musicVolume", 1); music.setLooping(true); if (musicOn) { music.play(); } music.setVolume(musicVolume); }
/** Sets the music volume which must be inside the range [0,1]. */ public void setVolume(float volume) { // check and set the new volume if (volume < 0 || volume > 1f) { throw new IllegalArgumentException("The volume must be inside the range: [0,1]"); } this.volume = volume; // if there is a music being played, change its volume if (musicBeingPlayed != null) { musicBeingPlayed.setVolume(volume); } }
/** * Plays the given music (starts the streaming). * * <p>If there is already a music being played it is stopped automatically. */ public void play(Music music) { // check if the music is enabled if (!enabled) return; // stop any music being played // stop(); // removing this solves the restart problem (if menu-music is added, maybe // it's needed again) // start streaming the new music musicBeingPlayed = music; musicBeingPlayed.setVolume(volume); musicBeingPlayed.setLooping(true); musicBeingPlayed.play(); }
/** Total reset */ public void reset() { clearLists(); ticks = 0; gameOverTicks = 0; soundEffects = !Specular.prefs.getBoolean("SoundsMuted"); particlesEnabled = Specular.prefs.getBoolean("Particles"); if (music != null) music.setVolume(1f); gameMode = new Ranked(this); enemiesKilled = 0; // Adding player and setting up input processor pss.spawn(false); shaken = false; gameInputProcessor = new GameInputProcessor(this); gameInputProcessor.reset(); input.setInputProcessor(gameInputProcessor); ggInputProcessor = new GameOverInputProcessor(game, this); pauseInputProcessor = new PauseInputProcessor(game, this); resetGameTime(); cs.resetCombo(); scoreMultiplier = 1; scoreMultiplierTimer = 0; boardshockCharge = 0; Bullet.maxBounces = 0; Bullet.setTwist(false); Bullet.setDamage(1); FireRateBoost.stacks = 0; // Refreshing upgrades refreshUpgrades(); waveNumber = 0; waveManager.resetGame(); currentWave = waveManager.getWave(waveNumber); }
public BaseLevel(GameScreen gameScreen) { m_GameScreen = gameScreen; m_Entities = new ArrayList<IEntity>(); m_BackgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("music/background.mp3")); m_BackgroundMusic.setVolume(gameScreen.m_Settings.m_BackgroundMusicVolume * 0.75f); m_BackgroundMusic.setLooping(true); m_BackgroundMusic.play(); m_ClockTick = Gdx.audio.newSound(Gdx.files.internal("music/tick.mp3")); m_Powerup = Gdx.audio.newSound(Gdx.files.internal("music/powerup.wav")); m_Crash = Gdx.audio.newSound(Gdx.files.internal("music/crash.mp3")); m_Wind = Gdx.audio.newSound(Gdx.files.internal("music/wind.mp3")); // title m_BorderTexture = new Texture(Gdx.files.internal("map/border.png")); m_BorderTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); TextureRegion borderRegion = new TextureRegion(m_BorderTexture, 0, 0, 800, 600); m_BorderSprite = new Sprite(borderRegion); m_BorderSprite.setColor(1, 1, 1, 0.5f); }
public void playSound(Sounds sound) { // This would work better with a switch case... if (soundOn) { if (sound == Sounds.Jump) { music.setVolume(.5f); jumpEffect.play(1); } if (sound == Sounds.Ding1) { music.setVolume(.5f); coin1.play(1); } if (sound == Sounds.Select) { music.setVolume(.5f); } if (sound == Sounds.Countdown) { music.setVolume(.5f); countdown.play(1); } if (sound == Sounds.Go) { music.setVolume(.5f); go.play(1); } if (sound == Sounds.Ding2) { music.setVolume(.5f); coin2.play(1); } if (sound == Sounds.Ding3) { music.setVolume(.5f); coin3.play(1); } if (sound == Sounds.Ding4) { music.setVolume(.5f); coin4.play(1); } } else { } }
protected void renderGame() { Gdx.gl.glClearDepthf(1f); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT); // Clearing screen, positioning camera, rendering map and entities // Positioning camera to the player Specular.camera.zoom = 1; Camera.setPosition(); Specular.camera.update(); // Rendering map and entities game.batch.setProjectionMatrix(Specular.camera.combined); game.batch.begin(); game.batch.setColor(1, 1, 1, 1); game.batch.draw( currentMap.getParallax(), -1024 + Camera.getCameraX() / 2, -1024 + Camera.getCameraY() / 2, 4096, 4096); game.batch.setColor(1, 1, 1, 1); Camera.setZoom(); BoardShock.setZoom(); Specular.camera.update(); game.batch.setProjectionMatrix(Specular.camera.combined); currentMap.render(game.batch, true); ScissorStack.calculateScissors( Specular.camera, game.batch.getTransformMatrix(), clipBounds, scissors); ScissorStack.pushScissors(scissors); if (tutorialOnGoing && tutorial.getCurrentWave().getEvent() == TutorialEvent.POWER_UPS_SHOWN) { if (!tutorial.enemiesHasSpawned()) { Util.writeCentered( game.batch, tutorial.getFont(), "these are power-ups", tutorial.getTextX(), tutorial.getTextY() + 200); if (tutorial.allPowerUpsActivated()) Util.writeCentered( game.batch, tutorial.getFont(), "some can be combined", tutorial.getTextX(), tutorial.getTextY()); } } for (Entity ent : entities) { if (!(ent instanceof Enemy)) ent.render(game.batch); } game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); for (UpgradeOrb orb : orbs) orb.render(game.batch); for (Particle p : particles) p.render(game.batch); game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); for (Entity ent : enemies) { ent.render(game.batch); } if (!gameMode.isGameOver()) player.render(game.batch); game.batch.flush(); ScissorStack.popScissors(); // Re-positioning camera for HUD Specular.camera.position.set(0, 0, 0); Specular.camera.zoom = 1; Specular.camera.update(); game.batch.setProjectionMatrix(Specular.camera.combined); if (isPaused) { // Pause menu game.batch.draw( greyPixel, -Specular.camera.viewportWidth / 2, -Specular.camera.viewportHeight / 2, Specular.camera.viewportWidth, Specular.camera.viewportHeight); game.batch.draw(pauseTex, -pauseTex.getWidth() / 2, 100); pauseInputProcessor.getResumeButton().render(); pauseInputProcessor.getToMenuButton().render(); } else { if (!gameMode.isGameOver()) { // Drawing HUD hud.render(game.batch, scoreMultiplierTimer); gameInputProcessor.getShootStick().render(game.batch); gameInputProcessor.getMoveStick().render(game.batch); // Tutorial if (tutorialOnGoing && !showTutorialEnd) tutorial.render(game.batch); // Drawing SCORE in the middle top of the screen Util.writeCentered( game.batch, scoreFont, player.getFormattedScore(), 0, Specular.camera.viewportHeight / 2 - 36); // Drawing MULTIPLIER on screen Util.writeCentered( game.batch, multiplierFont, "x" + Math.round(scoreMultiplier), 0, Specular.camera.viewportHeight / 2 - 98); // Tutorial end if (showTutorialEnd) { tutorialTicks++; if (tutorialTicks > 120) { scoreFontAlpha = (tutorialTicks - 120) / 180f; scoreFontAlpha = scoreFontAlpha > 1 ? 1 : scoreFontAlpha; game.batch.setColor(1, 1, 1, scoreFontAlpha); game.batch.draw( greyPixel, -Specular.camera.viewportWidth / 2, -Specular.camera.viewportHeight / 2, Specular.camera.viewportWidth, Specular.camera.viewportHeight); game.batch.setColor(Color.WHITE); scoreFont.setColor(1, 0, 0, scoreFontAlpha); Util.writeCentered(game.batch, scoreFont, "tap to continue", 0, -100); } } gameMode.render(game.batch); } else if (gameMode.isGameOver()) { // Game over screen // Manual camera shake Specular.camera.position.set(0, 0, 0); Specular.camera.position.add( rand.nextFloat() * 100 * Camera.getShakeIntensity(), rand.nextFloat() * 100 * Camera.getShakeIntensity(), 0); Specular.camera.update(); game.batch.setProjectionMatrix(Specular.camera.combined); game.batch.draw( greyPixel, -Specular.camera.viewportWidth / 2, -Specular.camera.viewportHeight / 2, Specular.camera.viewportWidth, Specular.camera.viewportHeight); game.batch.draw(gameOverTex, -gameOverTex.getWidth() / 2, -gameOverTex.getHeight() / 2); // Game Over effects [fade in, camera shake] if (gameOverScoreFont.getScaleX() > 1f) { gameOverScoreFont.scale(-0.1f); gameOverScoreFont.setColor( 1, 0, 0, Math.max((10 - gameOverScoreFont.getScaleX()) / 10f, 0)); } else { gameOverScoreFont.setScale(1); if (!shaken) { Camera.shake(0.5f, 0.02f); shaken = true; } if (player.getScore() >= lastHighscore) { Util.drawCentered(game.batch, newHighscore, 0, 0, 0); lastHighscore = player.getScore(); } } // Drawing final score and buttons if (music != null) music.setVolume(0.25f); if (gameOverTicks == GAMEOVERSOUND_TIMER && isSoundEnabled()) { gameOverSound.play(1f, 1, 0); } Util.writeCentered(game.batch, gameOverScoreFont, player.getFormattedScore(), 0, 100); game.batch.setColor(Color.WHITE); ggInputProcessor.getRetryBtn().render(); ggInputProcessor.getMenuBtn().render(); ggInputProcessor.getHighscoreBtn().render(); if (player.getUpgradePoints() >= 1) { if (!ggInputProcessor.isTouchingUpgradeBtn()) { if (gameOverTicks % 90 < 40) { ggInputProcessor.getUpgradeBtn().setScale(1.00f); ggInputProcessor.getUpgradeBtn().setTouch(true); } else { ggInputProcessor.getUpgradeBtn().setScale(1.0f); ggInputProcessor.getUpgradeBtn().setTouch(false); } } } ggInputProcessor.getUpgradeBtn().render(); } } game.batch.end(); }
public void setMusicVolume(float volume) { preferences.putFloat("musicVolume", volume); preferences.flush(); music.setVolume(volume); }
public void Update(float delta) { if (m_FadeIn < 1) { m_FadeIn += delta / 10; m_BackgroundMusic.setVolume(m_GameScreen.m_Settings.m_BackgroundMusicVolume * m_FadeIn); } // update and render the tilemap m_TiledMapRenderer.setView(m_GameScreen.m_Camera); m_TiledMapRenderer.render(); // update physics system m_PhysicsWorld.step(1f / 60f, 6, 2); // update and render the artemis entity system m_ArtemisWorld.setDelta(delta); m_ArtemisWorld.process(); m_SpineRenderSystem.process(); m_GameScreen.m_Camera.update(); m_GameScreen.GetSpriteBatch().setProjectionMatrix(m_GameScreen.m_Camera.combined); // update the player's light distance from watch float distance = 225; if (!m_WatchSpine.m_State.getAnimation().getName().contentEquals("tick")) { m_ClockTicking = false; } if (m_WatchSpine.m_State.getAnimation().getName().contentEquals("tick")) { if (!m_ClockTicking) { m_ClockTick.play(m_GameScreen.m_Settings.m_GameSoundVolume / 2); m_ClockTicking = true; } float time = m_WatchSpine.m_State.getTime(); if (time < 10.0f) { float timePercentageComplete = (10 - time) / 10.0f; distance += (timePercentageComplete * 300); m_LightPowerDistance = timePercentageComplete * 300; } } else if (m_WatchSpine.m_State.getAnimation().getName().contentEquals("wind")) { float time = m_WatchSpine.m_State.getTime(); float timePercentageComplete = time / m_WatchSpine.m_State.getAnimation().getDuration(); distance += (timePercentageComplete * 300); m_LightPowerDistance = timePercentageComplete * 300; } // update the players light distance sensor m_PlayerEntity .m_LightDistanceSensor .getShape() .setRadius((m_LightPowerDistance * WORLD_TO_BOX) / 2); if (m_PlayerEntity.m_Entity != null) { BodyComponent bodyComponent = m_PlayerEntity.m_Entity.getComponent(BodyComponent.class); if (bodyComponent != null) { bodyComponent.m_Light.setDistance(distance * WORLD_TO_BOX); } } // render the lighting m_RayHandler.setCombinedMatrix(m_GameScreen.m_Camera.combined.scl(BOX_TO_WORLD)); m_RayHandler.updateAndRender(); // draw border m_BorderSprite.setColor(1, 1, 1, m_FadeIn * 0.5f); m_BorderSprite.setPosition( m_GameScreen.m_Camera.position.x - 400, m_GameScreen.m_Camera.position.y - 300); m_GameScreen.GetSpriteBatch().begin(); m_BorderSprite.draw(m_GameScreen.GetSpriteBatch()); m_GameScreen.GetSpriteBatch().end(); // draw the vials m_VialOne.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialOne.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 375); m_VialOne.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 275); m_VialOne.m_Skeleton.getRootBone().setRotation(m_VialOne.m_Rotation); m_VialOne.m_State.update(Gdx.graphics.getDeltaTime()); m_VialOne.m_State.apply(m_VialOne.m_Skeleton); m_VialOne.m_Skeleton.updateWorldTransform(); m_VialTwo.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialTwo.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 305); m_VialTwo.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 275); m_VialTwo.m_Skeleton.getRootBone().setRotation(m_VialTwo.m_Rotation); m_VialTwo.m_State.update(Gdx.graphics.getDeltaTime()); m_VialTwo.m_State.apply(m_VialTwo.m_Skeleton); m_VialTwo.m_Skeleton.updateWorldTransform(); m_VialThree.m_Skeleton.getColor().set(1, 1, 1, m_FadeIn * 0.75f); m_VialThree.m_Skeleton.setX(m_GameScreen.m_Camera.position.x - 390); m_VialThree.m_Skeleton.setY(m_GameScreen.m_Camera.position.y - 205); m_VialThree.m_Skeleton.getRootBone().setRotation(m_VialThree.m_Rotation); m_VialThree.m_State.update(Gdx.graphics.getDeltaTime()); m_VialThree.m_State.apply(m_VialThree.m_Skeleton); m_VialThree.m_Skeleton.updateWorldTransform(); // draw watch last m_WatchSpine.m_Skeleton.setX(m_GameScreen.m_Camera.position.x + 300); m_WatchSpine.m_Skeleton.setY(m_GameScreen.m_Camera.position.y + 200); m_WatchSpine.m_State.update(Gdx.graphics.getDeltaTime()); m_WatchSpine.m_State.apply(m_WatchSpine.m_Skeleton); m_WatchSpine.m_Skeleton.updateWorldTransform(); m_GameScreen.GetSpriteBatch().begin(); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialOne.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialTwo.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_VialThree.m_Skeleton); m_SpineRenderSystem.m_Renderer.draw(m_GameScreen.GetSpriteBatch(), m_WatchSpine.m_Skeleton); m_GameScreen.GetSpriteBatch().end(); }
public static void setVolume(float value) { volume = value; if (music != null) music.setVolume(volume); }
public void setVolumeAll(float vol) { for (Object o : music.values()) { Music music = (Music) o; music.setVolume(vol); } }