More sound fixes

This commit is contained in:
Anuken
2020-11-08 16:40:32 -05:00
parent 7bb23c3384
commit 28dfe2b1f7
6 changed files with 23 additions and 6 deletions

Binary file not shown.

View File

@@ -18,11 +18,12 @@ public class SoundLoop{
} }
public void update(float x, float y, boolean play){ public void update(float x, float y, boolean play){
if(baseVolume < 0) return; if(baseVolume <= 0) return;
if(id < 0){ if(id < 0){
if(play){ if(play){
id = sound.loop(sound.calcVolume(x, y) * volume * baseVolume, 1f, sound.calcPan(x, y)); id = sound.loop(sound.calcVolume(x, y) * volume * baseVolume, 1f, sound.calcPan(x, y));
Log.info("playing, id = @", id);
} }
}else{ }else{
//fade the sound in or out //fade the sound in or out
@@ -36,6 +37,7 @@ public class SoundLoop{
return; return;
} }
} }
sound.setPan(id, sound.calcPan(x, y), sound.calcVolume(x, y) * volume * baseVolume); sound.setPan(id, sound.calcPan(x, y), sound.calcVolume(x, y) * volume * baseVolume);
} }
} }

View File

@@ -432,7 +432,8 @@ public class UnitTypes implements ContentList{
reload = 320f; reload = 320f;
recoil = 0f; recoil = 0f;
shootSound = Sounds.laser; chargeSound = Sounds.lasercharge2;
shootSound = Sounds.beam;
continuous = true; continuous = true;
cooldownTime = 200f; cooldownTime = 200f;
@@ -1588,7 +1589,7 @@ public class UnitTypes implements ContentList{
inaccuracy = 7f; inaccuracy = 7f;
ejectEffect = Fx.none; ejectEffect = Fx.none;
shake = 3f; shake = 3f;
shootSound = Sounds.shootBig; shootSound = Sounds.missile;
xRand = 8f; xRand = 8f;
shotDelay = 1f; shotDelay = 1f;

View File

@@ -4,6 +4,7 @@ import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.util.*; import arc.util.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.audio.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.entities.bullet.*; import mindustry.entities.bullet.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
@@ -117,10 +118,18 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc, Velc, Statusc{
mount.bullet.rotation(weaponRotation + 90); mount.bullet.rotation(weaponRotation + 90);
mount.bullet.set(shootX, shootY); mount.bullet.set(shootX, shootY);
vel.add(Tmp.v1.trns(rotation + 180f, mount.bullet.type.recoil)); 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{ }else{
//heat decreases when not firing //heat decreases when not firing
mount.heat = Math.max(mount.heat - Time.delta * reloadMultiplier / mount.weapon.cooldownTime, 0); 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 //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; float baseX = this.x, baseY = this.y;
boolean delay = weapon.firstShotDelay + weapon.shotDelay > 0f; 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; BulletType ammo = weapon.bullet;
float lifeScl = ammo.scaleVelocity ? Mathf.clamp(Mathf.dst(x, y, aimX, aimY) / ammo.range()) : 1f; 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)); vel.add(Tmp.v1.trns(rotation + 180f, ammo.recoil));
Effect.shake(weapon.shake, weapon.shake, x, y); Effect.shake(weapon.shake, weapon.shake, x, y);
mount.heat = 1f; 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{ }else{
vel.add(Tmp.v1.trns(rotation + 180f, ammo.recoil)); vel.add(Tmp.v1.trns(rotation + 180f, ammo.recoil));

View File

@@ -1,6 +1,7 @@
package mindustry.entities.units; package mindustry.entities.units;
import arc.util.*; import arc.util.*;
import mindustry.audio.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
@@ -25,6 +26,8 @@ public class WeaponMount{
public boolean side; public boolean side;
/** current bullet for continuous weapons */ /** current bullet for continuous weapons */
public @Nullable Bullet bullet; public @Nullable Bullet bullet;
/** sound loop for continuous weapons */
public @Nullable SoundLoop sound;
public WeaponMount(Weapon weapon){ public WeaponMount(Weapon weapon){
this.weapon = weapon; this.weapon = weapon;

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=b99073959675a037f3a722a7ca08d28c21e10038 archash=3919455d82ac008743cf6794593b3379f9758a38