Stair body + linkedsub flipping

This commit is contained in:
Regalis
2016-09-30 20:07:36 +03:00
parent 8e8a0e57f0
commit 0fe822c96a
2 changed files with 51 additions and 30 deletions
+45 -23
View File
@@ -70,7 +70,8 @@ namespace Barotrauma
public Direction StairDirection public Direction StairDirection
{ {
get { return prefab.StairDirection; } get;
private set;
} }
public override string Name public override string Name
@@ -177,6 +178,8 @@ namespace Barotrauma
isHorizontal = (rect.Width>rect.Height); isHorizontal = (rect.Width>rect.Height);
StairDirection = prefab.StairDirection;
if (prefab.HasBody) if (prefab.HasBody)
{ {
bodies = new List<Body>(); bodies = new List<Body>();
@@ -207,29 +210,9 @@ namespace Barotrauma
sections = new WallSection[1]; sections = new WallSection[1];
sections[0] = new WallSection(rect); sections[0] = new WallSection(rect);
if (StairDirection!=Direction.None) if (StairDirection != Direction.None)
{ {
bodies = new List<Body>(); CreateStairBodies();
Body newBody = BodyFactory.CreateRectangle(GameMain.World,
ConvertUnits.ToSimUnits(rect.Width * Math.Sqrt(2.0) + Submarine.GridSize.X*3.0f),
ConvertUnits.ToSimUnits(10),
1.5f);
newBody.BodyType = BodyType.Static;
Vector2 stairPos = new Vector2(Position.X, rect.Y - rect.Height + rect.Width / 2.0f);
stairPos += new Vector2(
(StairDirection == Direction.Right) ? -Submarine.GridSize.X*1.5f : Submarine.GridSize.X*1.5f,
- Submarine.GridSize.Y*2.0f);
newBody.Position = ConvertUnits.ToSimUnits(stairPos);
newBody.Rotation = (StairDirection == Direction.Right) ? MathHelper.PiOver4 : -MathHelper.PiOver4;
newBody.Friction = 0.8f;
newBody.CollisionCategories = Physics.CollisionStairs;
newBody.UserData = this;
bodies.Add(newBody);
} }
} }
@@ -242,6 +225,31 @@ namespace Barotrauma
InsertToList(); InsertToList();
} }
private void CreateStairBodies()
{
bodies = new List<Body>();
Body newBody = BodyFactory.CreateRectangle(GameMain.World,
ConvertUnits.ToSimUnits(rect.Width * Math.Sqrt(2.0) + Submarine.GridSize.X * 3.0f),
ConvertUnits.ToSimUnits(10),
1.5f);
newBody.BodyType = BodyType.Static;
Vector2 stairPos = new Vector2(Position.X, rect.Y - rect.Height + rect.Width / 2.0f);
stairPos += new Vector2(
(StairDirection == Direction.Right) ? -Submarine.GridSize.X * 1.5f : Submarine.GridSize.X * 1.5f,
-Submarine.GridSize.Y * 2.0f);
newBody.Position = ConvertUnits.ToSimUnits(stairPos);
newBody.Rotation = (StairDirection == Direction.Right) ? MathHelper.PiOver4 : -MathHelper.PiOver4;
newBody.Friction = 0.8f;
newBody.CollisionCategories = Physics.CollisionStairs;
newBody.UserData = this;
bodies.Add(newBody);
}
private void CreateSections() private void CreateSections()
{ {
int xsections = 1, ysections = 1; int xsections = 1, ysections = 1;
@@ -736,6 +744,20 @@ namespace Barotrauma
return newBody; return newBody;
} }
public override void FlipX()
{
base.FlipX();
if (StairDirection != Direction.None)
{
StairDirection = StairDirection == Direction.Left ? Direction.Right : Direction.Left;
bodies.ForEach(b => GameMain.World.RemoveBody(b));
CreateStairBodies();
}
//todo: flip sprites & wall sections
}
public override XElement Save(XElement parentElement) public override XElement Save(XElement parentElement)
{ {
+5 -6
View File
@@ -285,8 +285,6 @@ namespace Barotrauma
public static void Draw(SpriteBatch spriteBatch, bool editing = false) public static void Draw(SpriteBatch spriteBatch, bool editing = false)
{ {
if (PlayerInput.KeyHit(InputType.Crouch)) Submarine.MainSub.FlipX();
for (int i = 0; i < MapEntity.mapEntityList.Count; i++ ) for (int i = 0; i < MapEntity.mapEntityList.Count; i++ )
{ {
MapEntity.mapEntityList[i].Draw(spriteBatch, editing); MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
@@ -501,8 +499,6 @@ namespace Barotrauma
{ {
if (e.MoveWithLevel || e.Submarine != this || e is Item) continue; if (e.MoveWithLevel || e.Submarine != this || e is Item) continue;
e.FlipX();
if (e is LinkedSubmarine) if (e is LinkedSubmarine)
{ {
Submarine sub = ((LinkedSubmarine)e).Sub; Submarine sub = ((LinkedSubmarine)e).Sub;
@@ -514,6 +510,10 @@ namespace Barotrauma
sub.FlipX(parents); sub.FlipX(parents);
} }
} }
else
{
e.FlipX();
}
} }
for (int i = 0; i < MapEntity.mapEntityList.Count; i++) for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
@@ -562,8 +562,7 @@ namespace Barotrauma
public void Update(float deltaTime) public void Update(float deltaTime)
{ {
if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
if (PlayerInput.KeyHit(InputType.Crouch)) FlipX();
if (Level.Loaded == null) return; if (Level.Loaded == null) return;