This commit is contained in:
Anuken 2019-07-31 18:59:28 -04:00
parent d8085d88a8
commit 2be3cc2f1e
6 changed files with 50 additions and 3 deletions

Binary file not shown.

BIN
core/assets/music/menu.mp3 Normal file

Binary file not shown.

Binary file not shown.

View File

@ -133,6 +133,7 @@ public class Vars{
public static GlobalData data;
public static EntityCollisions collisions;
public static DefaultWaves defaultWaves;
public static MusicControl mcont;
public static Control control;
public static Logic logic;
@ -208,6 +209,7 @@ public class Vars{
state = new GameState();
data = new GlobalData();
mcont = new MusicControl();
mobile = Core.app.getType() == ApplicationType.Android || Core.app.getType() == ApplicationType.iOS || testMobile;
ios = Core.app.getType() == ApplicationType.iOS;

View File

@ -168,9 +168,6 @@ public class Control implements ApplicationListener{
Events.on(ZoneConfigureCompleteEvent.class, e -> {
ui.hudfrag.showToast(Core.bundle.format("zone.config.complete", e.zone.configureWave));
});
Musics.menu.setLooping(true);
// Musics.menu.play();
}
void createPlayer(){
@ -312,6 +309,19 @@ public class Control implements ApplicationListener{
//autosave global data if it's modified
data.checkSave();
if(state.is(State.menu)){
if(ui.deploy.isShown()){
mcont.silence(); //TODO deploy music
}else if(ui.editor.isShown()){
mcont.play(Musics.editor);
}else{
mcont.play(Musics.menu);
}
}else{
//TODO game music
mcont.silence();
}
if(!state.is(State.menu)){
input.update();

View File

@ -1,4 +1,39 @@
package io.anuke.mindustry.game;
import io.anuke.annotations.Annotations.*;
import io.anuke.arc.audio.*;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
public class MusicControl{
private static final float finTime = 80f, foutTime = 80f;
private @Nullable Music current;
public void play(@Nullable Music music){
if(current == null && music != null){
current = music;
current.setLooping(true);
current.setVolume(0f);
current.play();
}else if(current == music && music != null){
current.setVolume(Mathf.clamp(current.getVolume() + Time.delta()/finTime));
}else if(current != null){
current.setVolume(Mathf.clamp(current.getVolume() - Time.delta()/foutTime));
if(current.getVolume() <= 0.01f){
current.stop();
current = null;
if(music != null){
current = music;
current.setVolume(0f);
current.setLooping(true);
current.play();
}
}
}
}
public void silence(){
play(null);
}
}