- The range and volume of sounds emitted by StatusEffects can be changed and they can be set to loop.
- StatusEffect sounds are configured as child elements of the StatusEffect (instead of attributes). - Background sprites can emit sounds.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Barotrauma
|
||||
private List<ParticleEmitter> particleEmitters;
|
||||
|
||||
private Sound sound;
|
||||
private bool loopSound;
|
||||
#endif
|
||||
|
||||
public string[] propertyNames;
|
||||
@@ -132,11 +133,10 @@ namespace Barotrauma
|
||||
case "duration":
|
||||
duration = ToolBox.GetAttributeFloat(attribute, 0.0f);
|
||||
break;
|
||||
#if CLIENT
|
||||
case "sound":
|
||||
sound = Sound.Load(attribute.Value.ToString());
|
||||
DebugConsole.ThrowError("Error in StatusEffect " + element.Parent.Name.ToString() +
|
||||
" - sounds should be defined as child elements of the StatusEffect, not as attributes.");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
propertyAttributes.Add(attribute);
|
||||
break;
|
||||
@@ -181,6 +181,10 @@ namespace Barotrauma
|
||||
case "particleemitter":
|
||||
particleEmitters.Add(new ParticleEmitter(subElement));
|
||||
break;
|
||||
case "sound":
|
||||
sound = Sound.Load(subElement);
|
||||
loopSound = ToolBox.GetAttributeBool(subElement, "loop", false);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -227,7 +231,24 @@ namespace Barotrauma
|
||||
protected void Apply(float deltaTime, Entity entity, List<IPropertyObject> targets)
|
||||
{
|
||||
#if CLIENT
|
||||
if (sound != null) sound.Play(1.0f, 1000.0f, entity.WorldPosition);
|
||||
if (sound != null)
|
||||
{
|
||||
if (loopSound)
|
||||
{
|
||||
if (!Sounds.SoundManager.IsPlaying(sound))
|
||||
{
|
||||
sound.Play(entity.WorldPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound.UpdatePosition(entity.WorldPosition);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sound.Play(entity.WorldPosition);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (useItem)
|
||||
|
||||
@@ -53,8 +53,30 @@ namespace Barotrauma
|
||||
{
|
||||
this.ParticleEmitter = new ParticleEmitter(prefab.ParticleEmitterPrefab);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (prefab.SoundElement != null)
|
||||
{
|
||||
Sound = Sound.Load(prefab.SoundElement, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Vector2 LocalToWorld(Vector2 localPosition, float swingState = 0.0f)
|
||||
{
|
||||
Vector2 emitterPos = localPosition * Scale;
|
||||
|
||||
if (Rotation != 0.0f || Prefab.SwingAmount != 0.0f)
|
||||
{
|
||||
float rot = Rotation + swingState * Prefab.SwingAmount;
|
||||
|
||||
var ca = (float)Math.Cos(rot);
|
||||
var sa = (float)Math.Sin(rot);
|
||||
|
||||
emitterPos = new Vector2(
|
||||
ca * emitterPos.X + sa * emitterPos.Y,
|
||||
-sa * emitterPos.X + ca * emitterPos.Y);
|
||||
}
|
||||
return new Vector2(Position.X, Position.Y) + emitterPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,10 @@ namespace Barotrauma
|
||||
ParticleEmitterPrefab = new Particles.ParticleEmitterPrefab(subElement);
|
||||
EmitterPosition = ToolBox.GetAttributeVector2(subElement, "position", Vector2.Zero);
|
||||
break;
|
||||
case "sound":
|
||||
SoundElement = subElement;
|
||||
SoundPosition = ToolBox.GetAttributeVector2(subElement, "position", Vector2.Zero);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user