Flipping sprites of staircases & engine

This commit is contained in:
juanjp600
2016-10-01 16:41:16 -03:00
parent d7047c0df8
commit bdcd894b83
8 changed files with 81 additions and 39 deletions

View File

@@ -8,7 +8,7 @@
pickthroughwalls="true"
pickdistance="150">
<Sprite texture ="engine.png" depth="0.8" sourcerect="0,0,373,113"/>
<Sprite texture ="engine.png" depth="0.8" sourcerect="0,0,373,113" canflipx="true"/>
<fixrequirement name="Mechanical repairs">
<skill name="Construction" level="40"/>
@@ -36,7 +36,7 @@
pickthroughwalls="true"
pickdistance="150">
<Sprite texture ="engine.png" depth="0.8" sourcerect="0,115,224,73"/>
<Sprite texture ="engine.png" depth="0.8" sourcerect="0,115,224,73" canflipx="true"/>
<fixrequirement name="Mechanical repairs">
<skill name="Construction" level="30"/>

View File

@@ -49,19 +49,19 @@
</medicalLabel>
<arrowUp width="16" height="16">
<sprite texture="Content/Map/structures2.png" sourcerect="129,460,16,16" depth ="0.99"/>
<sprite texture="Content/Map/structures2.png" sourcerect="129,460,16,16" depth ="0.99" canflipx="true"/>
</arrowUp>
<arrowDown width="16" height="16">
<sprite texture="Content/Map/structures2.png" sourcerect="146,460,16,16" depth ="0.99"/>
<sprite texture="Content/Map/structures2.png" sourcerect="146,460,16,16" depth ="0.99" canflipx="true"/>
</arrowDown>
<arrowLeft width="16" height="16">
<sprite texture="Content/Map/structures2.png" sourcerect="129,477,16,16" depth ="0.99"/>
<sprite texture="Content/Map/structures2.png" sourcerect="129,477,16,16" depth ="0.99" canflipx="true"/>
</arrowLeft>
<arrowRight width="16" height="16">
<sprite texture="Content/Map/structures2.png" sourcerect="146,477,16,16" depth ="0.99"/>
<sprite texture="Content/Map/structures2.png" sourcerect="146,477,16,16" depth ="0.99" canflipx="true"/>
</arrowRight>
<leftwall description="A vertical wall with collision detection"
@@ -170,19 +170,19 @@
</PipesBackground>
<SlopeForward width="16" height="16" resizehorizontal="true" resizevertical="true">
<sprite texture="Content/Map/structures2.png" sourcerect="0,0,224,64" depth = "0.95" />
<sprite texture="Content/Map/structures2.png" sourcerect="0,0,224,64" depth = "0.95" canflipx="true"/>
</SlopeForward>
<SlopeBack width="16" height="16" resizehorizontal="true" resizevertical="true">
<sprite texture="Content/Map/structures2.png" sourcerect="0,64,224,64" depth = "0.95" />
<sprite texture="Content/Map/structures2.png" sourcerect="0,64,224,64" depth = "0.95" canflipx="true"/>
</SlopeBack>
<stairsright width="256" height="320" stairdirection="Right">
<sprite texture="Content/Map/structures2.png" sourcerect="256,193,256,319" depth = "0.1" />
<sprite texture="Content/Map/structures2.png" sourcerect="256,193,256,319" depth = "0.1" canflipx="true"/>
</stairsright>
<stairsleft width="256" height="320" stairdirection="Left">
<sprite texture="Content/Map/structures2.png" sourcerect="256,193,256,319" fliphorizontal="true" depth = "0.1" />
<sprite texture="Content/Map/structures2.png" sourcerect="256,193,256,319" fliphorizontal="true" depth = "0.1" canflipx="true"/>
</stairsleft>
<bunk width="173" height="129">

View File

@@ -67,7 +67,7 @@ namespace Barotrauma
TeamASub = Submarine.MainSubs[0];
TeamBSub = Submarine.MainSubs[1];
TeamBSub.SetPosition(Level.Loaded.EndPosition - new Vector2(0.0f, 2000.0f));
//TeamASub.FlipX();
TeamBSub.FlipX();
foreach (Submarine submarine in Submarine.Loaded)
{

View File

@@ -40,6 +40,8 @@ namespace Barotrauma
public Hull CurrentHull;
public SpriteEffects SpriteEffects = SpriteEffects.None;
//components that determine the functionality of the item
public List<ItemComponent> components;
public List<IDrawableComponent> drawableComponents;
@@ -798,16 +800,21 @@ namespace Barotrauma
}
return true;
}
public override void FlipX()
{
base.FlipX();
foreach (ItemComponent component in components)
}
public override void FlipX()
{
base.FlipX();
if (prefab.CanSpriteFlipX)
{
component.FlipX();
}
SpriteEffects ^= SpriteEffects.FlipHorizontally;
}
foreach (ItemComponent component in components)
{
component.FlipX();
}
}
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
@@ -815,6 +822,9 @@ namespace Barotrauma
Color color = (isSelected && editing) ? color = Color.Red : spriteColor;
if (isHighlighted) color = Color.Orange;
SpriteEffects oldEffects = prefab.sprite.effects;
prefab.sprite.effects ^= SpriteEffects;
if (prefab.sprite != null)
{
float depth = Sprite.Depth;
@@ -822,7 +832,7 @@ namespace Barotrauma
if (body == null)
{
if (prefab.ResizeHorizontal || prefab.ResizeVertical)
if (prefab.ResizeHorizontal || prefab.ResizeVertical || SpriteEffects.HasFlag(SpriteEffects.FlipHorizontally) || SpriteEffects.HasFlag(SpriteEffects.FlipVertically))
{
prefab.sprite.DrawTiled(spriteBatch, new Vector2(DrawPosition.X-rect.Width/2, -(DrawPosition.Y+rect.Height/2)), new Vector2(rect.Width, rect.Height), color);
}
@@ -855,6 +865,8 @@ namespace Barotrauma
}
}
prefab.sprite.effects = oldEffects;
for (int i = 0; i < drawableComponents.Count; i++ )
{
drawableComponents[i].Draw(spriteBatch, editing);
@@ -1733,32 +1745,32 @@ namespace Barotrauma
Condition = (float)message.ReadByte()/2.55f;
Client sender = null;
if (GameMain.Server != null)
{
sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender == null || sender.Character == null || !sender.Character.CanAccessItem(this))
{
return false;
}
}
if (GameMain.Server != null)
{
sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender == null || sender.Character == null || !sender.Character.CanAccessItem(this))
{
return false;
}
}
switch (type)
{
case NetworkEventType.DropItem:
if (GameMain.Server != null)
{
Drop(sender.Character, false);
if (body != null)
{
body.TargetPosition = sender.Character.SimPosition;
body.MoveToTargetPosition();
if (body != null)
{
body.TargetPosition = sender.Character.SimPosition;
body.MoveToTargetPosition();
}
}
else
else
{
//client should not tell the server where the item should drop
Drop(null, false);
if (body != null)
if (body != null)
{
body.ReadNetworkData(message, sendingTime);
body.MoveToTargetPosition();

View File

@@ -58,6 +58,8 @@ namespace Barotrauma
private set;
}
private bool canSpriteFlipX;
//if a matching itemprefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias
//(allows changing item names while keeping backwards compatibility with older sub files)
public string[] Aliases
@@ -116,6 +118,11 @@ namespace Barotrauma
private set;
}
public bool CanSpriteFlipX
{
get { return canSpriteFlipX; }
}
public Vector2 Size
{
get { return size; }
@@ -281,6 +288,9 @@ namespace Barotrauma
spriteFolder = Path.GetDirectoryName(filePath);
}
if (ToolBox.GetAttributeBool(subElement, "canflipx", false))
canSpriteFlipX = true;
sprite = new Sprite(subElement, spriteFolder);
size = sprite.size;
break;

View File

@@ -57,7 +57,9 @@ namespace Barotrauma
bool isHorizontal;
public float lastUpdate;
public SpriteEffects SpriteEffects = SpriteEffects.None;
public override Sprite Sprite
{
get { return prefab.sprite; }
@@ -438,7 +440,10 @@ namespace Barotrauma
Vector2.Zero, color, Point.Zero);
}
}
SpriteEffects oldEffects = prefab.sprite.effects;
prefab.sprite.effects ^= SpriteEffects;
if (back == prefab.sprite.Depth > 0.5f || editing)
{
foreach (WallSection s in sections)
@@ -462,6 +467,8 @@ namespace Barotrauma
prefab.sprite.DrawTiled(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset);
}
}
prefab.sprite.effects = oldEffects;
}
private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact)
@@ -747,6 +754,11 @@ namespace Barotrauma
public override void FlipX()
{
base.FlipX();
if (prefab.CanSpriteFlipX)
{
SpriteEffects ^= SpriteEffects.FlipHorizontally;
}
if (StairDirection != Direction.None)
{

View File

@@ -17,6 +17,7 @@ namespace Barotrauma
private bool isPlatform;
private Direction stairDirection;
private bool canSpriteFlipX;
private float maxHealth;
@@ -48,6 +49,11 @@ namespace Barotrauma
get { return stairDirection; }
}
public bool CanSpriteFlipX
{
get { return canSpriteFlipX; }
}
public Vector2 Size
{
get { return size; }
@@ -107,6 +113,8 @@ namespace Barotrauma
sp.sprite.effects = SpriteEffects.FlipHorizontally;
if (ToolBox.GetAttributeBool(subElement, "flipvertical", false))
sp.sprite.effects = SpriteEffects.FlipVertically;
if (ToolBox.GetAttributeBool(subElement, "canflipx", false))
sp.canSpriteFlipX = true;
break;
case "backgroundsprite":

View File

@@ -562,7 +562,7 @@ namespace Barotrauma
public void Update(float deltaTime)
{
if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
//if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
if (Level.Loaded == null) return;