Melee weapons (+ stun baton), improved throw animation, new damage sound effects

This commit is contained in:
Regalis
2015-09-07 16:31:04 +03:00
parent b77fa5df90
commit 7eae6fb026
38 changed files with 527 additions and 163 deletions

View File

@@ -148,7 +148,7 @@ namespace Subsurface
Limb limb = Character.AnimController.limbs[0];
distanceAccumulator += (limb.SimPosition - prevPosition).Length();
prevPosition = limb.body.Position;
prevPosition = limb.body.SimPosition;
}
private void UpdateAttack(float deltaTime)

View File

@@ -55,7 +55,7 @@ namespace Subsurface
public virtual void UpdateAnim(float deltaTime) { }
public virtual void HoldItem(float deltaTime, Camera cam, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, float holdAngle) { }
public virtual void HoldItem(float deltaTime, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, bool aim, float holdAngle) { }
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Subsurface.Particles;
using System;
using System.Xml.Linq;
@@ -42,6 +43,10 @@ namespace Subsurface
public readonly float Damage;
public readonly float BleedingDamage;
private Sound sound;
private ParticleEmitterPrefab particleEmitterPrefab;
public readonly float Stun;
private float priority;
@@ -73,12 +78,23 @@ namespace Subsurface
Stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f);
string soundPath = ToolBox.GetAttributeString(element, "sound", "");
if (!string.IsNullOrWhiteSpace(soundPath))
{
sound = Sound.Load(soundPath);
}
Range = FarseerPhysics.ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "range", 0.0f));
Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f);
priority = ToolBox.GetAttributeFloat(element, "priority", 1.0f);
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLower() == "particleemitter") particleEmitterPrefab = new ParticleEmitterPrefab(subElement);
}
}
public AttackResult DoDamage(IDamageable target, Vector2 position, float deltaTime, bool playSound = true)
@@ -89,28 +105,28 @@ namespace Subsurface
if (target as Character == null)
{
damageAmount = StructureDamage;
//damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt: DamageSoundType.StructureSlash;
}
else
{
damageAmount = Damage;
//damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;
}
//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)
if (particleEmitterPrefab != null)
{
return target.AddDamage(position, DamageType, damageAmount, bleedingAmount, Stun, playSound);
particleEmitterPrefab.Emit(position);
}
else
if (sound!=null)
{
return new AttackResult(0.0f, 0.0f);
sound.Play(1.0f, 500.0f, position);
}
return target.AddDamage(position, DamageType, damageAmount, bleedingAmount, Stun, playSound);
}
}
}

View File

@@ -549,7 +549,7 @@ namespace Subsurface
if (GetInputState(InputType.ActionHeld)) selectedConstruction.Use(deltaTime, this);
if (GetInputState(InputType.SecondaryHeld)) selectedConstruction.SecondaryUse(deltaTime, this);
}
if (IsNetworkPlayer)
{
foreach (Key key in keys)
@@ -920,9 +920,6 @@ namespace Subsurface
private void Implode()
{
Limb torso= AnimController.GetLimb(LimbType.Torso);
if (torso == null) torso = AnimController.GetLimb(LimbType.Head);
Vector2 centerOfMass = AnimController.GetCenterOfMass();
health = 0.0f;
@@ -935,17 +932,17 @@ namespace Subsurface
// limb.Damage = 100.0f;
}
AmbientSoundManager.PlayDamageSound(DamageSoundType.Implode, 50.0f, torso.body.FarseerBody);
AmbientSoundManager.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body.FarseerBody);
for (int i = 0; i < 10; i++)
{
Particle p = Game1.ParticleManager.CreateParticle("waterblood",
torso.Position + new Vector2(Rand.Range(-50f, 50f), Rand.Range(-50f, 50f)),
centerOfMass + Rand.Vector(50.0f),
Vector2.Zero);
if (p!=null) p.Size *= 2.0f;
Game1.ParticleManager.CreateParticle("bubbles",
torso.SimPosition,
centerOfMass + Rand.Vector(50.0f),
new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f,50f)));
}
@@ -1083,8 +1080,8 @@ namespace Subsurface
int i = 0;
foreach (Limb limb in AnimController.limbs)
{
message.Write(limb.body.Position.X);
message.Write(limb.body.Position.Y);
message.Write(limb.body.SimPosition.X);
message.Write(limb.body.SimPosition.Y);
//message.Write(limb.body.LinearVelocity.X);
//message.Write(limb.body.LinearVelocity.Y);
@@ -1103,8 +1100,8 @@ namespace Subsurface
}
else
{
message.Write(AnimController.RefLimb.Position.X);
message.Write(AnimController.RefLimb.Position.Y);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
LargeUpdateTimer = Math.Max(0, LargeUpdateTimer-1);
}

View File

@@ -202,7 +202,7 @@ namespace Subsurface
float footMid = (leftFoot.SimPosition.X + rightFoot.SimPosition.X) / 2.0f;
movement = MathUtils.SmoothStep(movement, TargetMovement, 0.5f);
movement = MathUtils.SmoothStep(movement, TargetMovement, 0.4f);
movement.Y = 0.0f;
//place the anchors of the head and the torso to make the ragdoll stand
@@ -678,7 +678,54 @@ namespace Subsurface
//MoveLimb(rightLeg, footPos, 0.7f);
}
public override void HoldItem(float deltaTime, Camera cam, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, float holdAngle)
//float punchTimer;
//bool punching;
//public void Punch()
//{
// if (punchTimer < 0.01f) punching = true;
// Limb rightHand = GetLimb(LimbType.RightHand);
// Limb head = GetLimb(LimbType.Head);
// Vector2 diff = Vector2.Normalize(character.CursorPosition - RefLimb.Position);
// rightHand.body.ApplyLinearImpulse(diff * 20.0f);
// head.body.ApplyLinearImpulse(diff * 5.0f);
// head.body.ApplyTorque(Dir*100.0f);
//}
//public void Block(float deltaTime)
//{
// Limb head = GetLimb(LimbType.Head);
// Limb torso = GetLimb(LimbType.Torso);
// Limb leftHand = GetLimb(LimbType.LeftHand);
// Limb leftFoot = GetLimb(LimbType.LeftFoot);
// Limb rightHand = GetLimb(LimbType.RightHand);
// Vector2 pos = head.SimPosition;
// rightHand.Disabled = true;
// leftHand.Disabled = true;
// HandIK(leftHand, pos + new Vector2(0.25f*Dir, 0.0f));
// if (punching)
// {
// punchTimer += deltaTime*10.0f;
// if (punchTimer>2.0f)
// {
// punching = false;
// }
// }
// else
// {
// punchTimer = MathHelper.Lerp(punchTimer, 0.0f, 0.3f);
// HandIK(rightHand, pos + new Vector2((0.3f + punchTimer) * Dir, 0.1f));
// }
//}
public override void HoldItem(float deltaTime, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, bool aim, float holdAngle)
{
//calculate the handle positions
Matrix itemTransfrom = Matrix.CreateRotationZ(item.body.Rotation);
@@ -689,14 +736,12 @@ namespace Subsurface
Limb head = GetLimb(LimbType.Head);
Limb torso = GetLimb(LimbType.Torso);
Limb leftHand = GetLimb(LimbType.LeftHand);
Limb leftArm = GetLimb(LimbType.LeftArm);
Limb rightHand = GetLimb(LimbType.RightHand);
Limb rightArm = GetLimb(LimbType.RightArm);
Vector2 itemPos = character.GetInputState(InputType.SecondaryHeld) ? aimPos : holdPos;
Vector2 itemPos = aim ? aimPos : holdPos;
float itemAngle;
if (stunTimer <= 0.0f && character.GetInputState(InputType.SecondaryHeld) && itemPos != Vector2.Zero)
if (stunTimer <= 0.0f && aim && itemPos != Vector2.Zero)
{
Vector2 mousePos = ConvertUnits.ToSimUnits(character.CursorPosition);
@@ -731,13 +776,11 @@ namespace Subsurface
{
transformedHoldPos = rightHand.pullJoint.WorldAnchorA - transformedHandlePos[0];
itemAngle = (rightHand.Rotation + (holdAngle - MathHelper.PiOver2) * Dir);
//rightHand.Disabled = true;
}
if (character.SelectedItems[1] == item)
{
transformedHoldPos = leftHand.pullJoint.WorldAnchorA - transformedHandlePos[1];
itemAngle = (leftHand.Rotation + (holdAngle - MathHelper.PiOver2) * Dir);
//leftHand.Disabled = true;
}
}
else
@@ -759,13 +802,10 @@ namespace Subsurface
transformedHoldPos += Vector2.Transform(itemPos, torsoTransform);
}
Vector2 bodyVelocity = torso.body.LinearVelocity / 60.0f;
item.body.ResetDynamics();
item.body.SetTransform(MathUtils.SmoothStep(item.body.Position, transformedHoldPos + bodyVelocity, 0.5f), itemAngle);
//item.body.SmoothRotate(itemAngle, 50.0f);
item.body.SetTransform(MathUtils.SmoothStep(item.body.SimPosition, transformedHoldPos + bodyVelocity, 0.5f), itemAngle);
for (int i = 0; i < 2; i++)
{
@@ -775,26 +815,6 @@ namespace Subsurface
Limb hand = (i == 0) ? rightHand : leftHand;
HandIK(hand, transformedHoldPos + transformedHandlePos[i]);
//Limb arm = (i == 0) ? rightArm : leftArm;
////hand length
//float a = 37.0f;
////arm length
//float b = 28.0f;
////distance from shoulder to holdpos
//float c = ConvertUnits.ToDisplayUnits(Vector2.Distance(transformedHoldPos + transformedHandlePos[i], shoulderPos));
//c = MathHelper.Clamp(a + b - 1, b-a, c);
//float ang2 = MathUtils.VectorToAngle((transformedHoldPos + transformedHandlePos[i]) - shoulderPos)+MathHelper.PiOver2;
//float armAngle = MathUtils.SolveTriangleSSS(a, b, c);
//float handAngle = MathUtils.SolveTriangleSSS(b, a, c);
//arm.body.SmoothRotate((ang2 - armAngle * Dir), 20.0f);
//hand.body.SmoothRotate((ang2 + handAngle * Dir), 100.0f);
}
}
@@ -837,7 +857,7 @@ namespace Subsurface
{
if (character.SelectedItems[i] != null)
{
difference = character.SelectedItems[i].body.Position - torso.SimPosition;
difference = character.SelectedItems[i].body.SimPosition - torso.SimPosition;
difference = Vector2.Transform(difference, torsoTransform);
difference.Y = -difference.Y;
@@ -855,14 +875,14 @@ namespace Subsurface
case LimbType.LeftArm:
case LimbType.RightHand:
case LimbType.RightArm:
difference = l.body.Position - torso.SimPosition;
difference = l.body.SimPosition - torso.SimPosition;
difference = Vector2.Transform(difference, torsoTransform);
difference.Y = -difference.Y;
l.body.SetTransform(torso.SimPosition + Vector2.Transform(difference, -torsoTransform), -l.body.Rotation);
break;
default:
if (!inWater) l.body.SetTransform(l.body.Position,
if (!inWater) l.body.SetTransform(l.body.SimPosition,
MathUtils.WrapAnglePi(l.body.Rotation * (l.DoesFlip ? -1.0f : 1.0f)));
break;
}

View File

@@ -79,12 +79,12 @@ namespace Subsurface
public Vector2 Position
{
get { return ConvertUnits.ToDisplayUnits(body.Position); }
get { return ConvertUnits.ToDisplayUnits(body.SimPosition); }
}
public Vector2 SimPosition
{
get { return body.Position; }
get { return body.SimPosition; }
}
public float Rotation
@@ -271,7 +271,7 @@ namespace Subsurface
public void Move(Vector2 pos, float amount, bool pullFromCenter=false)
{
Vector2 pullPos = body.Position;
Vector2 pullPos = body.SimPosition;
if (pullJoint!=null && !pullFromCenter)
{
pullPos = pullJoint.WorldAnchorA;
@@ -318,19 +318,8 @@ namespace Subsurface
//Bleeding += bleedingAmount;
//Damage += amount;
float bloodAmount = hitArmor ? 0 : (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;
// }
//}
float bloodAmount = hitArmor || bleedingAmount<=0.0f ? 0 : (int)Math.Min((int)(amount * 2.0f), 20);
for (int i = 0; i < bloodAmount; i++)
{
Vector2 particleVel = SimPosition - position;
@@ -357,7 +346,7 @@ namespace Subsurface
foreach (Limb limb in character.AnimController.limbs)
{
limb.body.ResetDynamics();
limb.body.SetTransform(body.Position, 0.0f);
limb.body.SetTransform(body.SimPosition, 0.0f);
}
}

View File

@@ -283,7 +283,8 @@ namespace Subsurface
}
else if (structure.StairDirection!=Direction.None)
{
if (inWater || !(targetMovement.Y>Math.Abs(targetMovement.X/2.0f)) && lowestLimb.Position.Y < structure.Rect.Y - structure.Rect.Height + 50.0f)
if ((inWater || !(targetMovement.Y>Math.Abs(targetMovement.X/2.0f))) &&
lowestLimb.Position.Y < structure.Rect.Y - structure.Rect.Height + 50.0f)
{
stairs = null;
return false;
@@ -341,9 +342,13 @@ namespace Subsurface
if (impact > 1.0f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(Math.Min(impact / 5.0f, 1.0f), impact * 100.0f, l.body.FarseerBody);
if (impact > l.impactTolerance)
{
{
character.Health -= (impact - l.impactTolerance * 0.1f);
strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance);
AmbientSoundManager.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body.FarseerBody);
if (Character.Controlled == character) Game1.GameScreen.Cam.Shake = strongestImpact;
}
}
@@ -385,7 +390,10 @@ namespace Subsurface
if (refLimb.body.TargetPosition != Vector2.Zero)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(refLimb.body.TargetPosition);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X-5, (int)-pos.Y-5, 10, 10), Color.LightBlue, false);
pos.Y = -pos.Y;
GUI.DrawLine(spriteBatch, pos+new Vector2(-30.0f,0.0f), pos+new Vector2(30.0f,0.0f), Color.LightBlue);
GUI.DrawLine(spriteBatch, pos + new Vector2(0.0f,-30.0f), pos + new Vector2(0.0f,30.0f), Color.LightBlue);
}
@@ -502,7 +510,8 @@ namespace Subsurface
inWater = false;
headInWater = false;
if (currentHull.Volume > currentHull.FullVolume * 0.95f || ConvertUnits.ToSimUnits(currentHull.Surface) - floorY > HeadPosition * 0.95f)
if (currentHull.Volume > currentHull.FullVolume * 0.95f ||
ConvertUnits.ToSimUnits(currentHull.Surface) - floorY > HeadPosition * 0.95f)
inWater = true;
}
@@ -517,13 +526,13 @@ namespace Subsurface
bool prevInWater = limb.inWater;
limb.inWater = false;
if (limbHull==null)
if (limbHull == null)
{
//limb isn't in any room -> it's in the water
limb.inWater = true;
}
else if (limbHull.Volume>0.0f && Submarine.RectContains(limbHull.Rect, limbPosition))
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limbPosition))
{
if (limbPosition.Y < limbHull.Surface)
@@ -578,9 +587,7 @@ namespace Subsurface
limbHull.WaveVel[n] = Math.Min(impulse.Y * 1.0f, 5.0f);
StrongestImpact = ((impulse.Length() * 0.5f) - limb.impactTolerance);
}
}
}
}
limb.Update(deltaTime);
@@ -591,7 +598,11 @@ namespace Subsurface
private void UpdateNetplayerPosition()
{
if (refLimb.body.TargetPosition == Vector2.Zero) return;
if (refLimb.body.TargetPosition == Vector2.Zero)
{
correctionMovement = Vector2.Zero;
return;
}
//if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
float resetDistance = NetConfig.ResetRagdollDistance;
@@ -599,10 +610,10 @@ namespace Subsurface
//if the limb is closer than alloweddistance, just ignore the difference
float allowedDistance = NetConfig.AllowedRagdollDistance;
float dist = Vector2.Distance(refLimb.body.Position, refLimb.body.TargetPosition);
float dist = Vector2.Distance(refLimb.body.SimPosition, refLimb.body.TargetPosition);
bool resetAll = (dist > resetDistance && character.LargeUpdateTimer == 1);
Vector2 newMovement = (refLimb.body.TargetPosition - refLimb.body.Position);
Vector2 newMovement = (refLimb.body.TargetPosition - refLimb.body.SimPosition);
if (newMovement == Vector2.Zero || newMovement.Length() < allowedDistance)
{
@@ -623,7 +634,7 @@ namespace Subsurface
}
else
{
correctionMovement = Vector2.Normalize(newMovement) * Math.Min(1.0f + dist, 3.0f);
correctionMovement = Vector2.Normalize(newMovement) * Math.Min(0.1f + dist, 3.0f);
if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
}
}