Rendering lights, fow penumbra, human anim tweaking, female sprite, electricity bugfixes

This commit is contained in:
Regalis
2015-07-24 00:36:44 +03:00
parent 4820e55e05
commit c2be74324d
36 changed files with 334 additions and 150 deletions
+56 -31
View File
@@ -164,10 +164,19 @@ namespace Subsurface
float walkCycleSpeed = head.LinearVelocity.X * 0.08f;
if (stairs != null)
{
if (TargetMovement!=Vector2.Zero && TargetMovement.Length()>3.0f)
TargetMovement = new Vector2(MathHelper.Clamp(TargetMovement.X, -2.0f, 2.0f), TargetMovement.Y) ;
if ((TargetMovement.X>0.0f && stairs.StairDirection == Direction.Right) ||
TargetMovement.X < 0.0f && stairs.StairDirection == Direction.Left)
{
TargetMovement /= TargetMovement.Length() / 3.0f;
TargetMovement *= 1.35f;
}
else
{
TargetMovement /= 1.2f;
}
walkCycleSpeed *= 1.5f;
}
@@ -211,12 +220,12 @@ namespace Subsurface
torso.pullJoint.Enabled = true;
torso.pullJoint.WorldAnchorB =
MathUtils.SmoothStep(torso.SimPosition,
new Vector2(footMid + movement.X * 0.35f, colliderPos.Y + TorsoPosition - Math.Abs(walkPosX * 0.05f)), getUpSpeed);
new Vector2(footMid + movement.X * 0.35f, 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 - Math.Abs(walkPosX * 0.05f)), getUpSpeed);
new Vector2(footMid + movement.X * 0.4f, colliderPos.Y + HeadPosition), getUpSpeed);
}
@@ -224,46 +233,47 @@ namespace Subsurface
if (TargetMovement.X != 0.0f)
{
//progress the walking animation
walkPos -= (walkCycleSpeed / runningModifier);
walkPos -= (walkCycleSpeed / runningModifier)*0.8f;
MoveLimb(leftFoot,
colliderPos + new Vector2(
stepSize.X,
(stepSize.Y > 0.0f) ? stepSize.Y : -0.15f),
10.0f, true);
15.0f, true);
MoveLimb(rightFoot,
colliderPos + new Vector2(
-stepSize.X,
(-stepSize.Y > 0.0f) ? -stepSize.Y : -0.15f),
10.0f, true);
15.0f, true);
if (Math.Sign(stepSize.X) == Math.Sign(Dir))
{
leftFoot.body.SmoothRotate(leftLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.3f, 20.0f * runningModifier);
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.3f, 20 * runningModifier);
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) * -2.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) * -2.0f);
GetLimb(LimbType.RightThigh).body.ApplyTorque(walkPosY * Dir * Math.Abs(movement.X) * -5.0f);
}
//calculate the positions of hands
handPos = torso.SimPosition;
handPos.X = -walkPosX * 0.25f;
handPos.X = -walkPosX * 0.1f * runningModifier;
float lowerY = -0.4f / runningModifier;
handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(walkPos - Math.PI * 1.5f) * 0.1)) * runningModifier;
float lowerY = -0.6f + runningModifier/3.5f;
handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(walkPos - Math.PI * 1.5f) * 0.1)) / runningModifier;
Vector2 posAdditon = new Vector2(movement.X*0.05f, 0.0f);
Vector2 posAdditon = new Vector2(movement.X*0.07f, 0.0f);
if (stairs!=null)
{
if ((stairs.StairDirection == Direction.Right && movement.X < 0.0f) ||
@@ -273,7 +283,7 @@ namespace Subsurface
}
else
{
posAdditon.Y += 0.1f;
posAdditon.Y += 0.1f;
}
}
@@ -318,17 +328,30 @@ 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;
//handPos = torso.SimPosition;
//handPos.X += movement.X;
//handPos.Y -= 0.4f;
if (!rightHand.Disabled)
{
MoveLimb(rightHand, handPos, 1.5f, true);
// MoveLimb(rightHand, handPos, 0.05f, true);
//rightHand.body.ApplyLinearImpulse((handPos - rightHand.Position));
rightHand.body.SmoothRotate(0.0f, 5.0f);
var rightArm = GetLimb(LimbType.RightArm);
rightArm.body.SmoothRotate(0.0f, 20.0f);
}
if (!leftHand.Disabled)
{
MoveLimb(leftHand, handPos, 1.5f, true);
//MoveLimb(leftHand, handPos, 0.05f, true);
//leftHand.body.ApplyLinearImpulse((handPos - leftHand.Position));
leftHand.body.SmoothRotate(0.0f, 5.0f);
var leftArm = GetLimb(LimbType.LeftArm);
leftArm.body.SmoothRotate(0.0f, 20.0f);
}
}
}
@@ -554,7 +577,7 @@ namespace Subsurface
handPos = new Vector2(
ladderSimPos.X,
head.SimPosition.Y + 0.3f + movement.Y * 0.1f - ladderSimPos.Y);
head.SimPosition.Y + 0.5f + movement.Y * 0.1f - ladderSimPos.Y);
MoveLimb(leftHand,
new Vector2(handPos.X,
@@ -570,32 +593,34 @@ namespace Subsurface
rightHand.body.ApplyTorque(Dir * 2.0f);
footPos = new Vector2(
handPos.X + Dir*0.1f,
handPos.X - Dir*0.05f,
head.SimPosition.Y - stepHeight * 2.7f - ladderSimPos.Y);
//if (movement.Y < 0) footPos.Y += 0.05f;
MoveLimb(leftFoot,
new Vector2(footPos.X,
MathUtils.Round(footPos.Y + stepHeight, stepHeight * 2.0f) - stepHeight + ladderSimPos.Y),
7.5f, true);
15.5f, true);
MoveLimb(rightFoot,
new Vector2(footPos.X,
MathUtils.Round(footPos.Y, stepHeight * 2.0f) + ladderSimPos.Y),
7.5f, true);
15.5f, true);
//apply torque to the legs to make the knees bend
Limb leftLeg = GetLimb(LimbType.LeftLeg);
Limb rightLeg = GetLimb(LimbType.RightLeg);
leftLeg.body.ApplyTorque(Dir * -3.0f);
rightLeg.body.ApplyTorque(Dir * -3.0f);
leftLeg.body.ApplyTorque(Dir * -8.0f);
rightLeg.body.ApplyTorque(Dir * -8.0f);
//apply forces to the head and the torso to move the character up/down
float movementFactor = (handPos.Y / stepHeight) * (float)Math.PI;
movementFactor = 0.8f + (float)Math.Abs(Math.Sin(movementFactor));
Vector2 climbForce = new Vector2(0.0f, movement.Y + 0.5f) * movementFactor;
torso.body.ApplyForce(climbForce * 65.0f * torso.Mass);
Vector2 climbForce = new Vector2(0.0f, movement.Y + 0.4f) * movementFactor;
torso.body.ApplyForce(climbForce * 40.0f * torso.Mass);
head.body.SmoothRotate(0.0f);
Rectangle trigger = character.SelectedConstruction.Prefab.Triggers.First();
@@ -607,8 +632,8 @@ namespace Subsurface
// - reached the top or bottom of the ladder
if (Math.Abs(torso.LinearVelocity.Y) > 5.0f ||
TargetMovement.X != 0.0f ||
(TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition*2.0f) ||
(TargetMovement.Y > 0.0f && -handPos.Y < ConvertUnits.ToSimUnits(10.0f)))
(TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition*1.5f) ||
(TargetMovement.Y > 0.0f && handPos.Y > 0.3f))
{
Anim = Animation.None;
character.SelectedConstruction = null;
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

+40 -40
View File
@@ -1,87 +1,87 @@
<?xml version="1.0" encoding="utf-8" ?>
<character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,4" femaleheadid="1,2" drowningtime="30">
<character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,4" femaleheadid="1,4" drowningtime="30">
<name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" />
<ragdoll headposition="150" torsoposition="110"
stepsize="35.0, 10.0">
<ragdoll headposition="156" torsoposition="120"
stepsize="42.0, 12.0">
<!-- head -->
<limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="3.0">
<sprite texture="Content/Characters/Human/[GENDER]head[HEADID].png" sourcerect="1,1,37,38" depth="0.12" origin="0.5,0.5"/>
<sprite texture="Content/Characters/Human/[GENDER]head[HEADID].png" sourcerect="1,1,37,38" depth="0.04" origin="0.5,0.5"/>
</limb>
<!-- body -->
<limb id = "1" width="26" height="30" mass = "20" type="Torso" attackpriority="3" impacttolerance="5.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="32,0,36,39" depth="0.045" origin="0.5,0.5"/>
<limb id = "1" radius="14" height="21" mass = "20" type="Torso" attackpriority="3" impacttolerance="5.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="0,0,29,58" depth="0.05" origin="0.5,0.6"/>
</limb>
<limb id = "12" width="26" height="30" mass = "20" type="Waist" impacttolerance="5.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="35,30,37,31" depth="0.05" origin="0.5,0.5"/>
<limb id = "12" radius="13" mass = "20" type="Waist" impacttolerance="5.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,0,32,29" depth="0.045" origin="0.5,0.5"/>
</limb>
<!-- left arm -->
<limb id = "2" width="12" height="30" mass="3" type="LeftArm">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="0,0,16,34" depth="0.15" origin="0.5,0.5"/>
<limb id = "2" radius="8" height="20" mass="3" type="LeftArm">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="30,2,17,39" depth="0.15" origin="0.5,0.5"/>
</limb>
<limb id = "3" width="12" height="30" mass="3" type="LeftHand" pullpos="0.0,-15.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="16,0,16,49" depth="0.16" origin="0.5,0.5"/>
<limb id = "3" radius="6" height="26" mass="3" type="LeftHand" pullpos="0.0,-15.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="49,2,13,47" depth="0.16" origin="0.5,0.5"/>
</limb>
<!-- right arm -->
<limb id = "4" width="12" height="30" mass="3" type="RightArm">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="0,0,16,34" origin="0.5,0.5"/>
<limb id = "4" radius="8" height="20" mass="3" type="RightArm">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="30,2,17,39" depth="0.01" origin="0.5,0.5"/>
</limb>
<limb id = "5" width="12" height="30" mass ="3" type="RightHand" pullpos="0.0,-15.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="16,0,16,49" origin="0.5,0.5"/>
<limb id = "5" radius="6" height="26" mass ="3" type="RightHand" pullpos="0.0,-15.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="49,2,13,47" origin="0.5,0.5"/>
</limb>
<!-- left leg -->
<limb id = "6" width="12" height="30" mass = "8" type="LeftThigh">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,0,24,47" depth="0.16" origin="0.5,0.5"/>
<limb id = "6" radius="10" height="30" mass = "8" type="LeftThigh">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,32,26,48" depth="0.15" origin="0.5,0.5"/>
</limb>
<limb id = "7" width="12" height="30" mass = "5" type="LeftLeg">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="24,1,18,39" depth="0.15" origin="0.5,0.5"/>
<limb id = "7" radius="6" height="39" mass = "5" type="LeftLeg">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="32,0,22,50" depth="0.16" origin="0.5,0.5"/>
</limb>
<limb id = "8" width="6" height="16" mass = "2" type ="LeftFoot" flip="true" pullpos="-3.0,0.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="43,4,15,26" depth="0.14" origin="0.5,0.5"/>
<limb id = "8" radius="5" height="13" mass = "2" type ="LeftFoot" flip="true" pullpos="-5.0,0.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="35,53,16,25" depth="0.14" origin="0.5,0.5"/>
<sound file ="Content/step.ogg"/>
</limb>
<!-- right leg -->
<limb id = "9" width="12" height="30" mass = "8" type="RightThigh">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="1,1,24,47" depth="0.12" origin="0.5,0.5"/>
<limb id = "9" radius="10" height="30" mass = "8" type="RightThigh">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,32,26,48" depth="0.11" origin="0.5,0.5"/>
</limb>
<limb id = "10" width="12" height="30" mass = "5" type="RightLeg">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="24,1,18,39" depth="0.11" origin="0.5,0.5"/>
<limb id = "10" radius="6" height="39" mass = "5" type="RightLeg">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="32,0,22,50" depth="0.12" origin="0.5,0.5"/>
</limb>
<limb id = "11" width="6" height="16" mass = "2" type ="RightFoot" flip="true" pullpos="-3.0,0.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="43,4,15,26" depth="0.1" origin="0.5,0.5"/>
<limb id = "11" radius="5" height="13" mass = "2" type ="RightFoot" flip="true" pullpos="-5.0,0.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="35,53,16,25" depth="0.1" origin="0.5,0.5"/>
<sound file ="Content/step.ogg"/>
</limb>
<!-- head to body -->
<joint limb1="0" limb1anchor="0,-13" limb2="1" limb2anchor="0,10" lowerlimit="-90" upperlimit="45"/>
<joint limb1="1" limb1anchor="0,-10" limb2="12" limb2anchor="0,10" lowerlimit="-40" upperlimit="40"/>
<joint limb1="0" limb1anchor="0,-13" limb2="1" limb2anchor="-1,20" lowerlimit="-90" upperlimit="45"/>
<joint limb1="1" limb1anchor="0,-17" limb2="12" limb2anchor="0,7" lowerlimit="-10" upperlimit="10"/>
<!-- body to left arm -->
<joint limb1="1" limb1anchor="-5,0" limb2="2" limb2anchor="0,10"/>
<joint limb1="2" limb1anchor="2,-14" limb2="3" limb2anchor="0,19" lowerlimit="0" upperlimit="170"/>
<joint limb1="1" limb1anchor="-3,14" limb2="2" limb2anchor="0,12"/>
<joint limb1="2" limb1anchor="0,-16" limb2="3" limb2anchor="-2,19" lowerlimit="0" upperlimit="170"/>
<!-- body to right arm -->
<joint limb1="1" limb1anchor="-5,0" limb2="4" limb2anchor="0,10"/>
<joint limb1="4" limb1anchor="2,-14" limb2="5" limb2anchor="0,19" lowerlimit="0" upperlimit="170"/>
<joint limb1="1" limb1anchor="-3,14" limb2="4" limb2anchor="0,12"/>
<joint limb1="4" limb1anchor="0,-16" limb2="5" limb2anchor="-2,19" lowerlimit="0" upperlimit="170"/>
<!-- body to left leg -->
<joint limb1="12" limb1anchor="0,-10" limb2="6" limb2anchor="0,14" lowerlimit="-30" upperlimit="140"/>
<joint limb1="6" limb1anchor="0,-15" limb2="7" limb2anchor="0,14" lowerlimit="-170" upperlimit="0"/>
<joint limb1="7" limb1anchor="0,-17" limb2="8" limb2anchor="5,9" lowerlimit="70" upperlimit="135"/>
<joint limb1="12" limb1anchor="0,-1" limb2="6" limb2anchor="0,14" lowerlimit="-30" upperlimit="140"/>
<joint limb1="6" limb1anchor="0,-15" limb2="7" limb2anchor="0,20" lowerlimit="-170" upperlimit="0"/>
<joint limb1="7" limb1anchor="-3,-21" limb2="8" limb2anchor="5,7" lowerlimit="10" upperlimit="135"/>
<!-- body to right leg -->
<joint limb1="12" limb1anchor="0,-10" limb2="9" limb2anchor="0,14" lowerlimit="-30" upperlimit="140"/>
<joint limb1="9" limb1anchor="0,-15" limb2="10" limb2anchor="0,14" lowerlimit="-170" upperlimit="0"/>
<joint limb1="10" limb1anchor="0,-17" limb2="11" limb2anchor="5,9" lowerlimit="70" upperlimit="135"/>
<joint limb1="12" limb1anchor="0,-1" limb2="9" limb2anchor="0,14" lowerlimit="-30" upperlimit="140"/>
<joint limb1="9" limb1anchor="0,-15" limb2="10" limb2anchor="0,20" lowerlimit="-170" upperlimit="0"/>
<joint limb1="10" limb1anchor="-3,-21" limb2="11" limb2anchor="5,7" lowerlimit="10" upperlimit="135"/>
</ragdoll>
</character>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.
@@ -31,7 +31,9 @@
<Body width="16" height="16"/>
<Holdable aimpos="35,-10" handle1="0,0" attachable="true" aimable="true"/>
<Holdable aimpos="35,-10" handle1="0,0" attachable="true" aimable="true">
<requireditem name="Wrench" type="Equipped"/>
</Holdable>
<Pickable slots="Any,RightHand,LeftHand" msg="Detach [Wrench]">
<requireditem name="Wrench" type="Equipped"/>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

+17 -2
View File
@@ -213,6 +213,12 @@ namespace Subsurface
Game1.Level = new Level("asdf", 50.0f, 500,500, 50);
Game1.Level.Generate(100.0f);
break;
case "fixitems":
foreach (Item it in Item.itemList)
{
it.Condition = 100.0f;
}
break;
case "fowenabled":
case "fow":
case "drawfow":
@@ -221,8 +227,16 @@ namespace Subsurface
case "lighting":
case "lightingenabled":
case "light":
case "lights":
Game1.LightManager.LightingEnabled = !Game1.LightManager.LightingEnabled;
break;
case "oxygen":
case "air":
foreach (Hull hull in Hull.hullList)
{
hull.OxygenPercentage = 100.0f;
}
break;
case "lobbyscreen":
case "lobby":
Game1.LobbyScreen.Select();
@@ -266,8 +280,9 @@ namespace Subsurface
}
public static void ThrowError(string error, Exception e = null)
{
if (e!=null) error += " {"+e.Message+"}";
{
if (e != null) error += " {" + e.Message + "}";
System.Diagnostics.Debug.WriteLine(error);
NewMessage(error, Color.Red);
isOpen = true;
}
+1 -1
View File
@@ -123,7 +123,7 @@ namespace Subsurface.Items.Components
{
foreach (Item contained in inventory.items)
{
if (contained == null) continue;
if (contained == null || contained.Condition<=0.0f) continue;
if (contained.body!=null) contained.body.Enabled = false;
@@ -162,7 +162,7 @@ namespace Subsurface.Items.Components
// return false;
//}
if (attached) return false;
//if (attached) return false;
item.body = body;
item.body.Enabled = true;
@@ -172,12 +172,14 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (!attachable || item.body==null) return false;
if (!attachable || item.body==null) return true;
item.Drop();
item.body.Enabled = false;
item.body = null;
attached = true;
return true;
}
+4 -4
View File
@@ -396,18 +396,18 @@ namespace Subsurface
public bool HasRequiredContainedItems(bool addMessage)
{
if (!requiredItems.Any()) return true;
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
if (!requiredContained.Any()) return true;
Item[] containedItems = item.ContainedItems;
if (containedItems == null || !containedItems.Any()) return false;
foreach (RelatedItem ri in requiredItems)
foreach (RelatedItem ri in requiredContained)
{
if (ri.Type != RelatedItem.RelationType.Contained) continue;
Item containedItem = Array.Find(containedItems, x => x != null && x.Condition > 0.0f && ri.MatchesItem(x));
if (containedItem == null)
{
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
if (addMessage && !string.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
+30 -22
View File
@@ -54,7 +54,7 @@ namespace Subsurface.Items.Components
pingState = (pingState + deltaTime * 0.5f);
if (pingState>1.0f)
{
item.Use(deltaTime,null);
item.Use(deltaTime, null);
pingState = 0.0f;
}
@@ -63,7 +63,7 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
return true;
return (pingState > 1.0f);
}
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
@@ -87,7 +87,7 @@ namespace Subsurface.Items.Components
//lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Math.Min(width, height) / 2.0f;
//GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green);
if (!isActive || Level.Loaded == null) return;
if (!isActive) return;
if (pingCircle!=null)
{
@@ -97,35 +97,43 @@ namespace Subsurface.Items.Components
float scale = 0.015f;
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 7);
Vector2 offset = Vector2.Zero;
for (int i = 0; i < edges.Count; i++)
if (Level.Loaded != null)
{
GUI.DrawLine(spriteBatch,
center + (edges[i][0] - offset) * scale,
center + (edges[i][1] - offset) * scale, Color.White);
}
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 7);
Vector2 offset = Vector2.Zero;
scale = ConvertUnits.ToDisplayUnits(scale);
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start = Submarine.Loaded.HullVertices[i] * scale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale;
end.Y = -end.Y;
for (int i = 0; i < edges.Count; i++)
{
GUI.DrawLine(spriteBatch,
center + (edges[i][0] - offset) * scale,
center + (edges[i][1] - offset) * scale, Color.White);
}
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White);
scale = ConvertUnits.ToDisplayUnits(scale);
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start = Submarine.Loaded.HullVertices[i] * scale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale;
end.Y = -end.Y;
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White);
}
}
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.CurrentHull != null) continue;
if (c.SimPosition!=Vector2.Zero && c.SimPosition.Length() < 7*Level.GridCellWidth)
if (c.SimPosition != Vector2.Zero && c.SimPosition.Length() < 7 * Level.GridCellWidth)
{
int width = (int)c.Mass/5;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)c.Position.X - width / 2, (int)c.Position.Y - width / 2, width, width), Color.White);
int width = (int)Math.Min(c.Mass / 5, 30);
Vector2 pos = c.Position * scale;
pos.Y = -pos.Y;
pos += center;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - width / 2, (int)pos.Y - width / 2, width, width), Color.White, true);
}
}
@@ -112,7 +112,7 @@ namespace Subsurface.Items.Components
fissionRate = Math.Min(fissionRate, AvailableFuel);
float heat = 100 * fissionRate;
float heat = 100 * fissionRate * (AvailableFuel/2000.0f);
float heatDissipation = 50 * coolingRate + ExtraCooling;
float deltaTemp = (((heat - heatDissipation) * 5) - temperature) / 1000.0f;
@@ -125,14 +125,14 @@ namespace Subsurface.Items.Components
}
else if (temperature==0.0f)
{
if (powerUpTask==null || powerUpTask.IsFinished)
if (powerUpTask == null || powerUpTask.IsFinished)
{
powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Power up the reactor");
}
}
}
item.Condition -= temperature*deltaTime*0.00005f;
item.Condition -= temperature * deltaTime * 0.00005f;
if (temperature > shutDownTemp)
{
@@ -360,13 +360,13 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.White);
Vector2 prevPoint = new Vector2(x, y + height - (graph[1] + (graph[0] - graph[1]) * xOffset) * yScale);
Vector2 prevPoint = new Vector2(x + width, y + height - (graph[1] + (graph[0] - graph[1]) * xOffset) * yScale);
float currX = x + ((xOffset - 1.0f) * lineWidth);
float currX = x + width - ((xOffset - 1.0f) * lineWidth);
for (int i = 1; i < graph.Count - 1; i++)
{
currX += lineWidth;
currX -= lineWidth;
Vector2 newPoint = new Vector2(currX, y + height - graph[i] * yScale);
@@ -375,7 +375,7 @@ namespace Subsurface.Items.Components
prevPoint = newPoint;
}
Vector2 lastPoint = new Vector2(x + width,
Vector2 lastPoint = new Vector2(x,
y + height - (graph[graph.Count - 1] + (graph[graph.Count - 2] - graph[graph.Count - 1]) * xOffset) * yScale);
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.Red);
@@ -138,7 +138,7 @@ namespace Subsurface.Items.Components
return;
}
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, maxRechargeSpeed*rechargeSpeed, 0.05f);
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, rechargeSpeed, 0.05f);
charge += currPowerConsumption*voltage / 3600.0f;
}
//provide power to the grid
@@ -3,12 +3,15 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Lights;
using System;
using System.IO;
using System.Xml.Linq;
namespace Subsurface.Items.Components
{
class LightComponent : Powered
{
static Sound[] sparkSounds;
private Color lightColor;
//private Sprite sprite;
@@ -19,7 +22,7 @@ namespace Subsurface.Items.Components
float lightBrightness;
[HasDefaultValue(100.0f, true)]
[Editable, HasDefaultValue(100.0f, true)]
public float Range
{
get { return range; }
@@ -47,6 +50,16 @@ namespace Subsurface.Items.Components
public LightComponent(Item item, XElement element)
: base (item, element)
{
if (sparkSounds==null)
{
sparkSounds = new Sound[4];
string dir = Path.GetDirectoryName(item.Prefab.ConfigFile)+"\\";
for (int i = 0; i<4; i++)
{
sparkSounds[i] = Sound.Load(dir+"zap"+(i+1)+".ogg");
}
}
//foreach (XElement subElement in element.Elements())
//{
// if (subElement.Name.ToString().ToLower() != "sprite") continue;
@@ -79,8 +92,9 @@ namespace Subsurface.Items.Components
currPowerConsumption = powerConsumption;
}
if (voltage < Rand.Range(0.0f, minVoltage))
if (Rand.Range(0.0f, 1.0f)<0.05f && voltage < Rand.Range(0.0f, minVoltage))
{
if (voltage>0.1f) sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 400.0f, item.Position);
lightBrightness = 0.0f;
}
else
+79 -9
View File
@@ -8,7 +8,8 @@ namespace Subsurface.Lights
class ConvexHull
{
public static List<ConvexHull> list = new List<ConvexHull>();
static BasicEffect drawingEffect;
static BasicEffect fowEffect;
static BasicEffect shadowEffect;
private VertexPositionColor[] vertices;
private short[] indices;
@@ -86,14 +87,22 @@ namespace Subsurface.Lights
// }
//}
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos)
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, bool fow = true)
{
if (!Enabled) return;
if (drawingEffect == null)
if (fowEffect == null)
{
drawingEffect = new BasicEffect(graphicsDevice);
drawingEffect.VertexColorEnabled = true;
fowEffect = new BasicEffect(graphicsDevice);
fowEffect.VertexColorEnabled = true;
}
if (shadowEffect==null)
{
shadowEffect = new BasicEffect(graphicsDevice);
shadowEffect.TextureEnabled = true;
//shadowEffect.VertexColorEnabled = true;
shadowEffect.LightingEnabled = false;
shadowEffect.Texture = Game1.TextureLoader.FromFile("Content/lights/penumbra.png");
}
//compute facing of each edge, using N*L
@@ -129,6 +138,59 @@ namespace Subsurface.Lights
startingIndex = nextEdge;
}
VertexPositionTexture[] penumbraVertices = new VertexPositionTexture[6];
if (fow)
{
for (int n = 0; n < 4; n+=3)
{
Vector3 penumbraStart = (n == 0) ? vertices[startingIndex].Position : vertices[endingIndex].Position;
penumbraVertices[n] = new VertexPositionTexture();
penumbraVertices[n].Position = penumbraStart;
penumbraVertices[n].TextureCoordinate = new Vector2(0.0f, 1.0f);
//penumbraVertices[0].te = fow ? Color.Black : Color.Transparent;
for (int i = 0; i < 2; i++ )
{
penumbraVertices[n + i + 1] = new VertexPositionTexture();
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
vertexDir.Normalize();
Vector3 normal = (i == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f)*0.05f;
if (n > 0) normal = -normal;
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
vertexDir.Normalize();
penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000;
if (i==0)
{
//penumbraVertices[n].Position -= normal*2.0f;
}
if (fow)
{
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
}
else
{
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f):Vector2.Zero;
}
//penumbraVertices[i+1].Color = Color.Black;
}
if (n>0)
{
var temp = penumbraVertices[4];
penumbraVertices[4] = penumbraVertices[5];
penumbraVertices[5] = temp;
}
}
}
int shadowVertexCount;
//nr of vertices that are in the shadow
@@ -148,12 +210,12 @@ namespace Subsurface.Lights
//one vertex on the hull
shadowVertices[svCount] = new VertexPositionColor();
shadowVertices[svCount].Color = Color.Black;
shadowVertices[svCount].Color = fow ? Color.Black : Color.Transparent;
shadowVertices[svCount].Position = vertexPos;
//one extruded by the light direction
shadowVertices[svCount + 1] = new VertexPositionColor();
shadowVertices[svCount + 1].Color = Color.Black;
shadowVertices[svCount + 1].Color = fow ? Color.Black : Color.Transparent;
Vector3 L2P = vertexPos - new Vector3(lightSourcePos, 0);
L2P.Normalize();
shadowVertices[svCount + 1].Position = new Vector3(lightSourcePos, 0) + L2P * 9000;
@@ -162,12 +224,20 @@ namespace Subsurface.Lights
currentIndex = (currentIndex + 1) % primitiveCount;
}
drawingEffect.World = cam.ShaderTransform
fowEffect.World = cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
drawingEffect.CurrentTechnique.Passes[0].Apply();
fowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
if (fow)
{
shadowEffect.World = cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
shadowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, penumbraVertices, 0, 2, VertexPositionTexture.VertexDeclaration);
}
}
public void Remove()
+15 -7
View File
@@ -67,24 +67,32 @@ namespace Subsurface.Lights
{
graphics.SetRenderTarget(lightMap);
Rectangle viewRect = cam.WorldView;
viewRect.Y -= cam.WorldView.Height;
//clear to some small ambient light
graphics.Clear(AmbientLight);
foreach (LightSource light in lights)
{
if (light.Color.A < 0.01f || light.Range < 0.01f) continue;
if (!MathUtils.CircleIntersectsRectangle(light.Position, light.Range, viewRect)) continue;
//clear alpha to 1
ClearAlphaToOne(graphics, spriteBatch);
//draw all shadows
//write only to the alpha channel, which sets alpha to 0
//graphics.RasterizerState = RasterizerState.CullNone;
//graphics.BlendState = CustomBlendStates.WriteToAlpha;
graphics.RasterizerState = RasterizerState.CullNone;
graphics.BlendState = CustomBlendStates.WriteToAlpha;
//foreach (ConvexHull ch in ConvexHull.list)
//{
// //draw shadow
// ch.DrawShadows(graphics, cam, light.Position);
//}
foreach (ConvexHull ch in ConvexHull.list)
{
//draw shadow
ch.DrawShadows(graphics, cam, light.Position, false);
}
//draw the light shape
//where Alpha is 0, nothing will be written
+16 -19
View File
@@ -148,21 +148,17 @@ namespace Subsurface
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
Game1.LightManager.DrawLightmap(graphics, spriteBatch, cam);
sw.Stop();
System.Diagnostics.Debug.WriteLine(sw.ElapsedMilliseconds+" - "+sw.ElapsedTicks);
//----------------------------------------------------------------------------------------
//1. draw the characters and the parts of the map that are behind them
//1. draw the background, characters and the parts of the submarine that are behind them
//----------------------------------------------------------------------------------------
//cam.UpdateTransform();
//----------------------------------------------------------------------------------------
//draw the map and characters to a rendertarget
graphics.SetRenderTarget(renderTarget);
graphics.Clear(new Color(11, 18, 26, 255));
@@ -263,10 +259,18 @@ namespace Subsurface
Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform);
if (Game1.LightManager.LightingEnabled)
{
//multiply scene with lightmap
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative);
spriteBatch.Draw(Game1.LightManager.LightMap, Vector2.Zero, Color.White);
spriteBatch.End();
}
//----------------------------------------------------------------------------------------
//3. draw the sections of the map that are on top of the water
//----------------------------------------------------------------------------------------
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend, SamplerState.LinearWrap,
null, null, null,
@@ -287,18 +291,11 @@ namespace Subsurface
Game1.GameSession.Level.Render(graphics, cam);
Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
}
if (Game1.Level != null) Game1.Level.Render(graphics, cam);
if (Game1.LightManager.LightingEnabled)
else if (Game1.Level != null)
{
//multiply scene with lightmap
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative);
spriteBatch.Draw(Game1.LightManager.LightMap, Vector2.Zero, Color.White);
spriteBatch.End();
Game1.Level.Render(graphics, cam);
}
Game1.LightManager.DrawFow(graphics,cam,LightManager.ViewPos);
}
+24 -1
View File
@@ -243,6 +243,12 @@
<Content Include="Content\Characters\Human\fhead2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\fhead3.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\fhead4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\firstnames.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -394,6 +400,9 @@
<Content Include="Content\Lights\light.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Lights\penumbra.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Map\iceCrack.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -675,6 +684,21 @@
<None Include="Content\effects.mgfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Electricity\powerOn.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Electricity\zap1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Electricity\zap2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Electricity\zap3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Electricity\zap4.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Engine\radarPing.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -693,7 +717,6 @@
<None Include="Content\Items\Weapons\stunGrenade.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Lights\AlphaOne.dds" />
<None Include="Content\SmallFont.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+20
View File
@@ -152,6 +152,26 @@ namespace Subsurface
return (r >= 0 && r <= 1) && (s >= 0 && s <= 1);
}
public static bool CircleIntersectsRectangle(Vector2 circlePos, float radius, Rectangle rect)
{
Vector2 circleDistance = new Vector2(Math.Abs(circlePos.X - rect.Center.X), Math.Abs(circlePos.Y -rect.Center.Y));
if (circleDistance.X > (rect.Width / 2 + radius)) { return false; }
if (circleDistance.Y > (rect.Height / 2 + radius)) { return false; }
if (circleDistance.X <= (rect.Width / 2)) { return true; }
if (circleDistance.Y <= (rect.Height / 2)) { return true; }
float distSqX = circleDistance.X - rect.Width / 2;
float distSqY = circleDistance.Y - rect.Height / 2;
float cornerDistanceSq = distSqX * distSqX + distSqY * distSqY;
return (cornerDistanceSq <= (radius * radius));
}
/// <summary>
/// divide a convex hull into triangles
/// </summary>
Binary file not shown.