diff --git a/Subsurface/Source/Camera.cs b/Subsurface/Source/Camera.cs index d483da785..2aac86935 100644 --- a/Subsurface/Source/Camera.cs +++ b/Subsurface/Source/Camera.cs @@ -148,16 +148,17 @@ namespace Barotrauma Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) * viewMatrix; - prevPosition = position; - prevZoom = zoom; + Sound.CameraPos = new Vector3(WorldViewCenter.X, WorldViewCenter.Y, 0.0f); - } - + public void MoveCamera(float deltaTime) - { + { + prevPosition = position; + prevZoom = zoom; + float moveSpeed = 20.0f/zoom; Vector2 moveCam = Vector2.Zero; @@ -210,6 +211,7 @@ namespace Barotrauma public Vector2 Position { get { return position; } + set { position = value; } } public Vector2 ScreenToWorld(Vector2 coords) diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs index 1c2b2c4cb..0e9d9ea34 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveIdle.cs @@ -54,15 +54,19 @@ namespace Barotrauma (pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable))) { //steer away from edges of the hull - if (character.Position.X < character.AnimController.CurrentHull.Rect.X + WallAvoidDistance) + if (character.AnimController.CurrentHull!=null) { - pathSteering.SteeringManual(deltaTime, Vector2.UnitX); - } - else if (character.Position.X > character.AnimController.CurrentHull.Rect.Right - WallAvoidDistance) - { - pathSteering.SteeringManual(deltaTime, -Vector2.UnitX); + if (character.Position.X < character.AnimController.CurrentHull.Rect.X + WallAvoidDistance) + { + pathSteering.SteeringManual(deltaTime, Vector2.UnitX); + } + else if (character.Position.X > character.AnimController.CurrentHull.Rect.Right - WallAvoidDistance) + { + pathSteering.SteeringManual(deltaTime, -Vector2.UnitX); + } } + character.AIController.SteeringManager.SteeringWander(1.0f); return; } diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs index ba52cab67..e1247ffdb 100644 --- a/Subsurface/Source/Characters/AICharacter.cs +++ b/Subsurface/Source/Characters/AICharacter.cs @@ -94,7 +94,6 @@ namespace Barotrauma case NetworkEventType.KillCharacter: return true; case NetworkEventType.ImportantEntityUpdate: - int i = 0; //foreach (Limb limb in AnimController.Limbs) //{ //if (RefLimb.ignoreCollisions) continue; diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 8d3ab1458..2bcb357c5 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -152,7 +152,17 @@ namespace Barotrauma public Hull CurrentHull { - get { return currentHull;} + get { return currentHull; } + set + { + if (value == currentHull) return; + + currentHull = value; + foreach (Limb limb in Limbs) + { + limb.body.Submarine = currentHull == null ? null : Submarine.Loaded; + } + } } public bool IgnorePlatforms @@ -534,8 +544,9 @@ namespace Barotrauma if (newHull == currentHull) return; - currentHull = newHull; + CurrentHull = newHull; + UpdateCollisionCategories(); } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 53a9f3573..2126dbb26 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -273,19 +273,19 @@ namespace Barotrauma get { return AnimController.RefLimb.SimPosition; } } - public Vector2 Position + public override Vector2 Position { - get { return ConvertUnits.ToDisplayUnits(AnimController.RefLimb.SimPosition); } + get { return AnimController.RefLimb.Position; } } - + static Character() { - DeathMsg[(int)CauseOfDeath.Damage] = "succumbed to your injuries"; - DeathMsg[(int)CauseOfDeath.Bloodloss] = "bled out"; - DeathMsg[(int)CauseOfDeath.Drowning] = "drowned"; + DeathMsg[(int)CauseOfDeath.Damage] = "succumbed to your injuries"; + DeathMsg[(int)CauseOfDeath.Bloodloss] = "bled out"; + DeathMsg[(int)CauseOfDeath.Drowning] = "drowned"; DeathMsg[(int)CauseOfDeath.Suffocation] = "suffocated"; - DeathMsg[(int)CauseOfDeath.Pressure] = "been crushed by water pressure"; - DeathMsg[(int)CauseOfDeath.Burn] = "burnt to death"; + DeathMsg[(int)CauseOfDeath.Pressure] = "been crushed by water pressure"; + DeathMsg[(int)CauseOfDeath.Burn] = "burnt to death"; } public static Character Create(string file, Vector2 position) @@ -334,6 +334,7 @@ namespace Barotrauma } protected Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false) + : base(null) { keys = new Key[Enum.GetNames(typeof(InputType)).Length]; @@ -522,7 +523,7 @@ namespace Barotrauma continue; } - Item item = new Item(itemPrefab, Position); + Item item = new Item(itemPrefab, Position, null); if (info.Job.EquipSpawnItem[i]) { @@ -754,12 +755,15 @@ namespace Barotrauma if (moveCam) { - cam.TargetPos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition); + cam.TargetPos = WorldPosition; cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, 250.0f, 0.05f); } - cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition); + cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition); + if (AnimController.CurrentHull != null) cursorPosition -= Submarine.Loaded.Position; + Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition); + if (Vector2.Distance(AnimController.Limbs[0].SimPosition, mouseSimPos)>1.0f) { Body body = Submarine.PickBody(AnimController.Limbs[0].SimPosition, mouseSimPos); @@ -877,9 +881,11 @@ namespace Barotrauma { if (!Enabled) return; + Submarine = AnimController.CurrentHull == null ? null : Submarine.Loaded; + obstructVisionAmount = Math.Max(obstructVisionAmount - deltaTime, 0.0f); - AnimController.SimplePhysicsEnabled = (Character.controlled != this && Vector2.Distance(cam.WorldViewCenter, Position) > 5000.0f); + AnimController.SimplePhysicsEnabled = (Character.controlled != this && Vector2.Distance(cam.WorldViewCenter, WorldPosition) > 5000.0f); if (isDead) return; diff --git a/Subsurface/Source/Events/Quests/SalvageQuest.cs b/Subsurface/Source/Events/Quests/SalvageQuest.cs index b46c52dd7..7f911a0ba 100644 --- a/Subsurface/Source/Events/Quests/SalvageQuest.cs +++ b/Subsurface/Source/Events/Quests/SalvageQuest.cs @@ -65,7 +65,7 @@ namespace Barotrauma } while (tries < 10); - item = new Item(itemPrefab, position); + item = new Item(itemPrefab, position, null); item.MoveWithLevel = true; item.body.FarseerBody.GravityScale = 0.5f; //item.MoveWithLevel = true; diff --git a/Subsurface/Source/GameSession/CargoManager.cs b/Subsurface/Source/GameSession/CargoManager.cs index 3e106d654..8d0226448 100644 --- a/Subsurface/Source/GameSession/CargoManager.cs +++ b/Subsurface/Source/GameSession/CargoManager.cs @@ -44,7 +44,7 @@ namespace Barotrauma Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20), Rand.Range(cargoRoom.Rect.Y - cargoRoom.Rect.Height + 20.0f, cargoRoom.Rect.Y)); - new Item(prefab as ItemPrefab, position); + new Item(prefab as ItemPrefab, position, wp.Submarine); } purchasedItems.Clear(); diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 210d4cc9c..a5fb7cc62 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -45,7 +45,7 @@ namespace Barotrauma.Items.Components linkedGap = e as Gap; if (linkedGap != null) return linkedGap; } - linkedGap = new Gap(item.Rect); + linkedGap = new Gap(item.Rect, Item.Submarine); linkedGap.Open = openState; item.linkedTo.Add(linkedGap); return linkedGap; diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 8f4177483..0d923aaf3 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -255,13 +255,14 @@ namespace Barotrauma //} - public Item(ItemPrefab itemPrefab, Vector2 position) - : this(new Rectangle((int)position.X, (int)position.Y, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab) + public Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine) + : this(new Rectangle((int)position.X, (int)position.Y, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab, submarine) { } - public Item(Rectangle newRect, ItemPrefab itemPrefab) + public Item(Rectangle newRect, ItemPrefab itemPrefab, Submarine submarine) + : base(submarine) { prefab = itemPrefab; @@ -409,6 +410,10 @@ namespace Barotrauma public virtual Hull FindHull() { CurrentHull = Hull.FindHull((body == null) ? Position : ConvertUnits.ToDisplayUnits(body.SimPosition), CurrentHull); + if (body!=null) + { + body.Submarine = CurrentHull == null ? null : Submarine.Loaded; + } return CurrentHull; } @@ -598,7 +603,16 @@ namespace Barotrauma { if (body == null) { - prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color); + if (prefab.ResizeHorizontal || prefab.ResizeVertical) + { + + prefab.sprite.DrawTiled(spriteBatch, new Vector2(DrawPosition.X+rect.Width/2, -DrawPosition.Y-rect.Height/2), new Vector2(rect.Width, rect.Height), color); + } + else + { + prefab.sprite.Draw(spriteBatch, new Vector2(DrawPosition.X, -DrawPosition.Y), color); + } + } else if (body.Enabled) { @@ -615,7 +629,7 @@ namespace Barotrauma depth = holdable.Picker.AnimController.GetLimb(LimbType.LeftArm).sprite.Depth - 0.000001f; } - body.Draw(spriteBatch, prefab.sprite, color, depth); + body.Draw(spriteBatch, prefab.sprite, color, depth); } else { @@ -1159,8 +1173,8 @@ 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(','); Rectangle rect = Rectangle.Empty; @@ -1195,7 +1209,8 @@ namespace Barotrauma rect.Height = (int)ip.Size.Y; } - Item item = new Item(rect, ip); + Item item = new Item(rect, ip, submarine); + item.Submarine = submarine; item.ID = (ushort)int.Parse(element.Attribute("ID").Value); item.linkedToID = new List(); diff --git a/Subsurface/Source/Items/ItemPrefab.cs b/Subsurface/Source/Items/ItemPrefab.cs index 8f9bd920d..23541fbea 100644 --- a/Subsurface/Source/Items/ItemPrefab.cs +++ b/Subsurface/Source/Items/ItemPrefab.cs @@ -83,7 +83,7 @@ namespace Barotrauma { if (PlayerInput.LeftButtonClicked()) { - new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this); + new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.Loaded); //constructor.Invoke(lobject); placePosition = Vector2.Zero; @@ -112,7 +112,7 @@ namespace Barotrauma if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released) { - new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this); + new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded); placePosition = Vector2.Zero; //selected = null; return; diff --git a/Subsurface/Source/Items/ItemSpawner.cs b/Subsurface/Source/Items/ItemSpawner.cs index 7c73b7407..4de33a80f 100644 --- a/Subsurface/Source/Items/ItemSpawner.cs +++ b/Subsurface/Source/Items/ItemSpawner.cs @@ -30,7 +30,8 @@ namespace Barotrauma { var itemInfo = spawnQueue.Dequeue(); - new Item(itemInfo.First, itemInfo.Second); + //!!!!!!!!!!!!!!!!!!!!!! + new Item(itemInfo.First, itemInfo.Second, null); } } } diff --git a/Subsurface/Source/Map/Entity.cs b/Subsurface/Source/Map/Entity.cs index c447765c2..a1f3c6b12 100644 --- a/Subsurface/Source/Map/Entity.cs +++ b/Subsurface/Source/Map/Entity.cs @@ -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); diff --git a/Subsurface/Source/Map/Gap.cs b/Subsurface/Source/Map/Gap.cs index 3a62159f0..5fe9e32ba 100644 --- a/Subsurface/Source/Map/Gap.cs +++ b/Subsurface/Source/Map/Gap.cs @@ -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(); @@ -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(); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 5573385fa..22f0f9f69 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -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); diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index dc2f70655..53361633b 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -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); diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 281d9f506..05e282a27 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -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; diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 718a604e8..b76cb1149 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -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; } diff --git a/Subsurface/Source/Map/StructurePrefab.cs b/Subsurface/Source/Map/StructurePrefab.cs index fb6cd0848..9938ebfdd 100644 --- a/Subsurface/Source/Map/StructurePrefab.cs +++ b/Subsurface/Source/Map/StructurePrefab.cs @@ -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; } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 5de6fd1db..fe80f64d8 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -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) { diff --git a/Subsurface/Source/Map/WaterRenderer.cs b/Subsurface/Source/Map/WaterRenderer.cs index c774a3ee2..814973ef3 100644 --- a/Subsurface/Source/Map/WaterRenderer.cs +++ b/Subsurface/Source/Map/WaterRenderer.cs @@ -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(); diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 1b2df74a1..7ed2808f5 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -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(); @@ -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 /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. @@ -94,12 +96,14 @@ namespace Barotrauma StatusEffect.UpdateAll((float)deltaTime); - Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4); + Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 6); //Physics.accumulator = Physics.step; while (Physics.accumulator >= Physics.step) { cam.MoveCamera((float)Physics.step); + if (Submarine.Loaded != null) Submarine.Loaded.SetPrevTransform(Submarine.Loaded.Position, cam); + foreach (PhysicsBody pb in PhysicsBody.list) { pb.SetPrevTransform(pb.SimPosition, pb.Rotation); @@ -229,7 +233,7 @@ namespace Barotrauma spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, - Matrix.CreateTranslation(new Vector3(Submarine.Loaded.Position.X, -Submarine.Loaded.Position.Y, 0.0f))*cam.Transform); + cam.Transform); Submarine.DrawBack(spriteBatch); @@ -315,7 +319,7 @@ namespace Barotrauma hull.Render(graphics, cam); } - Hull.renderer.Render(graphics, cam, renderTargetAir,Cam.ShaderTransform); + Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform); if (GameMain.GameSession != null && GameMain.GameSession.Level != null) { @@ -330,7 +334,7 @@ namespace Barotrauma spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null, null, - Matrix.CreateTranslation(new Vector3(Submarine.Loaded.Position.X, -Submarine.Loaded.Position.Y, 0.0f))*cam.Transform); + cam.Transform); foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch); diff --git a/Subsurface/Source/Sprite.cs b/Subsurface/Source/Sprite.cs index ab6af11d7..d36dec81d 100644 --- a/Subsurface/Source/Sprite.cs +++ b/Subsurface/Source/Sprite.cs @@ -216,8 +216,8 @@ namespace Barotrauma public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color) { - pos.X = (int)pos.X; - pos.Y = (int)pos.Y; + //pos.X = (int)pos.X; + //pos.Y = (int)pos.Y; //how many times the texture needs to be drawn on the x-axis int xTiles = (int)Math.Ceiling((targetSize.X+startOffset.X) / sourceRect.Width); diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index e9dcb3c81..ffd5b832a 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ