(bc739e38f) Added impact sounds to items (e.g. when dropped to the ground). Closes #841

This commit is contained in:
Joonas Rikkonen
2019-04-07 13:40:53 +03:00
parent d15a88c619
commit db754188ce
4 changed files with 72 additions and 10 deletions
@@ -9,6 +9,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Barotrauma.Extensions;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
namespace Barotrauma
{
@@ -22,6 +24,9 @@ namespace Barotrauma
public IEnumerable<ItemComponent> ActiveHUDs => activeHUDs;
public float LastImpactSoundTime;
public const float ImpactSoundInterval = 0.2f;
class SpriteState
{
public float RotationState;
@@ -360,6 +365,17 @@ namespace Barotrauma
}
}
partial void OnCollisionProjSpecific(Fixture f1, Fixture f2, Contact contact, float impact)
{
if (impact > 1.0f &&
!string.IsNullOrEmpty(Prefab.ImpactSoundTag) &&
Timing.TotalTime > LastImpactSoundTime + ImpactSoundInterval)
{
LastImpactSoundTime = (float)Timing.TotalTime;
SoundPlayer.PlaySound(Prefab.ImpactSoundTag, 1.0f, 500.0f, WorldPosition, CurrentHull);
}
}
public void UpdateSpriteStates(float deltaTime)
{
foreach (int spriteGroup in Prefab.DecorativeSpriteGroups.Keys)
@@ -191,6 +191,10 @@ namespace Barotrauma
protected set;
}
[Serialize("", false)]
public string ImpactSoundTag { get; private set; }
public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);