Work on sound effects

This commit is contained in:
Anuken 2019-08-11 10:47:22 -04:00
parent 2341da995e
commit 4c08c98f8c
17 changed files with 115 additions and 86 deletions

BIN
core/assets/sounds/boom.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
core/assets/sounds/message.ogg Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
core/assets/sounds/unlock.ogg Executable file

Binary file not shown.

BIN
core/assets/sounds/windowHide.ogg Executable file

Binary file not shown.

View File

@ -1,6 +1,7 @@
package io.anuke.mindustry.core;
import io.anuke.arc.*;
import io.anuke.arc.Application.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.input.*;
@ -175,6 +176,10 @@ public class Control implements ApplicationListener{
Events.on(ZoneConfigureCompleteEvent.class, e -> {
ui.hudfrag.showToast(Core.bundle.format("zone.config.complete", e.zone.configureWave));
});
if(Core.app.getType() == ApplicationType.Android){
Sounds.empty.loop(0f, 1f, 0f);
}
}
void createPlayer(){

View File

@ -23,6 +23,7 @@ import io.anuke.arc.util.*;
import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.editor.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.ui.dialogs.*;
import io.anuke.mindustry.ui.fragments.*;
@ -88,6 +89,8 @@ public class UI implements ApplicationListener{
Core.app.post(() -> showError("Failed to access local storage.\nSettings will not be saved."));
});
ClickListener.clicked = () -> Sounds.press.play();
Colors.put("accent", Pal.accent);
Colors.put("highlight", Pal.accent.cpy().lerp(Color.WHITE, 0.3f));
Colors.put("stat", Pal.stat);

View File

@ -14,7 +14,7 @@ import static io.anuke.mindustry.Vars.*;
/** Controls playback of multiple music tracks.*/
public class MusicControl{
private static final float finTime = 120f, foutTime = 120f, musicInterval = 60 * 60 * 3f, musicChance = 0.25f, musicWaveChance = 0.2f;
private static final float finTime = 120f, foutTime = 120f, musicInterval = 60 * 60 * 3f, musicChance = 0.3f, musicWaveChance = 0.24f;
/** normal, ambient music, plays at any time */
public final Array<Music> ambientMusic = Array.with(Musics.game1, Musics.game3, Musics.game4, Musics.game6);
@ -30,6 +30,7 @@ public class MusicControl{
private boolean silenced;
public MusicControl(){
//only run music 10 seconds after a wave spawns
Events.on(WaveEvent.class, e -> Time.run(60f * 10f, () -> {
if(Mathf.chance(musicWaveChance)){
playRandom();
@ -40,6 +41,7 @@ public class MusicControl{
/** Update and play the right music track.*/
public void update(){
if(state.is(State.menu)){
silenced = false;
if(ui.deploy.isShown()){
play(Musics.launch);
}else if(ui.editor.isShown()){
@ -48,6 +50,7 @@ public class MusicControl{
play(Musics.menu);
}
}else if(state.rules.editor){
silenced = false;
play(Musics.editor);
}else{
//this just fades out the last track to make way for ingame music
@ -79,17 +82,13 @@ public class MusicControl{
return true;
}
if(state.enemies() > 25){
//many enemies -> dark
return true;
}
//it may be dark based on wave
if(Mathf.chance((float)(Math.log10((state.wave - 17f)/19f) + 1) / 4f)){
return true;
}
return false;
//dark based on enemies
return Mathf.chance(state.enemies() / 70f);
}
/** Plays and fades in a music track. This must be called every frame.

View File

@ -56,11 +56,11 @@ public class DatabaseDialog extends FloatingDialog{
UnlockableContent unlock = (UnlockableContent)array.get(i);
Image image = unlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked", Pal.gray);
image.addListener(new HandCursorListener());
list.add(image).size(unlocked(unlock) ? 8*4 : Vars.iconsize).pad(3);
ClickListener listener = new ClickListener();
image.addListener(listener);
if(!Vars.mobile){
if(!Vars.mobile && unlocked(unlock)){
image.addListener(new HandCursorListener());
image.update(() -> image.getColor().lerp(!listener.isOver() ? Color.LIGHT_GRAY : Color.WHITE, 0.4f * Time.delta()));
}

View File

@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.*;
import io.anuke.arc.input.*;
import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.core.GameState.*;
@ -33,7 +32,6 @@ public class FloatingDialog extends Dialog{
}
Sounds.back.play();
});
ClickListener.clicked = () -> Sounds.press.play();
shown(() -> {
if(shouldPause && !state.is(State.menu)){

View File

@ -15,6 +15,7 @@ import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.content.TechTree.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.*;
@ -237,6 +238,7 @@ public class TechTreeDialog extends FloatingDialog{
treeLayout();
rebuild();
Core.scene.act();
Sounds.unlock.play();
}
void rebuild(){

View File

@ -1,15 +1,16 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.scene.ui.Button;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.type.Zone.ZoneRequirement;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import io.anuke.mindustry.type.Zone.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Block.*;
import static io.anuke.mindustry.Vars.*;
@ -142,6 +143,7 @@ public class ZoneInfoDialog extends FloatingDialog{
Button button = cont.addButton(zone.locked() ? "$uncover" : "$launch", () -> {
if(!data.isUnlocked(zone)){
Sounds.unlock.play();
data.unlockContent(zone);
ui.deploy.setup();
setup(zone);

View File

@ -44,6 +44,7 @@ public class HudFragment extends Fragment{
private float lastCoreHP;
private Team lastTeam;
private float coreAttackOpacity = 0f;
private long lastToast;
public void build(Group parent){
@ -372,7 +373,24 @@ public class HudFragment extends Fragment{
}
}
private void scheduleToast(Runnable run){
long duration = (int)(3.5 * 1000);
long since = Time.timeSinceMillis(lastToast);
if(since > duration){
lastToast = Time.millis();
run.run();
}else{
Time.runTask((duration - since) / 1000f * 60f, run);
lastToast += duration;
}
}
public void showToast(String text){
if(state.is(State.menu)) return;
scheduleToast(() -> {
Sounds.message.play();
Table table = new Table("button");
table.update(() -> {
if(state.is(State.menu)){
@ -388,9 +406,10 @@ public class HudFragment extends Fragment{
Table container = Core.scene.table();
container.top().add(table);
container.setTranslation(0, table.getPrefHeight());
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(2.5f),
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.remove())));
});
}
public boolean shown(){
@ -400,10 +419,13 @@ public class HudFragment extends Fragment{
/** Show unlock notification for a new recipe. */
public void showUnlock(UnlockableContent content){
//some content may not have icons... yet
if(content.getContentIcon() == null) return;
if(content.getContentIcon() == null || state.is(State.menu)) return;
Sounds.message.play();
//if there's currently no unlock notification...
if(lastUnlockTable == null){
scheduleToast(() -> {
Table table = new Table("button");
table.update(() -> {
if(state.is(State.menu)){
@ -431,7 +453,7 @@ public class HudFragment extends Fragment{
Table container = Core.scene.table();
container.top().add(table);
container.setTranslation(0, table.getPrefHeight());
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(2.5f),
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
lastUnlockTable = null;
@ -440,6 +462,7 @@ public class HudFragment extends Fragment{
lastUnlockTable = container;
lastUnlockLayout = in;
});
}else{
//max column size
int col = 3;

View File

@ -1,25 +1,22 @@
package io.anuke.mindustry.world.blocks.storage;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.annotations.Annotations.*;
import io.anuke.arc.*;
import io.anuke.arc.collection.EnumSet;
import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.traits.SpawnerTrait;
import io.anuke.arc.math.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.*;