diff --git a/core/src/mindustry/entities/effect/SoundEffect.java b/core/src/mindustry/entities/effect/SoundEffect.java new file mode 100644 index 0000000000..8ed0f74a20 --- /dev/null +++ b/core/src/mindustry/entities/effect/SoundEffect.java @@ -0,0 +1,38 @@ +package mindustry.entities.effect; + +import arc.*; +import arc.audio.*; +import arc.func.*; +import arc.graphics.*; +import arc.math.*; +import arc.struct.*; +import arc.util.*; +import mindustry.entities.*; +import mindustry.game.EventType.*; +import mindustry.gen.*; + +/** Plays a sound effect when created and simultaneously renders an effect. */ +public class SoundEffect extends Effect{ + public Sound sound = Sounds.none; + public float minPitch = 0.8f; + public float maxPitch = 1.2f; + public float minVolume = 1f; + public float maxVolume = 1f; + public Effect effect; + + public SoundEffect(){ + } + + public SoundEffect(Sound sound, Effect effect){ + this.sound = sound; + this.effect = effect; + } + + @Override + public void create(float x, float y, float rotation, Color color, Object data){ + if(!shouldCreate()) return; + + sound.at(x, y, Mathf.random(minPitch, maxPitch), Mathf.random(minVolume, maxVolume)); + effect.create(x, y, rotation, color, data); + } +} diff --git a/core/src/mindustry/mod/ClassMap.java b/core/src/mindustry/mod/ClassMap.java index 5ddec905f5..db15ff5e89 100644 --- a/core/src/mindustry/mod/ClassMap.java +++ b/core/src/mindustry/mod/ClassMap.java @@ -66,6 +66,7 @@ public class ClassMap{ classes.put("ParticleEffect", mindustry.entities.effect.ParticleEffect.class); classes.put("RadialEffect", mindustry.entities.effect.RadialEffect.class); classes.put("SeqEffect", mindustry.entities.effect.SeqEffect.class); + classes.put("SoundEffect", mindustry.entities.effect.SoundEffect.class); classes.put("WaveEffect", mindustry.entities.effect.WaveEffect.class); classes.put("WrapEffect", mindustry.entities.effect.WrapEffect.class); classes.put("DrawPart", mindustry.entities.part.DrawPart.class);