This commit is contained in:
Regalis
2015-12-04 01:37:30 +02:00
parent c064c5eb50
commit 242af12f14
25 changed files with 200 additions and 109 deletions
+24 -1
View File
@@ -45,14 +45,37 @@ namespace Barotrauma
{
get { return Vector2.Zero; }
}
public virtual Vector2 Position
{
get { return Vector2.Zero; }
}
public Vector2 WorldPosition
{
get { return Submarine == null ? Position : Submarine.Position + Position; }
}
public Vector2 DrawPosition
{
get { return Submarine == null ? Position : Submarine.DrawPosition + Position; }
}
public Submarine Submarine
{
get;
protected set;
}
public AITarget AiTarget
{
get { return aiTarget; }
}
public Entity()
public Entity(Submarine submarine)
{
this.Submarine = submarine;
//give an unique ID
bool IDfound;
id = 1;//Rand.Int(int.MaxValue);
+7 -7
View File
@@ -57,12 +57,12 @@ namespace Barotrauma
get { return flowTargetHull; }
}
public Gap(Rectangle newRect)
: this(newRect, (newRect.Width < newRect.Height))
{
}
public Gap(Rectangle newRect, Submarine submarine)
: this(newRect, newRect.Width < newRect.Height, submarine)
{ }
public Gap(Rectangle newRect, bool isHorizontal)
public Gap(Rectangle newRect, bool isHorizontal, Submarine submarine)
: base (submarine)
{
rect = newRect;
linkedTo = new ObservableCollection<MapEntity>();
@@ -564,7 +564,7 @@ namespace Barotrauma
}
public static void Load(XElement element)
public static void Load(XElement element, Submarine submarine)
{
Rectangle rect = new Rectangle(
int.Parse(element.Attribute("x").Value),
@@ -572,7 +572,7 @@ namespace Barotrauma
int.Parse(element.Attribute("width").Value),
int.Parse(element.Attribute("height").Value));
Gap g = new Gap(rect);
Gap g = new Gap(rect, submarine);
g.ID = (ushort)int.Parse(element.Attribute("ID").Value);
g.linkedToID = new List<ushort>();
+17 -14
View File
@@ -133,7 +133,8 @@ namespace Barotrauma
get { return fireSources; }
}
public Hull(Rectangle rectangle)
public Hull(Rectangle rectangle, Submarine submarine)
: base (submarine)
{
rect = rectangle;
@@ -376,12 +377,13 @@ namespace Barotrauma
if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return;
//calculate where the surface should be based on the water volume
float top = rect.Y;
float bottom = rect.Y - rect.Height;
float top = rect.Y+Submarine.Position.Y;
float bottom = top - rect.Height;
float surfaceY = bottom + Volume / rect.Width;
//interpolate the position of the rendered surface towards the "target surface"
surface = surface + (surfaceY - surface) / 10.0f;
surface = surface + ((surfaceY - Submarine.Position.Y) - surface) / 10.0f;
float drawSurface = surface + Submarine.Position.Y;
Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
@@ -393,15 +395,16 @@ namespace Barotrauma
Vector3[] corners = new Vector3[4];
corners[0] = new Vector3(rect.X, top, 0.0f);
corners[1] = new Vector3(rect.X + rect.Width, top, 0.0f);
corners[0] = new Vector3(rect.X, rect.Y, 0.0f);
corners[1] = new Vector3(rect.X + rect.Width, rect.Y, 0.0f);
corners[2] = new Vector3(corners[1].X, bottom, 0.0f);
corners[3] = new Vector3(corners[0].X, bottom, 0.0f);
corners[2] = new Vector3(corners[1].X, rect.Y-rect.Height, 0.0f);
corners[3] = new Vector3(corners[0].X, corners[2].Y, 0.0f);
Vector2[] uvCoords = new Vector2[4];
for (int i = 0; i < 4; i++ )
{
corners[i] += new Vector3(Submarine.Loaded.Position, 0.0f);
uvCoords[i] = Vector2.Transform(new Vector2(corners[i].X, -corners[i].Y), transform);
}
@@ -418,8 +421,8 @@ namespace Barotrauma
return;
}
int x = rect.X;
int start = (int)Math.Floor((float)(cam.WorldView.X - x) / WaveWidth);
float x = rect.X+Submarine.Position.X;
int start = (int)Math.Floor((cam.WorldView.X - x) / WaveWidth);
start = Math.Max(start, 0);
int end = (waveY.Length - 1)
@@ -435,7 +438,7 @@ namespace Barotrauma
Vector3[] corners = new Vector3[4];
corners[0] = new Vector3(x, top, 0.0f);
corners[3] = new Vector3(corners[0].X, surface + waveY[i], 0.0f);
corners[3] = new Vector3(corners[0].X, drawSurface + waveY[i], 0.0f);
//skip adjacent "water rects" if the surface of the water is roughly at the same position
int width = WaveWidth;
@@ -446,7 +449,7 @@ namespace Barotrauma
}
corners[1] = new Vector3(x + width, top, 0.0f);
corners[2] = new Vector3(corners[1].X, surface + waveY[i+1], 0.0f);
corners[2] = new Vector3(corners[1].X, drawSurface + waveY[i + 1], 0.0f);
Vector2[] uvCoords = new Vector2[4];
for (int n = 0; n < 4; n++)
@@ -527,7 +530,7 @@ namespace Barotrauma
return element;
}
public static void Load(XElement element)
public static void Load(XElement element, Submarine submarine)
{
Rectangle rect = new Rectangle(
int.Parse(element.Attribute("x").Value),
@@ -535,7 +538,7 @@ namespace Barotrauma
int.Parse(element.Attribute("width").Value),
int.Parse(element.Attribute("height").Value));
Hull h = new Hull(rect);
Hull h = new Hull(rect, submarine);
h.volume = ToolBox.GetAttributeFloat(element, "pressure", 0.0f);
+4 -4
View File
@@ -239,7 +239,7 @@ namespace Barotrauma
for (int i = 0; i <3 ; i++ )
{
Vector2 position = pathCells[Rand.Range((int)(pathCells.Count * 0.5f), pathCells.Count - 2, false)].Center;
WayPoint wayPoint = new WayPoint(new Rectangle((int)position.X, (int)position.Y, 10, 10));
WayPoint wayPoint = new WayPoint(new Rectangle((int)position.X, (int)position.Y, 10, 10), null);
wayPoint.MoveWithLevel = true;
wayPoint.SpawnType = SpawnType.Enemy;
}
@@ -454,7 +454,7 @@ namespace Barotrauma
if (placeWaypoints)
{
WayPoint newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, (int)(borders.Height + shaftHeight), 10, 10));
WayPoint newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, (int)(borders.Height + shaftHeight), 10, 10), null);
newWaypoint.MoveWithLevel = true;
WayPoint prevWaypoint = newWaypoint;
@@ -471,7 +471,7 @@ namespace Barotrauma
}
if (i >= pathCells.Count) break;
newWaypoint = new WayPoint(new Rectangle((int)pathCells[i].Center.X, (int)pathCells[i].Center.Y, 10, 10));
newWaypoint = new WayPoint(new Rectangle((int)pathCells[i].Center.X, (int)pathCells[i].Center.Y, 10, 10), null);
newWaypoint.MoveWithLevel = true;
if (prevWaypoint != null)
{
@@ -481,7 +481,7 @@ namespace Barotrauma
prevWaypoint = newWaypoint;
}
newWaypoint = new WayPoint(new Rectangle((int)pathCells[pathCells.Count - 1].Center.X, (int)(borders.Height + shaftHeight), 10, 10));
newWaypoint = new WayPoint(new Rectangle((int)pathCells[pathCells.Count - 1].Center.X, (int)(borders.Height + shaftHeight), 10, 10), null);
newWaypoint.MoveWithLevel = true;
prevWaypoint.linkedTo.Add(newWaypoint);
+4 -2
View File
@@ -82,7 +82,7 @@ namespace Barotrauma
get { return false; }
}
public virtual Vector2 Position
public override Vector2 Position
{
get
{
@@ -138,7 +138,9 @@ namespace Barotrauma
{
get { return ""; }
}
public MapEntity(Submarine submarine) : base(submarine) { }
public virtual void Move(Vector2 amount)
{
rect.X += (int)amount.X;
+12 -9
View File
@@ -138,7 +138,8 @@ namespace Barotrauma
//}
}
public Structure(Rectangle rectangle, StructurePrefab sp)
public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine)
: base(submarine)
{
if (rectangle.Width == 0 || rectangle.Height == 0) return;
@@ -291,24 +292,25 @@ namespace Barotrauma
Color color = (isHighlighted) ? Color.Green : Color.White;
if (isSelected && editing) color = Color.Red;
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
Vector2 drawPos = Submarine == null ? new Vector2(rect.X, -rect.Y) : new Vector2(rect.X + Submarine.DrawPosition.X, -(rect.Y + Submarine.DrawPosition.Y));
prefab.sprite.DrawTiled(spriteBatch, drawPos, new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
foreach (WallSection s in sections)
{
if (s.isHighLighted)
{
GUI.DrawRectangle(spriteBatch,
new Rectangle((int)s.rect.X, (int)-s.rect.Y, (int)s.rect.Width, (int)s.rect.Height),
drawPos, new Vector2(rect.Width, rect.Height),
new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true);
}
s.isHighLighted = false;
if (s.damage < 0.01f) continue;
GUI.DrawRectangle(spriteBatch,
new Rectangle((int)s.rect.X, (int)-s.rect.Y, (int)s.rect.Width, (int)s.rect.Height),
GUI.DrawRectangle(spriteBatch,
drawPos, new Vector2(rect.Width, rect.Height),
Color.Black * (s.damage / prefab.MaxHealth), true);
}
@@ -474,7 +476,7 @@ namespace Barotrauma
gapRect.Y += 10;
gapRect.Width += 20;
gapRect.Height += 20;
sections[sectionIndex].gap = new Gap(gapRect, !isHorizontal);
sections[sectionIndex].gap = new Gap(gapRect, !isHorizontal, Submarine);
}
}
@@ -590,7 +592,7 @@ namespace Barotrauma
return element;
}
public static void Load(XElement element)
public static void Load(XElement element, Submarine submarine)
{
string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
string[] rectValues = rectString.Split(',');
@@ -609,7 +611,8 @@ namespace Barotrauma
{
if (ep.Name == name)
{
s = new Structure(rect, (StructurePrefab)ep);
s = new Structure(rect, (StructurePrefab)ep, submarine);
s.Submarine = submarine;
s.ID = (ushort)int.Parse(element.Attribute("ID").Value);
break;
}
+1 -1
View File
@@ -143,7 +143,7 @@ namespace Barotrauma
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
{
new Structure(newRect, this);
new Structure(newRect, this, Submarine.Loaded);
selected = null;
return;
}
+23 -6
View File
@@ -41,6 +41,7 @@ namespace Barotrauma
private string filePath;
private string name;
private Vector2 prevPosition;
private float lastNetworkUpdate;
@@ -93,14 +94,18 @@ namespace Barotrauma
return (loaded==null) ? Rectangle.Empty : Loaded.subBody.Borders;
}
}
public Vector2 Position
public override Vector2 Position
{
get { return subBody.Position; }
}
public new Vector2 DrawPosition
{
get;
private set;
}
public Vector2 Speed
{
get { return subBody==null ? Vector2.Zero : subBody.Speed; }
@@ -129,7 +134,7 @@ namespace Barotrauma
//constructors & generation ----------------------------------------------------
public Submarine(string filePath, string hash = "")
public Submarine(string filePath, string hash = "") : base(null)
{
this.filePath = filePath;
try
@@ -180,6 +185,12 @@ namespace Barotrauma
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
}
if (Submarine.Loaded!=null)
{
Submarine.Loaded.DrawPosition = Physics.Interpolate(Submarine.Loaded.prevPosition, Submarine.Loaded.Position);
}
if (loaded == null) return;
//foreach (HullBody hb in loaded.hullBodies)
@@ -373,6 +384,12 @@ namespace Barotrauma
if (subBody != null) subBody.ApplyForce(force);
}
public void SetPrevTransform(Vector2 position, Camera cam = null)
{
if (cam != null) cam.Position += prevPosition - position;
prevPosition = position;
}
public void SetPosition(Vector2 position)
{
if (!MathUtils.IsValid(position)) return;
@@ -618,7 +635,7 @@ namespace Barotrauma
try
{
MethodInfo loadMethod = t.GetMethod("Load");
loadMethod.Invoke(t, new object[] { element });
loadMethod.Invoke(t, new object[] { element, this });
}
catch (Exception e)
{
+1 -1
View File
@@ -85,7 +85,7 @@ namespace Barotrauma
basicEffect.Texture = texture;
basicEffect.View = Matrix.Identity;
basicEffect.World = cam.ShaderTransform
basicEffect.World = transform
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
basicEffect.CurrentTechnique.Passes[0].Apply();
+15 -16
View File
@@ -63,7 +63,14 @@ namespace Barotrauma
}
}
public WayPoint(Rectangle newRect)
public WayPoint(Vector2 position, SpawnType spawnType, Submarine submarine, Gap gap = null)
: this(new Rectangle((int)position.X-3, (int)position.Y+3, 6, 6), submarine)
{
this.spawnType = spawnType;
ConnectedGap = gap;
}
public WayPoint(Rectangle newRect, Submarine submarine)
: base (submarine)
{
rect = newRect;
linkedTo = new ObservableCollection<MapEntity>();
@@ -73,14 +80,6 @@ namespace Barotrauma
WayPointList.Add(this);
}
public WayPoint(Vector2 position, SpawnType spawnType, Gap gap = null)
:this(new Rectangle((int)position.X-3, (int)position.Y+3, 6, 6))
{
this.spawnType = spawnType;
ConnectedGap = gap;
}
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back=true)
{
if (!editing && !GameMain.DebugDraw) return;
@@ -228,13 +227,13 @@ namespace Barotrauma
if (hull.Rect.Width<minDist*3.0f)
{
var wayPoint = new WayPoint(
new Vector2(hull.Rect.X + hull.Rect.Width / 2.0f, hull.Rect.Y - hull.Rect.Height + heightFromFloor), SpawnType.Path);
new Vector2(hull.Rect.X + hull.Rect.Width / 2.0f, hull.Rect.Y - hull.Rect.Height + heightFromFloor), SpawnType.Path, Submarine.Loaded);
continue;
}
for (float x = hull.Rect.X + minDist; x <= hull.Rect.X + hull.Rect.Width - minDist; x += minDist)
{
var wayPoint = new WayPoint(new Vector2(x, hull.Rect.Y - hull.Rect.Height + heightFromFloor), SpawnType.Path);
var wayPoint = new WayPoint(new Vector2(x, hull.Rect.Y - hull.Rect.Height + heightFromFloor), SpawnType.Path, Submarine.Loaded);
if (prevWaypoint != null) wayPoint.ConnectTo(prevWaypoint);
@@ -257,11 +256,11 @@ namespace Barotrauma
stairPoints[0] = new WayPoint(
new Vector2(stairs.Rect.X - 50.0f,
stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? 80 : stairs.Rect.Height) + heightFromFloor), SpawnType.Path);
stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? 80 : stairs.Rect.Height) + heightFromFloor), SpawnType.Path, Submarine.Loaded);
stairPoints[1] = new WayPoint(
new Vector2(stairs.Rect.Right + 50.0f,
stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? stairs.Rect.Height : 80) + heightFromFloor), SpawnType.Path);
stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? stairs.Rect.Height : 80) + heightFromFloor), SpawnType.Path, Submarine.Loaded);
for (int i = 0; i < 2; i++ )
{
@@ -281,7 +280,7 @@ namespace Barotrauma
if (!gap.isHorizontal) continue;
var wayPoint = new WayPoint(
new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height + heightFromFloor), SpawnType.Path, gap);
new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height + heightFromFloor), SpawnType.Path, Submarine.Loaded, gap);
for (int dir = -1; dir <= 1; dir += 2)
{
@@ -442,14 +441,14 @@ namespace Barotrauma
return element;
}
public static void Load(XElement element)
public static void Load(XElement element, Submarine submarine)
{
Rectangle rect = new Rectangle(
int.Parse(element.Attribute("x").Value),
int.Parse(element.Attribute("y").Value),
(int)Submarine.GridSize.X, (int)Submarine.GridSize.Y);
WayPoint w = new WayPoint(rect);
WayPoint w = new WayPoint(rect, submarine);
w.ID = (ushort)int.Parse(element.Attribute("ID").Value);
w.spawnType = (SpawnType)Enum.Parse(typeof(SpawnType),