Stair body + linkedsub flipping
This commit is contained in:
@@ -70,7 +70,8 @@ namespace Barotrauma
|
||||
|
||||
public Direction StairDirection
|
||||
{
|
||||
get { return prefab.StairDirection; }
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public override string Name
|
||||
@@ -176,6 +177,8 @@ namespace Barotrauma
|
||||
prefab = sp;
|
||||
|
||||
isHorizontal = (rect.Width>rect.Height);
|
||||
|
||||
StairDirection = prefab.StairDirection;
|
||||
|
||||
if (prefab.HasBody)
|
||||
{
|
||||
@@ -207,29 +210,9 @@ namespace Barotrauma
|
||||
sections = new WallSection[1];
|
||||
sections[0] = new WallSection(rect);
|
||||
|
||||
if (StairDirection!=Direction.None)
|
||||
if (StairDirection != Direction.None)
|
||||
{
|
||||
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);
|
||||
CreateStairBodies();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +225,31 @@ namespace Barotrauma
|
||||
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()
|
||||
{
|
||||
int xsections = 1, ysections = 1;
|
||||
@@ -736,6 +744,20 @@ namespace Barotrauma
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -285,8 +285,6 @@ namespace Barotrauma
|
||||
|
||||
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++ )
|
||||
{
|
||||
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
|
||||
@@ -500,9 +498,7 @@ namespace Barotrauma
|
||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||
{
|
||||
if (e.MoveWithLevel || e.Submarine != this || e is Item) continue;
|
||||
|
||||
e.FlipX();
|
||||
|
||||
|
||||
if (e is LinkedSubmarine)
|
||||
{
|
||||
Submarine sub = ((LinkedSubmarine)e).Sub;
|
||||
@@ -514,6 +510,10 @@ namespace Barotrauma
|
||||
sub.FlipX(parents);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.FlipX();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
|
||||
@@ -562,8 +562,7 @@ namespace Barotrauma
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
|
||||
if (PlayerInput.KeyHit(InputType.Crouch)) FlipX();
|
||||
if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
|
||||
|
||||
if (Level.Loaded == null) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user