diff --git a/core/assets/sounds/lasercharge2.ogg b/core/assets/sounds/lasercharge2.ogg new file mode 100644 index 0000000000..2a737e5f63 Binary files /dev/null and b/core/assets/sounds/lasercharge2.ogg differ diff --git a/core/src/mindustry/audio/SoundLoop.java b/core/src/mindustry/audio/SoundLoop.java index 99d6837251..a4b229b147 100644 --- a/core/src/mindustry/audio/SoundLoop.java +++ b/core/src/mindustry/audio/SoundLoop.java @@ -18,11 +18,12 @@ public class SoundLoop{ } public void update(float x, float y, boolean play){ - if(baseVolume < 0) return; + if(baseVolume <= 0) return; if(id < 0){ if(play){ id = sound.loop(sound.calcVolume(x, y) * volume * baseVolume, 1f, sound.calcPan(x, y)); + Log.info("playing, id = @", id); } }else{ //fade the sound in or out @@ -36,6 +37,7 @@ public class SoundLoop{ return; } } + sound.setPan(id, sound.calcPan(x, y), sound.calcVolume(x, y) * volume * baseVolume); } } diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 8592381131..ed1fe92341 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -432,7 +432,8 @@ public class UnitTypes implements ContentList{ reload = 320f; recoil = 0f; - shootSound = Sounds.laser; + chargeSound = Sounds.lasercharge2; + shootSound = Sounds.beam; continuous = true; cooldownTime = 200f; @@ -1588,7 +1589,7 @@ public class UnitTypes implements ContentList{ inaccuracy = 7f; ejectEffect = Fx.none; shake = 3f; - shootSound = Sounds.shootBig; + shootSound = Sounds.missile; xRand = 8f; shotDelay = 1f; diff --git a/core/src/mindustry/entities/comp/WeaponsComp.java b/core/src/mindustry/entities/comp/WeaponsComp.java index d9488084b0..ab4321393a 100644 --- a/core/src/mindustry/entities/comp/WeaponsComp.java +++ b/core/src/mindustry/entities/comp/WeaponsComp.java @@ -4,6 +4,7 @@ import arc.math.*; import arc.math.geom.*; import arc.util.*; import mindustry.annotations.Annotations.*; +import mindustry.audio.*; import mindustry.entities.*; import mindustry.entities.bullet.*; import mindustry.entities.units.*; @@ -117,10 +118,18 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc, Velc, Statusc{ mount.bullet.rotation(weaponRotation + 90); mount.bullet.set(shootX, shootY); vel.add(Tmp.v1.trns(rotation + 180f, mount.bullet.type.recoil)); + if(weapon.shootSound != Sounds.none && !headless){ + if(mount.sound == null) mount.sound = new SoundLoop(weapon.shootSound, 1f); + mount.sound.update(x, y, true); + } } }else{ //heat decreases when not firing mount.heat = Math.max(mount.heat - Time.delta * reloadMultiplier / mount.weapon.cooldownTime, 0); + + if(mount.sound != null){ + mount.sound.update(x, y, false); + } } //flip weapon shoot side for alternating weapons at half reload @@ -168,7 +177,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc, Velc, Statusc{ float baseX = this.x, baseY = this.y; boolean delay = weapon.firstShotDelay + weapon.shotDelay > 0f; - (delay ? weapon.chargeSound : weapon.shootSound).at(x, y, Mathf.random(weapon.soundPitchMin, weapon.soundPitchMax)); + (delay ? weapon.chargeSound : weapon.continuous ? Sounds.none : weapon.shootSound).at(x, y, Mathf.random(weapon.soundPitchMin, weapon.soundPitchMax)); BulletType ammo = weapon.bullet; float lifeScl = ammo.scaleVelocity ? Mathf.clamp(Mathf.dst(x, y, aimX, aimY) / ammo.range()) : 1f; @@ -195,7 +204,9 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc, Velc, Statusc{ vel.add(Tmp.v1.trns(rotation + 180f, ammo.recoil)); Effect.shake(weapon.shake, weapon.shake, x, y); mount.heat = 1f; - weapon.shootSound.at(x, y, Mathf.random(weapon.soundPitchMin, weapon.soundPitchMax)); + if(!weapon.continuous){ + weapon.shootSound.at(x, y, Mathf.random(weapon.soundPitchMin, weapon.soundPitchMax)); + } }); }else{ vel.add(Tmp.v1.trns(rotation + 180f, ammo.recoil)); diff --git a/core/src/mindustry/entities/units/WeaponMount.java b/core/src/mindustry/entities/units/WeaponMount.java index 80bf713f20..e5f61679c7 100644 --- a/core/src/mindustry/entities/units/WeaponMount.java +++ b/core/src/mindustry/entities/units/WeaponMount.java @@ -1,6 +1,7 @@ package mindustry.entities.units; import arc.util.*; +import mindustry.audio.*; import mindustry.gen.*; import mindustry.type.*; @@ -25,6 +26,8 @@ public class WeaponMount{ public boolean side; /** current bullet for continuous weapons */ public @Nullable Bullet bullet; + /** sound loop for continuous weapons */ + public @Nullable SoundLoop sound; public WeaponMount(Weapon weapon){ this.weapon = weapon; diff --git a/gradle.properties b/gradle.properties index d6dced3c14..74f8398b48 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=b99073959675a037f3a722a7ca08d28c21e10038 +archash=3919455d82ac008743cf6794593b3379f9758a38