Added music (no sounds yet)
Fixed translation mistake
This commit is contained in:
parent
b66979508c
commit
53b9b6bb14
File diff suppressed because one or more lines are too long
@ -857,8 +857,9 @@ int layout unlock_message 0x7f0a0041
|
||||
int layout world_button 0x7f0a0042
|
||||
int layout worlds 0x7f0a0043
|
||||
int mipmap ic_launcher 0x7f0b0000
|
||||
int raw background 0x7f0c0000
|
||||
int raw ramp 0x7f0c0001
|
||||
int raw music_game 0x7f0c0000
|
||||
int raw music_menu 0x7f0c0001
|
||||
int raw ramp 0x7f0c0002
|
||||
int string abc_action_bar_home_description 0x7f0d0000
|
||||
int string abc_action_bar_home_description_format 0x7f0d0001
|
||||
int string abc_action_bar_home_subtitle_description_format 0x7f0d0002
|
||||
|
@ -92,8 +92,6 @@ public class GameActivity extends Activity implements ExceptionHandler, User.LvU
|
||||
|
||||
soundManager = new SoundManager(this);
|
||||
soundManager.setSoundOn(dataStorageHandler.readIsSoundOn());
|
||||
soundManager.backgroundMusic.getPlayer().setLooping(true);
|
||||
soundManager.backgroundMusic.start();
|
||||
|
||||
levelManager = new LevelManager(this, dataStorageHandler);
|
||||
tutorialManager = new TutorialManager(this);
|
||||
|
@ -106,6 +106,8 @@ public class Game extends Rendering<GameScene> {
|
||||
}
|
||||
|
||||
public void countdownFinished() {
|
||||
GameLog.i("Start music");
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().gameMusic);
|
||||
gameState = GameState.RUNNING;
|
||||
}
|
||||
|
||||
@ -203,6 +205,7 @@ public class Game extends Rendering<GameScene> {
|
||||
public void tryToPause() {
|
||||
if (gameState == GameState.GAME_OVER || gameState == GameState.LEVEL_FINISHED || gameState == GameState.PAUSED)
|
||||
return;
|
||||
gameActivity.getSoundManager().gameMusic.pause();
|
||||
viewManager.showShortMenu();
|
||||
if (gameState == GameState.COUNTDOWN)
|
||||
viewManager.stopCountdown();
|
||||
@ -227,6 +230,8 @@ public class Game extends Rendering<GameScene> {
|
||||
}
|
||||
|
||||
public void onGameOver(boolean playerExplode) {
|
||||
gameActivity.getSoundManager().gameMusic.pause();
|
||||
//TODO: Die sound
|
||||
if (playerExplode) {
|
||||
scene.getUncategorizedEntities().remove(player);
|
||||
DestroyEffect.EXPLOSION.createEffect(particleSystem, player.getPosition(),
|
||||
@ -237,6 +242,9 @@ public class Game extends Rendering<GameScene> {
|
||||
}
|
||||
|
||||
private void onGoalReached() {
|
||||
gameActivity.getSoundManager().gameMusic.pause();
|
||||
//TODO: Goal + firework sound
|
||||
|
||||
gameState = GameState.LEVEL_FINISHED;
|
||||
if (!level.isFinished())
|
||||
gameActivity.getUser().gainLvFinishedEp();
|
||||
|
@ -24,6 +24,8 @@ public class GLTestScreen extends GLScreen<RelativeLayout> {
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
glView.setCurrentRendering(rendering);
|
||||
}
|
||||
|
||||
|
@ -29,15 +29,18 @@ public class GameScreen extends GLScreen<RelativeLayout> {
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(null);
|
||||
gameActivity.getSoundManager().menuMusic.reset();
|
||||
|
||||
glView.setCurrentRendering(game);
|
||||
game.getViewManager().prepareToBeShown();
|
||||
}
|
||||
game.getViewManager().prepareToBeShown();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
game.tryToPause();
|
||||
}
|
||||
|
||||
public void setGamePausedWithoutMenu(){
|
||||
public void setGamePausedWithoutMenu() {
|
||||
game.pauseWithoutMenu();
|
||||
}
|
||||
|
||||
@ -52,7 +55,7 @@ public class GameScreen extends GLScreen<RelativeLayout> {
|
||||
@Override
|
||||
public void onBackKeyDown() {
|
||||
game.tryToPause();
|
||||
if(isLevelFinished())
|
||||
if (isLevelFinished())
|
||||
game.onGoalMessageKeyBack();
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,8 @@ public class LevelsScreen extends Screen<LinearLayout> implements LevelButtonOnC
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
topBar.update();
|
||||
build();
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ public class PlayerShapeShopScreen extends Screen<RelativeLayout> implements Pla
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
createViews();
|
||||
topBar.update();
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ public class SettingsScreen extends Screen<LinearLayout> implements View.OnClick
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
topBar.update();
|
||||
soundToggle.setChecked(gameActivity.getSoundManager().isSoundOn());
|
||||
resetButton.setEnabled(super.caller != ScreenType.GAME);
|
||||
|
@ -61,6 +61,8 @@ public class StartScreen extends GLScreen<RelativeLayout> implements View.OnClic
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
glView.setCurrentRendering(rendering);
|
||||
((StartScene) rendering.getScene()).randomizeWorld();
|
||||
((StartScene) rendering.getScene()).loadTexturesForCurrentWorld();
|
||||
|
@ -87,6 +87,8 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
topBar.update();
|
||||
slotSettings.unlockSlotsIfLevelReached(gameActivity.getUser().getLevelUpBounties());
|
||||
onToolOfferSlotSelected(toolOfferSlots.get(0));
|
||||
|
@ -42,6 +42,8 @@ public class WorldsScreen extends Screen<RelativeLayout> implements WorldButtonO
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
gameActivity.getSoundManager().setCurrentMusic(gameActivity.getSoundManager().menuMusic);
|
||||
|
||||
topBar.update();
|
||||
for (WorldButton button : worldButtons)
|
||||
button.update();
|
||||
|
@ -33,9 +33,11 @@ public class Music {
|
||||
|
||||
public void pause() {
|
||||
try {
|
||||
player.pause();
|
||||
paused = true;
|
||||
pausedPosition = player.getCurrentPosition();
|
||||
if (!paused) {
|
||||
player.pause();
|
||||
paused = true;
|
||||
pausedPosition = player.getCurrentPosition();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handler.onException(e);
|
||||
}
|
||||
@ -53,7 +55,8 @@ public class Music {
|
||||
|
||||
public void stop() {
|
||||
try {
|
||||
player.pause();
|
||||
if (!paused)
|
||||
player.pause();
|
||||
player.seekTo(0);
|
||||
paused = true;
|
||||
} catch (Exception e) {
|
||||
@ -73,6 +76,14 @@ public class Music {
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
try {
|
||||
player.seekTo(0);
|
||||
} catch (Exception e) {
|
||||
handler.onException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public MediaPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
@ -18,19 +18,34 @@ public class SoundManager {
|
||||
private SoundPool soundPool;
|
||||
private boolean soundOn;
|
||||
|
||||
public final Music backgroundMusic;
|
||||
public final Music menuMusic;
|
||||
public final Music gameMusic;
|
||||
private Music currentMusic;
|
||||
|
||||
public SoundManager(GameActivity activity) {
|
||||
this.context = activity;
|
||||
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
|
||||
|
||||
backgroundMusic = new Music(activity, activity, R.raw.background);
|
||||
menuMusic = new Music(activity, activity, R.raw.music_menu);
|
||||
menuMusic.getPlayer().setLooping(true);
|
||||
gameMusic = new Music(activity, context, R.raw.music_game);
|
||||
gameMusic.getPlayer().setLooping(true);
|
||||
ToolType.loadAllPlacingSounds(this);
|
||||
}
|
||||
|
||||
public void setCurrentMusic(Music music) {
|
||||
if (currentMusic != null && !currentMusic.equals(music)) {
|
||||
currentMusic.pause();
|
||||
}
|
||||
this.currentMusic = music;
|
||||
if (music != null)
|
||||
currentMusic.start();
|
||||
}
|
||||
|
||||
public void setSoundOn(boolean on) {
|
||||
this.soundOn = on;
|
||||
backgroundMusic.setMute(!on);
|
||||
menuMusic.setMute(!on);
|
||||
gameMusic.setMute(!on);
|
||||
}
|
||||
|
||||
public boolean isSoundOn() {
|
||||
@ -39,16 +54,19 @@ public class SoundManager {
|
||||
|
||||
public void pause() {
|
||||
soundPool.autoPause();
|
||||
backgroundMusic.pause();
|
||||
if (currentMusic != null)
|
||||
currentMusic.pause();
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
soundPool.autoResume();
|
||||
backgroundMusic.resume();
|
||||
if (currentMusic != null)
|
||||
currentMusic.resume();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
backgroundMusic.getPlayer().release();
|
||||
menuMusic.getPlayer().release();
|
||||
gameMusic.getPlayer().release();
|
||||
soundPool.release();
|
||||
}
|
||||
|
||||
@ -67,8 +85,7 @@ public class SoundManager {
|
||||
private float getVolume() {
|
||||
if (soundOn) {
|
||||
AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
float volume =
|
||||
manager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
float volume = manager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
float maxVolume = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
return volume / maxVolume;
|
||||
}
|
||||
|
Binary file not shown.
BIN
app/src/main/res/raw/music_game.mp3
Normal file
BIN
app/src/main/res/raw/music_game.mp3
Normal file
Binary file not shown.
BIN
app/src/main/res/raw/music_menu.wav
Normal file
BIN
app/src/main/res/raw/music_menu.wav
Normal file
Binary file not shown.
@ -9,7 +9,7 @@
|
||||
<string name="message_next_level">Nächstes Level</string>
|
||||
<string name="goal_message_restart_format_d">Neustart: Level %d</string>
|
||||
<string name="goal_message_next_level_format_d">Nächstes Level: %d</string>
|
||||
<string name="goal_message_next_world_format_s">Gehe zur nächsten Welt: %s</string>
|
||||
<string name="goal_message_next_world_format_s">Gehe zur nächsten Welt:\n%s</string>
|
||||
<string name="pre_start_screen_loading">LÄDT...</string>
|
||||
<string name="short_menu_continue">Weiter</string>
|
||||
<string name="short_menu_restart">Neustart</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user