Commit baed8ac9 authored by Aneta Steimarova's avatar Aneta Steimarova

#865 Added music dispose for each sound in sequence for each level

parent f1dbca01
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package cz.nic.tablexia.game.games.safe; package cz.nic.tablexia.game.games.safe;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
...@@ -29,6 +30,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; ...@@ -29,6 +30,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Scaling; import com.badlogic.gdx.utils.Scaling;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -114,6 +116,7 @@ public class SafeGame extends AbstractTablexiaGame<Void> { ...@@ -114,6 +116,7 @@ public class SafeGame extends AbstractTablexiaGame<Void> {
public int level_fails = 0; public int level_fails = 0;
private boolean paused = false; private boolean paused = false;
private boolean isVisualisationVisible = false; private boolean isVisualisationVisible = false;
private List<Music> musicList;
public AbstractMechanics getSafeGroup() { public AbstractMechanics getSafeGroup() {
...@@ -167,6 +170,7 @@ public class SafeGame extends AbstractTablexiaGame<Void> { ...@@ -167,6 +170,7 @@ public class SafeGame extends AbstractTablexiaGame<Void> {
round = 0; round = 0;
score = 0; score = 0;
level_fails = 0; level_fails = 0;
musicList = new ArrayList<Music>();
selectedLight = null; selectedLight = null;
usedHelpButton = false; usedHelpButton = false;
setGameScore(SCORE_COUNT, score); setGameScore(SCORE_COUNT, score);
...@@ -328,17 +332,33 @@ public class SafeGame extends AbstractTablexiaGame<Void> { ...@@ -328,17 +332,33 @@ public class SafeGame extends AbstractTablexiaGame<Void> {
playSoundSequence(safeSequence); playSoundSequence(safeSequence);
makeButtonsTouchable(); makeButtonsTouchable();
} else { } else {
disposeMusicInMusicList();
gameComplete(); gameComplete();
} }
} }
private void prepareNextRound() { private void prepareNextRound() {
disposeMusicInMusicList();
safeSequence = null; safeSequence = null;
selectedLight = null; selectedLight = null;
prepareSequenceMusic(); prepareSequenceMusic();
generateSafeForRound(); generateSafeForRound();
} }
private void disposeMusicInMusicList(){
for(Music music: musicList){
music.dispose();
}
musicList.clear();
}
public void addMusicToMusicList(Music sound){
for(Music music: musicList){
if(music.equals(sound)) return;
}
musicList.add(sound);
}
private void addHelpBtn() { private void addHelpBtn() {
helpButton = new ImageTablexiaButton(getText(SafeAssets.HELP_EYE_TEXT), new Image(getScreenTextureRegion(SafeAssets.HELP_BTN_EYE)), Align.left, StandardTablexiaButton.TablexiaButtonType.BLUE); helpButton = new ImageTablexiaButton(getText(SafeAssets.HELP_EYE_TEXT), new Image(getScreenTextureRegion(SafeAssets.HELP_BTN_EYE)), Align.left, StandardTablexiaButton.TablexiaButtonType.BLUE);
setButton(helpButton, getViewportWidth() - REPLAY_BUTTON_OFFSET_X, getSceneInnerTopY() - HELP_BUTTON_OFFSET_Y, new HelpButtonClickListener(this)); setButton(helpButton, getViewportWidth() - REPLAY_BUTTON_OFFSET_X, getSceneInnerTopY() - HELP_BUTTON_OFFSET_Y, new HelpButtonClickListener(this));
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package cz.nic.tablexia.game.games.safe.actors; package cz.nic.tablexia.game.games.safe.actors;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
...@@ -129,7 +130,9 @@ public class SequenceGenerator extends Group { ...@@ -129,7 +130,9 @@ public class SequenceGenerator extends Group {
//actions to play !!!there always has to be only one in one level (but can be used more than one after reset) //actions to play !!!there always has to be only one in one level (but can be used more than one after reset)
List<Action> playMusicActionList = new ArrayList<Action>(); List<Action> playMusicActionList = new ArrayList<Action>();
for (SafeSounds safeSound : safeSequence.getSoundsToSequence()) { for (SafeSounds safeSound : safeSequence.getSoundsToSequence()) {
PlayMusicAction musicAction = PlayMusicAction.getInstance(safegame.getMusic(safeSound.getSoundPath())); Music music = safegame.getMusic(safeSound.getSoundPath());
safegame.addMusicToMusicList(music);
PlayMusicAction musicAction = PlayMusicAction.getInstance(music);
musicAction.reset(); musicAction.reset();
playMusicActionList.add(musicAction); playMusicActionList.add(musicAction);
} }
......
...@@ -26,7 +26,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; ...@@ -26,7 +26,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import java.util.List; import java.util.List;
import cz.nic.tablexia.game.AbstractTablexiaGame; import cz.nic.tablexia.game.games.safe.SafeGame;
/** /**
* Created by Aneta Steimarová on 25.5.17. * Created by Aneta Steimarová on 25.5.17.
...@@ -51,24 +51,26 @@ public class SafeLightImage extends Image { ...@@ -51,24 +51,26 @@ public class SafeLightImage extends Image {
return inputListener; return inputListener;
} }
public SafeLightImage(AbstractTablexiaGame game, String greyTextureRegion, String redTextureRegion, String greenTextureRegion, String blueTextureRegion, Music music, float angle) { public SafeLightImage(SafeGame safeGame, String greyTextureRegion, String redTextureRegion, String greenTextureRegion, String blueTextureRegion, Music music, float angle) {
super(game.getScreenTextureRegion(greyTextureRegion)); super(safeGame.getScreenTextureRegion(greyTextureRegion));
this.screenTextureGrey = game.getScreenTextureRegion(greyTextureRegion); this.screenTextureGrey = safeGame.getScreenTextureRegion(greyTextureRegion);
this.screenTextureRed = game.getScreenTextureRegion(redTextureRegion); this.screenTextureRed = safeGame.getScreenTextureRegion(redTextureRegion);
this.screenTextureGreen = game.getScreenTextureRegion(greenTextureRegion); this.screenTextureGreen = safeGame.getScreenTextureRegion(greenTextureRegion);
this.screenTextureBlue = game.getScreenTextureRegion(blueTextureRegion); this.screenTextureBlue = safeGame.getScreenTextureRegion(blueTextureRegion);
this.sound = music; this.sound = music;
this.angle = angle; this.angle = angle;
safeGame.addMusicToMusicList(sound);
} }
public SafeLightImage(AbstractTablexiaGame game, String greyTextureRegion, String redTextureRegion, String greenTextureRegion, String blueTextureRegion, Music music) { public SafeLightImage(SafeGame safeGame, String greyTextureRegion, String redTextureRegion, String greenTextureRegion, String blueTextureRegion, Music music) {
super(game.getScreenTextureRegion(greyTextureRegion)); super(safeGame.getScreenTextureRegion(greyTextureRegion));
this.screenTextureGrey = game.getScreenTextureRegion(greyTextureRegion); this.screenTextureGrey = safeGame.getScreenTextureRegion(greyTextureRegion);
this.screenTextureRed = game.getScreenTextureRegion(redTextureRegion); this.screenTextureRed = safeGame.getScreenTextureRegion(redTextureRegion);
this.screenTextureGreen = game.getScreenTextureRegion(greenTextureRegion); this.screenTextureGreen = safeGame.getScreenTextureRegion(greenTextureRegion);
this.screenTextureBlue = game.getScreenTextureRegion(blueTextureRegion); this.screenTextureBlue = safeGame.getScreenTextureRegion(blueTextureRegion);
this.sound = music; this.sound = music;
this.angle = DEFAULT_ANGLE; this.angle = DEFAULT_ANGLE;
safeGame.addMusicToMusicList(sound);
} }
public Music getSound() { public Music getSound() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment