improved humanoid animations, some map stats in map editor, gap connections visible in editor, editing wire nodes in editor, pumps don't have to be manually linked, coroutine exception handling

This commit is contained in:
Regalis
2015-09-15 17:24:52 +03:00
parent d29ee03681
commit 16bf562837
21 changed files with 254 additions and 136 deletions
+32 -16
View File
@@ -680,17 +680,8 @@ namespace Subsurface
public void Update(Camera cam, float deltaTime)
{
if (isDead)
{
if (controlled == this)
{
cam.Zoom = MathHelper.Lerp(cam.Zoom, 1.5f, 0.1f);
cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition);
cam.OffsetAmount = 0.0f;
}
return;
}
if (isDead) return;
if (PressureProtection==0.0f &&
(AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure >= 100.0f))
{
@@ -953,15 +944,40 @@ namespace Subsurface
Kill(true);
}
private IEnumerable<object> DeathAnim()
private IEnumerable<object> DeathAnim(Camera cam)
{
float timer = 8.0f;
float dimDuration = 8.0f;
float timer = 0.0f;
while (timer > 0.0f)
Color prevAmbientLight = Game1.LightManager.AmbientLight;
while (timer < dimDuration)
{
AnimController.UpdateAnim(1.0f / 60.0f);
timer -= 1.0f / 60.0f;
timer += 1.0f / 60.0f;
if (cam != null)
{
cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.limbs[0].SimPosition);
cam.OffsetAmount = 0.0f;
}
Game1.LightManager.AmbientLight = Color.Lerp(prevAmbientLight, Color.DarkGray, timer / dimDuration);
yield return CoroutineStatus.Running;
}
while (Character.Controlled == this)
{
yield return CoroutineStatus.Running;
}
float lerpLightBack = 0.0f;
while (lerpLightBack<1.0f)
{
lerpLightBack = Math.Min(lerpLightBack+0.05f,1.0f);
Game1.LightManager.AmbientLight = Color.Lerp(Color.DarkGray, prevAmbientLight, lerpLightBack);
yield return CoroutineStatus.Running;
}
@@ -985,7 +1001,7 @@ namespace Subsurface
}
}
CoroutineManager.StartCoroutine(DeathAnim());
CoroutineManager.StartCoroutine(DeathAnim(Game1.GameScreen.Cam));
health = 0.0f;
@@ -11,9 +11,21 @@ namespace Subsurface
{
private bool aiming;
private float walkAnimSpeed;
private float movementLerp;
private float thighTorque;
public HumanoidAnimController(Character character, XElement element)
: base(character, element)
{
walkAnimSpeed = ToolBox.GetAttributeFloat(element, "walkanimspeed", 4.0f);
walkAnimSpeed = MathHelper.ToRadians(walkAnimSpeed);
movementLerp = ToolBox.GetAttributeFloat(element, "movementlerp", 0.4f);
thighTorque = ToolBox.GetAttributeFloat(element, "thightorque", -5.0f);
}
public override void UpdateAnim(float deltaTime)
@@ -26,7 +38,7 @@ namespace Subsurface
Vector2 colliderPos = GetLimb(LimbType.Torso).SimPosition;
if (inWater) stairs = null;
//if (inWater) stairs = null;
Vector2 rayStart = colliderPos; // at the bottom of the player sprite
Vector2 rayEnd = rayStart - new Vector2(0.0f, TorsoPosition);
@@ -42,7 +54,7 @@ namespace Subsurface
switch (fixture.CollisionCategories)
{
case Physics.CollisionStairs:
if (inWater) return -1;
if (inWater && TargetMovement.Y < 0.5f) return -1;
Structure structure = fixture.Body.UserData as Structure;
if (stairs == null && structure!=null)
{
@@ -155,6 +167,8 @@ namespace Subsurface
aiming = false;
}
void UpdateStanding()
{
Vector2 handPos;
@@ -164,6 +178,8 @@ namespace Subsurface
Limb head = GetLimb(LimbType.Head);
Limb torso = GetLimb(LimbType.Torso);
Limb waist = GetLimb(LimbType.Waist);
Limb leftHand = GetLimb(LimbType.LeftHand);
Limb rightHand = GetLimb(LimbType.RightHand);
@@ -171,7 +187,7 @@ namespace Subsurface
Limb rightLeg = GetLimb(LimbType.RightLeg);
float getUpSpeed = 0.3f;
float walkCycleSpeed = head.LinearVelocity.X * 0.08f;
float walkCycleSpeed = head.LinearVelocity.X * walkAnimSpeed;
if (stairs != null)
{
TargetMovement = new Vector2(MathHelper.Clamp(TargetMovement.X, -2.0f, 2.0f), TargetMovement.Y) ;
@@ -183,7 +199,6 @@ namespace Subsurface
}
else
{
TargetMovement /= 1.2f;
}
@@ -200,9 +215,9 @@ namespace Subsurface
this.stepSize.X * walkPosX * runningModifier,
this.stepSize.Y * walkPosY * runningModifier * runningModifier);
float footMid = (leftFoot.SimPosition.X + rightFoot.SimPosition.X) / 2.0f;
float footMid = waist.SimPosition.X;// (leftFoot.SimPosition.X + rightFoot.SimPosition.X) / 2.0f;
movement = MathUtils.SmoothStep(movement, TargetMovement, 0.4f);
movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp);
movement.Y = 0.0f;
//place the anchors of the head and the torso to make the ragdoll stand
@@ -230,12 +245,17 @@ namespace Subsurface
torso.pullJoint.Enabled = true;
torso.pullJoint.WorldAnchorB =
MathUtils.SmoothStep(torso.SimPosition,
new Vector2(footMid + movement.X * 0.35f, colliderPos.Y + TorsoPosition), getUpSpeed);
new Vector2(footMid + movement.X * 0.3f, colliderPos.Y + TorsoPosition), getUpSpeed);
head.pullJoint.Enabled = true;
head.pullJoint.WorldAnchorB =
MathUtils.SmoothStep(head.SimPosition,
new Vector2(footMid + movement.X * 0.4f, colliderPos.Y + HeadPosition), getUpSpeed);
new Vector2(footMid + movement.X * (0.2f + runningModifier / 10.0f), colliderPos.Y + HeadPosition), getUpSpeed);
waist.pullJoint.Enabled = true;
waist.pullJoint.WorldAnchorB = waist.SimPosition + movement*0.1f;
//MathUtils.SmoothStep(waist.SimPosition,
//new Vector2(footMid + movement.X * 0.4f, colliderPos.Y + HeadPosition), getUpSpeed);
}
@@ -257,31 +277,40 @@ namespace Subsurface
(-stepSize.Y > 0.0f) ? -stepSize.Y : -0.15f),
15.0f, true);
if (Math.Sign(stepSize.X) == Math.Sign(Dir))
leftFoot.body.SmoothRotate(leftLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier);
rightFoot.body.SmoothRotate(rightLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier);
if (runningModifier>1.0f)
{
leftFoot.body.SmoothRotate(leftLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier);
}
else if (Math.Sign(-stepSize.X) == Math.Sign(Dir))
{
rightFoot.body.SmoothRotate(rightLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20 * runningModifier);
if (walkPosY > 0.0f)
{
GetLimb(LimbType.LeftThigh).body.ApplyTorque(-walkPosY * Dir * Math.Abs(movement.X) * thighTorque);
}
else
{
GetLimb(LimbType.RightThigh).body.ApplyTorque(walkPosY * Dir * Math.Abs(movement.X) * thighTorque);
}
}
if (walkPosY > 0.0f)
if (legTorque>0.0f)
{
GetLimb(LimbType.LeftThigh).body.ApplyTorque(-walkPosY * Dir * Math.Abs(movement.X) * -5.0f);
}
else
{
GetLimb(LimbType.RightThigh).body.ApplyTorque(walkPosY * Dir * Math.Abs(movement.X) * -5.0f);
if (Math.Sign(walkPosX) != Math.Sign(movement.X))
{
GetLimb(LimbType.LeftLeg).body.ApplyTorque(-walkPosY * Dir * Math.Abs(movement.X) * legTorque / runningModifier);
}
else
{
GetLimb(LimbType.RightLeg).body.ApplyTorque(walkPosY * Dir * Math.Abs(movement.X) * legTorque / runningModifier);
}
}
//calculate the positions of hands
handPos = torso.SimPosition;
handPos.X = -walkPosX * 0.1f * runningModifier;
handPos.X = -walkPosX * 0.2f;// *runningModifier;
float lowerY = -0.6f + runningModifier/3.5f;
handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(walkPos - Math.PI * 1.5f) * 0.1)) / runningModifier;
handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(walkPos - Math.PI * 1.5f) * 0.05)) / runningModifier;
Vector2 posAdditon = new Vector2(movement.X*0.07f, 0.0f);
if (stairs!=null)
@@ -321,11 +350,6 @@ namespace Subsurface
}
else
{
//add torque to the head to do a subtle "breathing" effect
//head.body.ApplyTorque((float)Math.Sin(gameTime.TotalGameTime.TotalMilliseconds / 300) * 0.2f);
//standing still -> "attach" the feet to the ground
float movementFactor = (movement.X / 4.0f) * movement.X * Math.Sign(movement.X);
Vector2 footPos = new Vector2(
@@ -337,13 +361,7 @@ namespace Subsurface
leftFoot.body.SmoothRotate(Dir * MathHelper.PiOver2, 5.0f);
rightFoot.body.SmoothRotate(Dir * MathHelper.PiOver2, 5.0f);
//handPos = torso.SimPosition;
//handPos.X += movement.X;
//handPos.Y -= 0.4f;
if (!rightHand.Disabled)
{
// MoveLimb(rightHand, handPos, 0.05f, true);
+1 -1
View File
@@ -426,7 +426,7 @@ namespace Subsurface
if (pullJoint!=null)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)pos.Y, 5, 5), Color.Red, true);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
}
if (bodyShapeTexture == null)
+11 -7
View File
@@ -283,13 +283,15 @@ 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 (targetMovement.Y < 0.5f)
{
stairs = null;
return false;
if (inWater || lowestLimb.Position.Y < structure.Rect.Y - structure.Rect.Height + 50.0f)
{
stairs = null;
return false;
}
}
if (targetMovement.Y >= 0.0f && lowestLimb.SimPosition.Y > ConvertUnits.ToSimUnits(structure.Rect.Y - Submarine.GridSize.Y * 8.0f))
{
stairs = null;
@@ -367,12 +369,14 @@ namespace Subsurface
if (limb.pullJoint != null)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(limb.pullJoint.WorldAnchorA);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true, 0.01f);
pos.Y = -pos.Y;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)pos.Y, 5, 5), Color.Red, true, 0.01f);
if (limb.AnimTargetPos == Vector2.Zero) continue;
Vector2 pos2 = ConvertUnits.ToDisplayUnits(limb.AnimTargetPos);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos2.X, (int)-pos2.Y, 5, 5), Color.Blue, true, 0.01f);
pos2.Y = -pos2.Y;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos2.X, (int)pos2.Y, 5, 5), Color.Blue, true, 0.01f);
GUI.DrawLine(spriteBatch, pos, pos2, Color.Green);
}