(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

View File

@@ -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)

View File

@@ -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);

View File

@@ -1928,6 +1928,42 @@
<None Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\ElectricalDischarger.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactHeavy1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactHeavy2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactHeavy3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactHeavy4.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactLight1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactLight2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactLight3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactLight4.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\MetalImpactLight5.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\SoftImpact1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\SoftImpact2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Content\Sounds\Impact\SoftImpact3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)Content\Characters\Carrier\CARRIER_alarmLoop.ogg">

View File

@@ -579,13 +579,12 @@ namespace Barotrauma
}
}
//containers need to handle collision events to notify items inside them about the impact
var itemContainer = GetComponent<ItemContainer>();
if (ImpactTolerance > 0.0f || itemContainer != null)
if (body != null)
{
if (body != null) body.FarseerBody.OnCollision += OnCollision;
body.FarseerBody.OnCollision += OnCollision;
}
var itemContainer = GetComponent<ItemContainer>();
if (itemContainer != null)
{
ownInventory = itemContainer.Inventory;
@@ -1145,6 +1144,12 @@ namespace Barotrauma
return;
}
float forceFactor = 1.0f;
if (CurrentHull != null)
{
return;
}
float forceFactor = 1.0f;
if (CurrentHull != null)
{
@@ -1166,19 +1171,18 @@ namespace Barotrauma
body.ApplyForce((uplift - drag) * 10.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity);
//apply simple angular drag
body.ApplyTorque(body.AngularVelocity * volume * -0.05f);
body.ApplyTorque(body.AngularVelocity * volume * -0.05f);
}
private bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
#if CLIENT
if (GameMain.Client != null) return true;
#endif
Vector2 normal = contact.Manifold.LocalNormal;
float impact = Vector2.Dot(f1.Body.LinearVelocity, -normal);
OnCollisionProjSpecific(f1, f2, contact, impact);
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return true; }
if (ImpactTolerance > 0.0f && impact > ImpactTolerance)
{
ApplyStatusEffects(ActionType.OnImpact, 1.0f);
@@ -1200,6 +1204,8 @@ namespace Barotrauma
return true;
}
partial void OnCollisionProjSpecific(Fixture f1, Fixture f2, Contact contact, float impact);
public override void FlipX(bool relativeToSub)
{
base.FlipX(relativeToSub);