low pass filter to sounds playing at distance, "armored" limbs, moved playing damagesounds from attack to IDamageable

This commit is contained in:
Regalis
2015-06-01 22:20:17 +03:00
parent 95c0d41023
commit 1f42e4a4db
32 changed files with 331 additions and 175 deletions

View File

@@ -654,10 +654,8 @@ namespace Subsurface
}
}
public void AddDamage(Vector2 position, float amount, float bleedingAmount, float stun)
public void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound = false)
{
int bloodAmount = 0;
animController.StunTimer = Math.Max(animController.StunTimer, stun);
Limb closestLimb = null;
@@ -676,35 +674,9 @@ namespace Subsurface
if (pull != Vector2.Zero) pull = Vector2.Normalize(pull);
closestLimb.body.ApplyForce(pull*Math.Min(amount*100.0f, 100.0f));
closestLimb.Bleeding += bleedingAmount;
closestLimb.Damage += amount;
bloodAmount = (int)Math.Min((int)(amount*2.0f),20);
//if (closestLimb.Damage>=100.0f)
//{
// bloodAmount *= 2;
// foreach (var joint in animController.limbJoints)
// {
// if (!(joint.BodyA == closestLimb.body.FarseerBody) && !(joint.BodyB == closestLimb.body.FarseerBody)) continue;
// joint.Enabled = false;
// break;
// }
//}
for (int i = 0; i < bloodAmount; i++)
{
Vector2 particleVel = closestLimb.SimPosition-position;
if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel);
closestLimb.AddDamage(position, damageType, amount, bleedingAmount, playSound);
Game1.particleManager.CreateParticle("blood",
closestLimb.SimPosition,
particleVel * ToolBox.RandomFloat(1.0f,3.0f));
}
for (int i = 0; i < bloodAmount / 2; i++)
{
Game1.particleManager.CreateParticle("waterblood",closestLimb.SimPosition,Vector2.Zero);
}
}
public void Stun()

View File

@@ -41,12 +41,15 @@ namespace Subsurface
public readonly bool ignoreCollisions;
private float maxHealth;
private readonly float maxHealth;
private float damage;
private float bleeding;
public readonly float impactTolerance;
private readonly Vector2 armorSector;
private readonly float armorValue;
Sound hitSound;
//a timer for delaying when a hitsound/attacksound can be played again
public float soundTimer;
@@ -206,6 +209,12 @@ namespace Subsurface
steerForce = ToolBox.GetAttributeFloat(element, "steerforce", 0.0f);
maxHealth = Math.Max(ToolBox.GetAttributeFloat(element, "health", 100.0f),1.0f);
armorSector = ToolBox.GetAttributeVector2(element, "armorsector", Vector2.Zero);
armorSector.X = MathHelper.ToRadians(armorSector.X);
armorSector.Y = MathHelper.ToRadians(armorSector.Y);
armorValue = Math.Max(ToolBox.GetAttributeFloat(element, "armor", 1.0f), 1.0f);
body.BodyType = BodyType.Dynamic;
body.FarseerBody.AngularDamping = LimbAngularDamping;
@@ -248,6 +257,62 @@ namespace Subsurface
body.ApplyLinearImpulse((deltaPos - vel * 0.5f) * body.Mass, pullPos);
}
public void AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound)
{
DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;
if (armorSector != Vector2.Zero)
{
float rot = body.Rotation;
if (Dir == -1) rot -= MathHelper.Pi;
Vector2 armorLimits = new Vector2(rot-armorSector.X*Dir, rot-armorSector.Y*Dir);
float mid = (armorLimits.X + armorLimits.Y) / 2.0f;
float angleDiff = ToolBox.GetShortestAngle(ToolBox.VectorToAngle(position - SimPosition), mid);
if (Math.Abs(angleDiff) < (armorSector.Y-armorSector.X) / 2.0f) return;
}
if (playSound)
{
AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position);
}
Bleeding += bleedingAmount;
Damage += amount;
float bloodAmount = (int)Math.Min((int)(amount * 2.0f), 20);
//if (closestLimb.Damage>=100.0f)
//{
// bloodAmount *= 2;
// foreach (var joint in animController.limbJoints)
// {
// if (!(joint.BodyA == closestLimb.body.FarseerBody) && !(joint.BodyB == closestLimb.body.FarseerBody)) continue;
// joint.Enabled = false;
// break;
// }
//}
for (int i = 0; i < bloodAmount; i++)
{
Vector2 particleVel = SimPosition - position;
if (particleVel != Vector2.Zero) particleVel = Vector2.Normalize(particleVel);
Game1.particleManager.CreateParticle("blood",
SimPosition,
particleVel * ToolBox.RandomFloat(1.0f, 3.0f));
}
for (int i = 0; i < bloodAmount / 2; i++)
{
Game1.particleManager.CreateParticle("waterblood", SimPosition, Vector2.Zero);
}
}
public void Update(float deltaTime)
{
if (LinearVelocity.X>100.0f)

View File

@@ -8,11 +8,11 @@ using System.Xml.Linq;
namespace Subsurface
{
public enum DamageType { None, Blunt, Slash };
class Attack
{
public enum DamageType { None, Blunt, Slash };
public enum Type
{
@@ -70,26 +70,26 @@ namespace Subsurface
public void DoDamage(IDamageable target, Vector2 position, float deltaTime, bool playSound=true)
{
float damageAmount = 0.0f;
DamageSoundType damageSoundType = DamageSoundType.None;
//DamageSoundType damageSoundType = DamageSoundType.None;
if (target as Character == null)
{
damageAmount = structureDamage;
damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt: DamageSoundType.StructureSlash;
//damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt: DamageSoundType.StructureSlash;
}
else
{
damageAmount = damage;
damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;
//damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;
}
if (playSound) AmbientSoundManager.PlayDamageSound(damageSoundType, damageAmount, position);
//damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash;
//if (playSound) AmbientSoundManager.PlayDamageSound(damageSoundType, damageAmount, position);
if (duration > 0.0f) damageAmount *= deltaTime;
float bleedingAmount = (duration == 0.0f) ? bleedingDamage : bleedingDamage * deltaTime;
if (damageAmount>0.0f) target.AddDamage(position, damageAmount, bleedingAmount, stun);
if (damageAmount>0.0f) target.AddDamage(position, damageType, damageAmount, bleedingAmount, stun, playSound);
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Xml.Linq;
@@ -9,6 +10,7 @@ namespace Subsurface
class StatusEffect
{
[Flags]
public enum Target
{
@@ -20,6 +22,8 @@ namespace Subsurface
public string[] propertyNames;
private object[] propertyEffects;
private bool disableDeltaTime;
private string[] onContainingNames;
@@ -60,7 +64,9 @@ namespace Subsurface
{
IEnumerable<XAttribute> attributes = element.Attributes();
List<XAttribute> propertyAttributes = new List<XAttribute>();
disableDeltaTime = ToolBox.GetAttributeBool(element, "disabledeltatime", false);
foreach (XAttribute attribute in attributes)
{
switch (attribute.Name.ToString())
@@ -179,13 +185,14 @@ namespace Subsurface
protected void ApplyToProperty(ObjectProperty property, object value, float deltaTime)
{
if (disableDeltaTime) deltaTime = 1.0f;
Type type = value.GetType();
if (type == typeof(float))
{
property.TrySetValue((float)property.GetValue() + (float)value * deltaTime);
}
if (type == typeof(int))
else if (type == typeof(int))
{
property.TrySetValue((int)property.GetValue() + (int)value * deltaTime);
}