(bc739e38f) Added impact sounds to items (e.g. when dropped to the ground). Closes #841
This commit is contained in:
@@ -9,6 +9,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Barotrauma.Extensions;
|
using Barotrauma.Extensions;
|
||||||
|
using FarseerPhysics.Dynamics;
|
||||||
|
using FarseerPhysics.Dynamics.Contacts;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
@@ -22,6 +24,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public IEnumerable<ItemComponent> ActiveHUDs => activeHUDs;
|
public IEnumerable<ItemComponent> ActiveHUDs => activeHUDs;
|
||||||
|
|
||||||
|
public float LastImpactSoundTime;
|
||||||
|
public const float ImpactSoundInterval = 0.2f;
|
||||||
|
|
||||||
class SpriteState
|
class SpriteState
|
||||||
{
|
{
|
||||||
public float RotationState;
|
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)
|
public void UpdateSpriteStates(float deltaTime)
|
||||||
{
|
{
|
||||||
foreach (int spriteGroup in Prefab.DecorativeSpriteGroups.Keys)
|
foreach (int spriteGroup in Prefab.DecorativeSpriteGroups.Keys)
|
||||||
|
|||||||
@@ -191,6 +191,10 @@ namespace Barotrauma
|
|||||||
protected set;
|
protected set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Serialize("", false)]
|
||||||
|
public string ImpactSoundTag { get; private set; }
|
||||||
|
|
||||||
public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
|
public override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
|
||||||
{
|
{
|
||||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||||
|
|||||||
@@ -1928,6 +1928,42 @@
|
|||||||
<None Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\ElectricalDischarger.ogg">
|
<None Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\ElectricalDischarger.ogg">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="$(MSBuildThisFileDirectory)Content\Characters\Carrier\CARRIER_alarmLoop.ogg">
|
<None Include="$(MSBuildThisFileDirectory)Content\Characters\Carrier\CARRIER_alarmLoop.ogg">
|
||||||
|
|||||||
@@ -579,13 +579,12 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//containers need to handle collision events to notify items inside them about the impact
|
if (body != null)
|
||||||
var itemContainer = GetComponent<ItemContainer>();
|
|
||||||
if (ImpactTolerance > 0.0f || itemContainer != null)
|
|
||||||
{
|
{
|
||||||
if (body != null) body.FarseerBody.OnCollision += OnCollision;
|
body.FarseerBody.OnCollision += OnCollision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var itemContainer = GetComponent<ItemContainer>();
|
||||||
if (itemContainer != null)
|
if (itemContainer != null)
|
||||||
{
|
{
|
||||||
ownInventory = itemContainer.Inventory;
|
ownInventory = itemContainer.Inventory;
|
||||||
@@ -1145,6 +1144,12 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float forceFactor = 1.0f;
|
||||||
|
if (CurrentHull != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
float forceFactor = 1.0f;
|
float forceFactor = 1.0f;
|
||||||
if (CurrentHull != null)
|
if (CurrentHull != null)
|
||||||
{
|
{
|
||||||
@@ -1171,14 +1176,13 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private bool OnCollision(Fixture f1, Fixture f2, Contact contact)
|
private bool OnCollision(Fixture f1, Fixture f2, Contact contact)
|
||||||
{
|
{
|
||||||
#if CLIENT
|
|
||||||
if (GameMain.Client != null) return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Vector2 normal = contact.Manifold.LocalNormal;
|
Vector2 normal = contact.Manifold.LocalNormal;
|
||||||
|
|
||||||
float impact = Vector2.Dot(f1.Body.LinearVelocity, -normal);
|
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)
|
if (ImpactTolerance > 0.0f && impact > ImpactTolerance)
|
||||||
{
|
{
|
||||||
ApplyStatusEffects(ActionType.OnImpact, 1.0f);
|
ApplyStatusEffects(ActionType.OnImpact, 1.0f);
|
||||||
@@ -1200,6 +1204,8 @@ namespace Barotrauma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnCollisionProjSpecific(Fixture f1, Fixture f2, Contact contact, float impact);
|
||||||
|
|
||||||
public override void FlipX(bool relativeToSub)
|
public override void FlipX(bool relativeToSub)
|
||||||
{
|
{
|
||||||
base.FlipX(relativeToSub);
|
base.FlipX(relativeToSub);
|
||||||
|
|||||||
Reference in New Issue
Block a user