Fixed wrappingwalls, fixed Level.GetCells returning the same cell multiple times, placing backgroundsprites based on level seed

This commit is contained in:
Regalis
2016-01-20 23:26:41 +02:00
parent 2761c4a610
commit 75b8e44d3c
6 changed files with 35 additions and 120 deletions
@@ -70,12 +70,12 @@ namespace Barotrauma
private Vector2? FindSpritePosition(Level level, BackgroundSpritePrefab prefab) private Vector2? FindSpritePosition(Level level, BackgroundSpritePrefab prefab)
{ {
Vector2 randomPos = new Vector2(Rand.Range(0.0f, level.Size.X), Rand.Range(0.0f, level.Size.Y)); Vector2 randomPos = new Vector2(Rand.Range(0.0f, level.Size.X, false), Rand.Range(0.0f, level.Size.Y, false));
var cells = level.GetCells(randomPos); var cells = level.GetCells(randomPos);
if (!cells.Any()) return null; if (!cells.Any()) return null;
VoronoiCell cell = cells[Rand.Int(cells.Count)]; VoronoiCell cell = cells[Rand.Int(cells.Count, false)];
GraphEdge bestEdge = null; GraphEdge bestEdge = null;
foreach (GraphEdge edge in cell.edges) foreach (GraphEdge edge in cell.edges)
{ {
@@ -128,7 +128,7 @@ namespace Barotrauma
totalCommonness += prefab.Commonness; totalCommonness += prefab.Commonness;
} }
float randomNumber = Rand.Int(totalCommonness+1); float randomNumber = Rand.Int(totalCommonness+1, false);
foreach (BackgroundSpritePrefab prefab in prefabs) foreach (BackgroundSpritePrefab prefab in prefabs)
{ {
@@ -134,19 +134,22 @@ namespace Barotrauma.Items.Components
foreach (GraphEdge edge in cell.edges) foreach (GraphEdge edge in cell.edges)
{ {
if (!edge.isSolid) continue; if (!edge.isSolid) continue;
float cellDot = Vector2.Dot(cell.Center - item.WorldPosition, edge.Center - cell.Center); float cellDot = Vector2.Dot(cell.Center - item.WorldPosition, (edge.Center+cell.Translation) - cell.Center);
if (cellDot > 0) continue; if (cellDot > 0) continue;
float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center-item.WorldPosition)); float facingDot = Vector2.Dot(
facingDot = 1.0f;// MathHelper.Clamp(facingDot, -1.0f, 1.0f); Vector2.Normalize(edge.point1 - edge.point2),
Vector2.Normalize(cell.Center-item.WorldPosition));
Vector2 point1 = (edge.point1); //if (Math.Abs(facingDot) > 0.5f) continue;
Vector2 point2 = (edge.point2);
float length = (point1 - point2).Length(); //facingDot = 1.0f;// MathHelper.Clamp(facingDot, -1.0f, 1.0f);
for (float x = 0; x < length; x += Rand.Range(600.0f, 800.0f))
float length = (edge.point1 - edge.point2).Length();
for (float x = 0; x < length; x += Rand.Range(300.0f, 400.0f))
{ {
Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x; Vector2 point = edge.point1 + Vector2.Normalize(edge.point2 - edge.point1) * x;
point += cell.Translation;
float pointDist = Vector2.Distance(item.WorldPosition, point) * displayScale; float pointDist = Vector2.Distance(item.WorldPosition, point) * displayScale;
+7 -107
View File
@@ -872,7 +872,7 @@ namespace Barotrauma
endPos, endPos,
null, Physics.CollisionLevel) != null) null, Physics.CollisionLevel) != null)
{ {
position = ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition - Vector2.Normalize(startPos - endPos)*offsetFromWall); position = ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition + Vector2.Normalize(startPos - endPos)*offsetFromWall);
break; break;
} }
@@ -888,109 +888,13 @@ namespace Barotrauma
return position; return position;
} }
//public void SetPosition(Vector2 pos)
//{
// Vector2 amount = pos - Position;
// Vector2 simAmount = ConvertUnits.ToSimUnits(amount);
// //foreach (VoronoiCell cell in cells)
// //{
// // if (cell.body == null) continue;
// // cell.body.SleepingAllowed = false;
// // cell.body.SetTransform(cell.body.Position + simAmount, cell.body.Rotation);
// //}
// foreach (Body body in bodies)
// {
// body.SetTransform(body.Position + simAmount, body.Rotation);
// }
// foreach (MapEntity mapEntity in MapEntity.mapEntityList)
// {
// Item item = mapEntity as Item;
// if (item == null)
// {
// //if (!mapEntity.MoveWithLevel) continue;
// //mapEntity.Move(amount);
// }
// else if (item.body != null)
// {
// if (item.CurrentHull != null) continue;
// item.SetTransform(item.SimPosition+amount, item.body.Rotation);
// }
// }
// //WrappingWall.UpdateWallShift(Position, wrappingWalls);
//}
//Vector2 prevVelocity;
//public void Move(Vector2 amount)
//{
// Vector2 simVelocity = ConvertUnits.ToSimUnits(amount / (float)Physics.step);
// foreach (Body body in bodies)
// {
// body.LinearVelocity = simVelocity;
// }
// foreach (Character character in Character.CharacterList)
// {
// foreach (Limb limb in character.AnimController.Limbs)
// {
// if (character.AnimController.CurrentHull != null) continue;
// limb.body.LinearVelocity += simVelocity;
// }
// }
// foreach (Item item in Item.ItemList)
// {
// if (item.body==null || item.CurrentHull != null) continue;
// item.body.LinearVelocity += simVelocity;
// }
// AtStartPosition = Vector2.Distance(startPosition, -Position) < ExitDistance;
// AtEndPosition = Vector2.Distance(endPosition, -Position) < ExitDistance;
// prevVelocity = simVelocity;
// WrappingWall.UpdateWallShift(-Position, wrappingWalls);
//}
//public static void AfterWorldStep()
//{
// if (loaded == null) return;
// loaded.ResetBodyVelocities();
//}
//private void ResetBodyVelocities()
//{
// if (prevVelocity == Vector2.Zero) return;
// if (!MathUtils.IsValid(prevVelocity))
// {
// prevVelocity = Vector2.Zero;
// return;
// }
// foreach (Character character in Character.CharacterList)
// {
// if (character.AnimController.CurrentHull != null) continue;
// foreach (Limb limb in character.AnimController.Limbs)
// {
// limb.body.LinearVelocity -= prevVelocity;
// }
// }
// foreach (Item item in Item.ItemList)
// {
// if (item.body == null || item.CurrentHull != null) continue;
// item.body.LinearVelocity -= prevVelocity;
// }
//}
public void Update (float deltaTime) public void Update (float deltaTime)
{ {
if (Submarine.Loaded!=null)
{
WrappingWall.UpdateWallShift(Submarine.Loaded.WorldPosition, wrappingWalls);
}
renderer.Update(deltaTime); renderer.Update(deltaTime);
} }
@@ -1044,11 +948,7 @@ namespace Barotrauma
{ {
foreach (VoronoiCell cell in cellGrid[x, y]) foreach (VoronoiCell cell in cellGrid[x, y])
{ {
for (int i = 0; i < cell.edges.Count; i++) cells.Add(cell);
{
cells.Add(cell);
//GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red);
}
} }
} }
} }
@@ -182,6 +182,11 @@ namespace Barotrauma
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
basicEffect.World = Matrix.CreateTranslation(new Vector3(level.WrappingWalls[side, i].Offset, 0.0f)) * cam.ShaderTransform
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
basicEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].BodyVertices); graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].BodyVertices);
graphicsDevice.DrawPrimitives( graphicsDevice.DrawPrimitives(
@@ -203,6 +208,10 @@ namespace Barotrauma
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
basicEffect.World = Matrix.CreateTranslation(new Vector3(level.WrappingWalls[side,i].Offset, 0.0f)) * cam.ShaderTransform
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
basicEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].WallVertices); graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].WallVertices);
graphicsDevice.DrawPrimitives( graphicsDevice.DrawPrimitives(
@@ -126,9 +126,11 @@ namespace Voronoi2
public Body body; public Body body;
public Vector2 Translation;
public Vector2 Center public Vector2 Center
{ {
get { return new Vector2((float)site.coord.x, (float)site.coord.y); } get { return new Vector2((float)site.coord.x, (float)site.coord.y)+Translation; }
} }
public VoronoiCell(Vector2[] vertices) public VoronoiCell(Vector2[] vertices)
@@ -183,6 +183,7 @@ namespace Barotrauma
foreach (VoronoiCell cell in cells) foreach (VoronoiCell cell in cells)
{ {
cell.body.SetTransform(cell.body.Position + simMoveAmount, 0.0f); cell.body.SetTransform(cell.body.Position + simMoveAmount, 0.0f);
cell.Translation += moveAmount;
} }
midPos += moveAmount; midPos += moveAmount;