Conflicts:
	Subsurface_Solution.v12.suo
This commit is contained in:
Regalis
2015-07-06 22:48:47 +03:00
13 changed files with 309 additions and 144 deletions
+4 -2
View File
@@ -13,7 +13,7 @@ namespace Subsurface
public int HeadSpriteId; public int HeadSpriteId;
//public int ID; public Job Job;
public Gender Gender; public Gender Gender;
@@ -24,7 +24,7 @@ namespace Subsurface
// return gender.ToString(); // return gender.ToString();
//} //}
public CharacterInfo(string file, string name = "", Gender gender = Gender.None) public CharacterInfo(string file, string name = "", Gender gender = Gender.None, Job job = null)
{ {
this.File = file; this.File = file;
@@ -62,6 +62,8 @@ namespace Subsurface
HeadSpriteId = Rand.Range((int)headSpriteRange.X, (int)headSpriteRange.Y + 1); HeadSpriteId = Rand.Range((int)headSpriteRange.X, (int)headSpriteRange.Y + 1);
} }
this.Job = (job == null) ? Job.Random() : job;
if (!string.IsNullOrEmpty(name)) if (!string.IsNullOrEmpty(name))
{ {
this.Name = name; this.Name = name;
+4 -2
View File
@@ -106,14 +106,16 @@ namespace Subsurface
float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2; float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
Limb tail = GetLimb(LimbType.Tail); Limb tail = GetLimb(LimbType.Tail);
if (tail != null && waveAmplitude>0.0f) if (tail != null && waveAmplitude > 0.0f)
{ {
walkPos -= movement.Length(); walkPos -= movement.Length();
float waveRotation = (float)Math.Sin(walkPos / waveLength)*waveAmplitude; float waveRotation = (float)Math.Sin(walkPos / waveLength) * waveAmplitude;
float angle = MathUtils.GetShortestAngle(tail.body.Rotation, movementAngle + waveRotation); float angle = MathUtils.GetShortestAngle(tail.body.Rotation, movementAngle + waveRotation);
tail.body.ApplyTorque(angle * tail.Mass);
//limbs[tailIndex].body.ApplyTorque((Math.Sign(angle) + Math.Max(Math.Min(angle * 10.0f, 10.0f), -10.0f)) * limbs[tailIndex].body.Mass); //limbs[tailIndex].body.ApplyTorque((Math.Sign(angle) + Math.Max(Math.Min(angle * 10.0f, 10.0f), -10.0f)) * limbs[tailIndex].body.Mass);
//limbs[tailIndex].body.ApplyTorque(-limbs[tailIndex].body.AngularVelocity * 0.5f * limbs[tailIndex].body.Mass); //limbs[tailIndex].body.ApplyTorque(-limbs[tailIndex].body.AngularVelocity * 0.5f * limbs[tailIndex].body.Mass);
} }
+27 -31
View File
@@ -1,56 +1,52 @@
using System.Collections.Generic; using Microsoft.Xna.Framework;
using System.Xml.Linq; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Subsurface namespace Subsurface
{ {
class Job class Job
{ {
public static List<Job> jobList;
string name; private JobPrefab prefab;
string description;
//names of the items the character spawns with private Dictionary<string, float> skills;
public List<string> itemNames;
public string Name public string Name
{ {
get { return name; } get { return prefab.Name; }
} }
public Job(XElement element) public string Description
{ {
name = element.Name.ToString(); get { return prefab.Description; }
}
description = ToolBox.GetAttributeString(element, "description", ""); public Job(JobPrefab jobPrefab)
{
prefab = jobPrefab;
itemNames = new List<string>(); skills = new Dictionary<string, float>();
foreach (KeyValuePair<string, Vector2> skill in prefab.skills)
foreach (XElement subElement in element.Elements())
{ {
switch (subElement.Name.ToString()) skills.Add(skill.Key, Rand.Range(skill.Value.X, skill.Value.Y, false));
{
case "item":
string itemName = ToolBox.GetAttributeString(subElement, "name", "");
if (!string.IsNullOrEmpty(itemName)) itemNames.Add(itemName);
break;
}
} }
} }
public static Job Random()
public static void LoadAll(string filePath)
{ {
jobList = new List<Job>(); JobPrefab prefab = JobPrefab.List[Rand.Int(JobPrefab.List.Count-1, false)];
XDocument doc = ToolBox.TryLoadXml(filePath); return new Job(prefab);
if (doc == null) return; }
foreach (XElement element in doc.Root.Elements()) public float GetSkill(string skillName)
{ {
Job job = new Job(element); float skillLevel = 0.0f;
jobList.Add(job); skills.TryGetValue(skillName.ToLower(), out skillLevel);
}
return skillLevel;
} }
} }
} }
+105
View File
@@ -0,0 +1,105 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;
namespace Subsurface
{
class JobPrefab
{
public static List<JobPrefab> List;
string name;
string description;
//names of the items the character spawns with
public List<string> itemNames;
public Dictionary<string, Vector2> skills;
public string Name
{
get { return name; }
}
public string Description
{
get { return description; }
}
//public float GetSkill(string skillName)
//{
// float skillLevel = 0.0f;
// if (skills.TryGetValue(skillName.ToLower(), out skillLevel))
// {
// return skillLevel;
// }
// else
// {
// DebugConsole.ThrowError("Skill ''"+skillName+" not found!");
// return skillLevel;
// }
//}
public JobPrefab(XElement element)
{
name = element.Name.ToString();
description = ToolBox.GetAttributeString(element, "description", "");
itemNames = new List<string>();
skills = new Dictionary<string, Vector2>();
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString())
{
case "item":
string itemName = ToolBox.GetAttributeString(subElement, "name", "");
if (!string.IsNullOrEmpty(itemName)) itemNames.Add(itemName);
break;
case "skills":
LoadSkills(subElement);
break;
}
}
}
private void LoadSkills(XElement element)
{
foreach (XElement subElement in element.Elements())
{
string skillName = subElement.Name.ToString().ToLower();
if (skills.ContainsKey(skillName)) continue;
var levelAttribute = subElement.Attribute("level").ToString();
if (levelAttribute.Contains("'"))
{
skills.Add(skillName, ToolBox.ParseToVector2(levelAttribute, false));
}
else
{
float skillLevel = float.Parse(levelAttribute, CultureInfo.InvariantCulture);
skills.Add(skillName, new Vector2(skillLevel, skillLevel));
}
}
}
public static void LoadAll(string filePath)
{
List = new List<JobPrefab>();
XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null) return;
foreach (XElement element in doc.Root.Elements())
{
JobPrefab job = new JobPrefab(element);
List.Add(job);
}
}
}
}
+1 -1
View File
@@ -145,7 +145,7 @@ namespace Subsurface
MapEntityPrefab.Init(); MapEntityPrefab.Init();
Job.LoadAll("Content/Characters/Jobs.xml"); JobPrefab.LoadAll("Content/Characters/Jobs.xml");
StructurePrefab.LoadAll("Content/Map/StructurePrefabs.xml"); StructurePrefab.LoadAll("Content/Map/StructurePrefabs.xml");
ItemPrefab.LoadAll(); ItemPrefab.LoadAll();
+50 -49
View File
@@ -2,6 +2,7 @@
using FarseerPhysics.Common; using FarseerPhysics.Common;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories; using FarseerPhysics.Factories;
using Lidgren.Network;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
@@ -24,13 +25,13 @@ namespace Subsurface
private int siteInterval; private int siteInterval;
const int gridCellWidth = 2000; const int GridCellWidth = 2000;
List<VoronoiCell>[,] cellGrid; private List<VoronoiCell>[,] cellGrid;
//List<Body> bodies; //List<Body> bodies;
List<VoronoiCell> cells; private List<VoronoiCell> cells;
BasicEffect basicEffect; private BasicEffect basicEffect;
private VertexPositionColor[] vertices; private VertexPositionColor[] vertices;
private VertexBuffer vertexBuffer; private VertexBuffer vertexBuffer;
@@ -38,7 +39,7 @@ namespace Subsurface
private Vector2 startPosition; private Vector2 startPosition;
private Vector2 endPosition; private Vector2 endPosition;
Rectangle borders; private Rectangle borders;
public Vector2 StartPosition public Vector2 StartPosition
{ {
@@ -65,7 +66,7 @@ namespace Subsurface
{ {
seed = Rand.Range(0, int.MaxValue, false).ToString(); seed = Rand.Range(0, int.MaxValue, false).ToString();
} }
return new Level((string)seed, 100000, 40000, 2000); return new Level((string)seed, 100000, 40000, 2000);
} }
public void Generate(float minWidth) public void Generate(float minWidth)
@@ -88,7 +89,7 @@ namespace Subsurface
Random rand = new Random(ToolBox.SeedToInt(seed)); Random rand = new Random(ToolBox.SeedToInt(seed));
float siteVariance = siteInterval * 0.8f; float siteVariance = siteInterval * 0.8f;
for (int x = siteInterval/2; x < borders.Width; x += siteInterval) for (int x = siteInterval / 2; x < borders.Width; x += siteInterval)
{ {
for (int y = siteInterval / 2; y < borders.Height; y += siteInterval) for (int y = siteInterval / 2; y < borders.Height; y += siteInterval)
{ {
@@ -107,10 +108,10 @@ namespace Subsurface
Debug.WriteLine("MakeVoronoiGraph: " + sw2.ElapsedMilliseconds + " ms"); Debug.WriteLine("MakeVoronoiGraph: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart(); sw2.Restart();
cellGrid = new List<VoronoiCell>[borders.Width / gridCellWidth, borders.Height / gridCellWidth]; cellGrid = new List<VoronoiCell>[borders.Width / GridCellWidth, borders.Height / GridCellWidth];
for (int x = 0; x < borders.Width / gridCellWidth; x++) for (int x = 0; x < borders.Width / GridCellWidth; x++)
{ {
for (int y = 0; y < borders.Height / gridCellWidth; y++) for (int y = 0; y < borders.Height / GridCellWidth; y++)
{ {
cellGrid[x, y] = new List<VoronoiCell>(); cellGrid[x, y] = new List<VoronoiCell>();
} }
@@ -125,13 +126,13 @@ namespace Subsurface
Site site = (i == 0) ? ge.site1 : ge.site2; Site site = (i == 0) ? ge.site1 : ge.site2;
VoronoiCell cell = cellGrid[ VoronoiCell cell = cellGrid[
(int)Math.Floor(site.coord.x / gridCellWidth), (int)Math.Floor(site.coord.x / GridCellWidth),
(int)Math.Floor(site.coord.y / gridCellWidth)].Find(c => c.site == site); (int)Math.Floor(site.coord.y / GridCellWidth)].Find(c => c.site == site);
if (cell == null) if (cell == null)
{ {
cell = new VoronoiCell(site); cell = new VoronoiCell(site);
cellGrid[(int)Math.Floor(cell.Center.X / gridCellWidth), (int)Math.Floor(cell.Center.Y / gridCellWidth)].Add(cell); cellGrid[(int)Math.Floor(cell.Center.X / GridCellWidth), (int)Math.Floor(cell.Center.Y / GridCellWidth)].Add(cell);
cells.Add(cell); cells.Add(cell);
} }
@@ -162,21 +163,21 @@ namespace Subsurface
//generate a couple of random paths //generate a couple of random paths
for (int i = 0; i < rand.Next() % 3; i++ ) for (int i = 0; i < rand.Next() % 3; i++)
{ {
pathBorders = new Rectangle( pathBorders = new Rectangle(
borders.X + siteInterval * 2, borders.Y - siteInterval * 2, borders.X + siteInterval * 2, borders.Y - siteInterval * 2,
borders.Right - siteInterval * 2, borders.Y + borders.Height - siteInterval * 2); borders.Right - siteInterval * 2, borders.Y + borders.Height - siteInterval * 2);
Vector2 start = pathCells[rand.Next(1,pathCells.Count-2)].Center; Vector2 start = pathCells[rand.Next(1, pathCells.Count - 2)].Center;
float x = pathBorders.X + (float)rand.NextDouble() * (pathBorders.Right - pathBorders.X); float x = pathBorders.X + (float)rand.NextDouble() * (pathBorders.Right - pathBorders.X);
float y = pathBorders.Y + (float)rand.NextDouble() * (pathBorders.Bottom - pathBorders.Y); float y = pathBorders.Y + (float)rand.NextDouble() * (pathBorders.Bottom - pathBorders.Y);
Vector2 end = new Vector2(x,y); Vector2 end = new Vector2(x, y);
pathCells.AddRange pathCells.AddRange
( (
GeneratePath(rand, start,end, cells, pathBorders, 0.0f, 0.8f) GeneratePath(rand, start, end, cells, pathBorders, 0.0f, 0.8f)
); );
} }
@@ -193,9 +194,9 @@ namespace Subsurface
cells.Remove(cell); cells.Remove(cell);
} }
for (int x = 0; x < cellGrid.GetLength(0); x++ ) for (int x = 0; x < cellGrid.GetLength(0); x++)
{ {
for (int y = 0; y < cellGrid.GetLength(1); y++ ) for (int y = 0; y < cellGrid.GetLength(1); y++)
{ {
cellGrid[x, y].Clear(); cellGrid[x, y].Clear();
} }
@@ -203,7 +204,7 @@ namespace Subsurface
foreach (VoronoiCell cell in cells) foreach (VoronoiCell cell in cells)
{ {
cellGrid[(int)Math.Floor(cell.Center.X / gridCellWidth), (int)Math.Floor(cell.Center.Y / gridCellWidth)].Add(cell); cellGrid[(int)Math.Floor(cell.Center.X / GridCellWidth), (int)Math.Floor(cell.Center.Y / GridCellWidth)].Add(cell);
} }
GeneratePolygons(cells, pathCells); GeneratePolygons(cells, pathCells);
@@ -230,7 +231,7 @@ namespace Subsurface
basicEffect = new BasicEffect(Game1.CurrGraphicsDevice); basicEffect = new BasicEffect(Game1.CurrGraphicsDevice);
basicEffect.VertexColorEnabled = true; basicEffect.VertexColorEnabled = true;
Debug.WriteLine("Generated a map with "+sites.Count+" sites in "+sw.ElapsedMilliseconds+" ms"); Debug.WriteLine("Generated a map with " + sites.Count + " sites in " + sw.ElapsedMilliseconds + " ms");
} }
private List<VoronoiCell> GeneratePath(Random rand, Vector2 start, Vector2 end, List<VoronoiCell> cells, Microsoft.Xna.Framework.Rectangle limits, float minWidth, float wanderAmount = 0.3f) private List<VoronoiCell> GeneratePath(Random rand, Vector2 start, Vector2 end, List<VoronoiCell> cells, Microsoft.Xna.Framework.Rectangle limits, float minWidth, float wanderAmount = 0.3f)
@@ -255,7 +256,7 @@ namespace Subsurface
int edgeIndex = 0; int edgeIndex = 0;
//steer towards target //steer towards target
if (rand.NextDouble()>wanderAmount) if (rand.NextDouble() > wanderAmount)
{ {
for (int i = 0; i < currentCell.edges.Count; i++) for (int i = 0; i < currentCell.edges.Count; i++)
{ {
@@ -269,13 +270,13 @@ namespace Subsurface
{ {
List<GraphEdge> allowedEdges = new List<GraphEdge>(); List<GraphEdge> allowedEdges = new List<GraphEdge>();
foreach(GraphEdge edge in currentCell.edges) foreach (GraphEdge edge in currentCell.edges)
{ {
if (!limits.Contains(edge.AdjacentCell(currentCell).Center)) continue; if (!limits.Contains(edge.AdjacentCell(currentCell).Center)) continue;
allowedEdges.Add(edge); allowedEdges.Add(edge);
} }
edgeIndex = (allowedEdges.Count==0) ? edgeIndex = (allowedEdges.Count == 0) ?
0 : currentCell.edges.IndexOf(allowedEdges[rand.Next() % allowedEdges.Count]); 0 : currentCell.edges.IndexOf(allowedEdges[rand.Next() % allowedEdges.Count]);
} }
@@ -284,7 +285,7 @@ namespace Subsurface
pathCells.Add(currentCell); pathCells.Add(currentCell);
} while (currentCell!=endCell); } while (currentCell != endCell);
Debug.WriteLine("genpath: " + sw2.ElapsedMilliseconds + " ms"); Debug.WriteLine("genpath: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart(); sw2.Restart();
@@ -317,12 +318,12 @@ namespace Subsurface
minDistance *= 0.5f; minDistance *= 0.5f;
do do
{ {
for (int x = -1; x<=1; x++) for (int x = -1; x <= 1; x++)
{ {
for (int y = -1; y <= 1; y++) for (int y = -1; y <= 1; y++)
{ {
if (x == 0 && y == 0) continue; if (x == 0 && y == 0) continue;
Vector2 cornerPos = position + new Vector2(x*minDistance, y*minDistance); Vector2 cornerPos = position + new Vector2(x * minDistance, y * minDistance);
int cellIndex = FindCellIndex(cornerPos); int cellIndex = FindCellIndex(cornerPos);
if (cellIndex == -1) continue; if (cellIndex == -1) continue;
@@ -337,7 +338,7 @@ namespace Subsurface
if (Vector2.Distance(emptyCells[targetCellIndex].Center, position) < step * 2.0f) targetCellIndex++; if (Vector2.Distance(emptyCells[targetCellIndex].Center, position) < step * 2.0f) targetCellIndex++;
} while (Vector2.Distance(position, emptyCells[emptyCells.Count - 1].Center) > step*2.0f); } while (Vector2.Distance(position, emptyCells[emptyCells.Count - 1].Center) > step * 2.0f);
return tooCloseCells; return tooCloseCells;
} }
@@ -399,16 +400,16 @@ namespace Subsurface
float closestDist = 0.0f; float closestDist = 0.0f;
VoronoiCell closestCell = null; VoronoiCell closestCell = null;
int gridPosX = (int)Math.Floor(position.X / gridCellWidth); int gridPosX = (int)Math.Floor(position.X / GridCellWidth);
int gridPosY = (int)Math.Floor(position.Y / gridCellWidth); int gridPosY = (int)Math.Floor(position.Y / GridCellWidth);
int searchOffset = 1; int searchOffset = 1;
for (int x = Math.Max(gridPosX-searchOffset,0); x<=Math.Min(gridPosX+searchOffset, cellGrid.GetLength(0)-1); x++) for (int x = Math.Max(gridPosX - searchOffset, 0); x <= Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1); x++)
{ {
for (int y = Math.Max(gridPosY-searchOffset,0); y<=Math.Min(gridPosY+searchOffset, cellGrid.GetLength(1)-1); y++) for (int y = Math.Max(gridPosY - searchOffset, 0); y <= Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1); y++)
{ {
for (int i = 0; i < cellGrid[x,y].Count; i++) for (int i = 0; i < cellGrid[x, y].Count; i++)
{ {
float dist = Vector2.Distance(cellGrid[x, y][i].Center, position); float dist = Vector2.Distance(cellGrid[x, y][i].Center, position);
if (closestDist != 0.0f && dist > closestDist) continue; if (closestDist != 0.0f && dist > closestDist) continue;
@@ -461,12 +462,12 @@ namespace Subsurface
tempVertices.Sort(new CompareCCW(cell.Center)); tempVertices.Sort(new CompareCCW(cell.Center));
int lastIndex = 1; int lastIndex = 1;
for (int i = 0; i < triangleCount; i++ ) for (int i = 0; i < triangleCount; i++)
{ {
//simple triangulation //simple triangulation
List<Vector2> triangleVertices = new List<Vector2>(); List<Vector2> triangleVertices = new List<Vector2>();
triangleVertices.Add(tempVertices[0]); triangleVertices.Add(tempVertices[0]);
for (int j = lastIndex; j<=lastIndex+1; j++) for (int j = lastIndex; j <= lastIndex + 1; j++)
{ {
triangleVertices.Add(tempVertices[j]); triangleVertices.Add(tempVertices[j]);
} }
@@ -474,7 +475,7 @@ namespace Subsurface
foreach (Vector2 vertex in triangleVertices) foreach (Vector2 vertex in triangleVertices)
{ {
verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), Color.LightGray*0.8f));//new Color(n,(n*2)%255,(n*3)%255)*0.5f)); verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), Color.LightGray * 0.8f));//new Color(n,(n*2)%255,(n*3)%255)*0.5f));
} }
//bool isSame = false; //bool isSame = false;
@@ -492,10 +493,9 @@ namespace Subsurface
//todo: make sure the first point is the one where the edge should start from //todo: make sure the first point is the one where the edge should start from
bodyPoints.Sort(new CompareCCW(cell.Center)); bodyPoints.Sort(new CompareCCW(cell.Center));
if (bodyPoints.Count == tempVertices.Count) //if (bodyPoints.Count == tempVertices.Count)
{ //{
//}
}
for (int i = 0; i < bodyPoints.Count; i++) for (int i = 0; i < bodyPoints.Count; i++)
{ {
@@ -627,7 +627,7 @@ namespace Subsurface
avgPos += cell.body.Position; avgPos += cell.body.Position;
} }
System.Diagnostics.Debug.WriteLine("avgpos: "+avgPos / cells.Count); System.Diagnostics.Debug.WriteLine("avgpos: " + avgPos / cells.Count);
System.Diagnostics.Debug.WriteLine("pos: " + Position); System.Diagnostics.Debug.WriteLine("pos: " + Position);
} }
@@ -636,8 +636,8 @@ namespace Subsurface
public void SetObserverPosition(Vector2 position) public void SetObserverPosition(Vector2 position)
{ {
observerPosition = position - this.Position; observerPosition = position - this.Position;
int gridPosX = (int)Math.Floor(observerPosition.X / gridCellWidth); int gridPosX = (int)Math.Floor(observerPosition.X / GridCellWidth);
int gridPosY = (int)Math.Floor(observerPosition.Y / gridCellWidth); int gridPosY = (int)Math.Floor(observerPosition.Y / GridCellWidth);
int searchOffset = 2; int searchOffset = 2;
int startX = Math.Max(gridPosX - searchOffset, 0); int startX = Math.Max(gridPosX - searchOffset, 0);
@@ -706,14 +706,14 @@ namespace Subsurface
foreach (VoronoiCell cell in cells) foreach (VoronoiCell cell in cells)
{ {
for (int i = 0; i < cell.bodyVertices.Count-1; i++) for (int i = 0; i < cell.bodyVertices.Count - 1; i++)
{ {
Vector2 start = cell.bodyVertices[i]; Vector2 start = cell.bodyVertices[i];
start.X += Position.X; start.X += Position.X;
start.Y = -start.Y - Position.Y; start.Y = -start.Y - Position.Y;
start.X += Rand.Range(-10.0f, 10.0f); start.X += Rand.Range(-10.0f, 10.0f);
Vector2 end = cell.bodyVertices[i+1]; Vector2 end = cell.bodyVertices[i + 1];
end.X += Position.X; end.X += Position.X;
end.Y = -end.Y - Position.Y; end.Y = -end.Y - Position.Y;
end.X += Rand.Range(-10.0f, 10.0f); end.X += Rand.Range(-10.0f, 10.0f);
@@ -726,8 +726,8 @@ namespace Subsurface
public List<Vector2[]> GetCellEdges(Vector2 refPos, int searchDepth = 2, bool onlySolid = true) public List<Vector2[]> GetCellEdges(Vector2 refPos, int searchDepth = 2, bool onlySolid = true)
{ {
int gridPosX = (int)Math.Floor(refPos.X / gridCellWidth); int gridPosX = (int)Math.Floor(refPos.X / GridCellWidth);
int gridPosY = (int)Math.Floor(refPos.Y / gridCellWidth); int gridPosY = (int)Math.Floor(refPos.Y / GridCellWidth);
int startX = Math.Max(gridPosX - searchDepth, 0); int startX = Math.Max(gridPosX - searchDepth, 0);
int endX = Math.Min(gridPosX + searchDepth, cellGrid.GetLength(0) - 1); int endX = Math.Min(gridPosX + searchDepth, cellGrid.GetLength(0) - 1);
@@ -742,7 +742,7 @@ namespace Subsurface
{ {
for (int y = startY; y < endY; y++) for (int y = startY; y < endY; y++)
{ {
foreach (VoronoiCell cell in cellGrid[x,y]) foreach (VoronoiCell cell in cellGrid[x, y])
{ {
for (int i = 0; i < cell.edges.Count; i++) for (int i = 0; i < cell.edges.Count; i++)
{ {
@@ -768,7 +768,7 @@ namespace Subsurface
if (vertices == null) return; if (vertices == null) return;
if (vertices.Length <= 0) return; if (vertices.Length <= 0) return;
basicEffect.World = Matrix.CreateTranslation(new Vector3(Position, 0.0f))*cam.ShaderTransform basicEffect.World = Matrix.CreateTranslation(new Vector3(Position, 0.0f)) * cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f; * Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
@@ -800,6 +800,7 @@ namespace Subsurface
vertexBuffer.Dispose(); vertexBuffer.Dispose();
vertexBuffer = null; vertexBuffer = null;
} }
} }
} }
+63 -17
View File
@@ -5,6 +5,7 @@ using FarseerPhysics.Common.Decomposition;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts; using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Factories; using FarseerPhysics.Factories;
using Lidgren.Network;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
@@ -22,14 +23,14 @@ namespace Subsurface
None = 0, Left = 1, Right = 2 None = 0, Left = 1, Right = 2
} }
class Submarine class Submarine : Entity
{ {
public static List<Submarine> SavedSubmarines = new List<Submarine>(); public static List<Submarine> SavedSubmarines = new List<Submarine>();
private static Submarine loaded;
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f); public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
private static Submarine loaded;
private static Vector2 lastPickedPosition; private static Vector2 lastPickedPosition;
private static float lastPickedFraction; private static float lastPickedFraction;
@@ -38,6 +39,9 @@ namespace Subsurface
Vector2 speed; Vector2 speed;
Vector2 targetPosition;
Vector2 targetSpeed;
private Rectangle borders; private Rectangle borders;
private Body hullBody; private Body hullBody;
@@ -45,6 +49,10 @@ namespace Subsurface
private string filePath; private string filePath;
private string name; private string name;
private double lastNetworkUpdate;
//properties ---------------------------------------------------- //properties ----------------------------------------------------
public string Name public string Name
@@ -99,6 +107,11 @@ namespace Subsurface
get { return new Vector2(borders.X+borders.Width/2, borders.Y - borders.Height/2); } get { return new Vector2(borders.X+borders.Width/2, borders.Y - borders.Height/2); }
} }
public Vector2 Position
{
get { return (Level.Loaded==null) ? Vector2.Zero : -Level.Loaded.Position; }
}
public string FilePath public string FilePath
{ {
get { return filePath; } get { return filePath; }
@@ -392,19 +405,30 @@ namespace Subsurface
public void Update(float deltaTime) public void Update(float deltaTime)
{ {
Translate(ConvertUnits.ToDisplayUnits(hullBody.Position) * collisionRigidness + speed * deltaTime); Vector2 translateAmount = speed * deltaTime;
translateAmount += ConvertUnits.ToDisplayUnits(hullBody.Position) * collisionRigidness;
if (targetPosition != Vector2.Zero && Vector2.Distance(targetPosition, Position) > 5.0f)
{
translateAmount += (targetPosition - Position)*0.1f;
}
else
{
targetPosition = Vector2.Zero;
}
CalculateBuoyancy(); Translate(translateAmount);
ApplyForce(CalculateBuoyancy());
float dragCoefficient = 0.00001f; float dragCoefficient = 0.00001f;
float speedLength = speed.Length(); float speedLength = speed.Length();
float drag = speedLength * speedLength * dragCoefficient * mass; float drag = speedLength * speedLength * dragCoefficient * mass;
System.Diagnostics.Debug.WriteLine("speed: "+speed);
if (speed!=Vector2.Zero) if (speed != Vector2.Zero)
{ {
ApplyForce(-Vector2.Normalize(speed)*drag); ApplyForce(-Vector2.Normalize(speed) * drag);
} }
//hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position; //hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position;
@@ -439,7 +463,7 @@ namespace Subsurface
} }
private void CalculateBuoyancy() private Vector2 CalculateBuoyancy()
{ {
float waterVolume = 0.0f; float waterVolume = 0.0f;
float volume = 0.0f; float volume = 0.0f;
@@ -456,7 +480,7 @@ namespace Subsurface
float buoyancy = neutralPercentage-waterPercentage; float buoyancy = neutralPercentage-waterPercentage;
buoyancy *= mass * 10.0f; buoyancy *= mass * 10.0f;
ApplyForce(new Vector2(0.0f, buoyancy)); return new Vector2(0.0f, buoyancy);
} }
public void SetPosition(Vector2 position) public void SetPosition(Vector2 position)
@@ -510,6 +534,34 @@ namespace Subsurface
collidingCell = null; collidingCell = null;
} }
public override void FillNetworkData(Networking.NetworkEventType type, NetOutgoingMessage message, object data)
{
message.Write(NetTime.Now);
message.Write(Position.X);
message.Write(Position.Y);
}
public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message)
{
double sendingTime = message.ReadDouble();
if (sendingTime <= lastNetworkUpdate) return;
Vector2 newPosition = new Vector2(message.ReadFloat(), message.ReadFloat());
if (newPosition == Position) return;
if ((newPosition - Position).Length() > 500.0f)
{
System.Diagnostics.Debug.WriteLine("Submarine has moved over 500 pixels since last update");
return;
}
targetPosition = Position;
lastNetworkUpdate = sendingTime;
}
//saving/loading ---------------------------------------------------- //saving/loading ----------------------------------------------------
@@ -553,7 +605,7 @@ namespace Subsurface
if (loaded==null) if (loaded==null)
{ {
loaded = new Submarine(savePath); loaded = new Submarine(savePath);
return; // return;
} }
loaded.SaveAs(savePath); loaded.SaveAs(savePath);
@@ -768,7 +820,6 @@ namespace Subsurface
sub.Load(); sub.Load();
return sub; return sub;
} }
public static void Unload() public static void Unload()
@@ -793,9 +844,4 @@ namespace Subsurface
} }
//class HullBody
//{
// public Body body;
// //public Texture2D shapeTexture;
//}
} }
+2 -2
View File
@@ -187,7 +187,7 @@ namespace Subsurface
{ {
GUITextBlock textBlock = new GUITextBlock( GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), new Rectangle(0, 0, 0, 25),
c.Name, GUI.style, c.Name + " ("+c.Job.Name+")", GUI.style,
Alignment.Left, Alignment.Left,
Alignment.Left, Alignment.Left,
characterList); characterList);
@@ -205,7 +205,7 @@ namespace Subsurface
GUITextBlock textBlock = new GUITextBlock( GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), new Rectangle(0, 0, 0, 25),
c.Name, c.Name + " (" + c.Job.Name + ")",
Color.Transparent, Color.Black, Color.Transparent, Color.Black,
Alignment.Left, null, frame); Alignment.Left, null, frame);
+18 -6
View File
@@ -10,15 +10,15 @@ namespace Subsurface
{ {
enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3 } enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3 }
GUIFrame[] menuTabs; private GUIFrame[] menuTabs;
GUIListBox mapList; private GUIListBox mapList;
GUIListBox saveList; private GUIListBox saveList;
GUITextBox nameBox; private GUITextBox nameBox;
GUITextBox ipBox; private GUITextBox ipBox;
Game1 game; private Game1 game;
int selectedTab; int selectedTab;
@@ -87,6 +87,18 @@ namespace Subsurface
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", Color.Transparent, Color.Black, Alignment.CenterX, null, menuTabs[(int)Tabs.LoadGame]); new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", Color.Transparent, Color.Black, Alignment.CenterX, null, menuTabs[(int)Tabs.LoadGame]);
if (!Directory.Exists(SaveUtil.SaveFolder))
{
DebugConsole.ThrowError("Save folder ''"+SaveUtil.SaveFolder+" not found! Attempting to create a new folder");
try
{
Directory.CreateDirectory(SaveUtil.SaveFolder);
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to create the folder ''"+SaveUtil.SaveFolder+"''!", e);
}
}
string[] saveFiles = Directory.GetFiles(SaveUtil.SaveFolder, "*.save"); string[] saveFiles = Directory.GetFiles(SaveUtil.SaveFolder, "*.save");
+1 -1
View File
@@ -227,7 +227,7 @@ namespace Subsurface
GUIListBox jobList = new GUIListBox(new Rectangle(0,180,200,0), GUI.style, playerFrame); GUIListBox jobList = new GUIListBox(new Rectangle(0,180,200,0), GUI.style, playerFrame);
foreach (Job job in Job.jobList) foreach (JobPrefab job in JobPrefab.List)
{ {
GUITextBlock jobText = new GUITextBlock(new Rectangle(0,0,0,20), job.Name, GUI.style, jobList); GUITextBlock jobText = new GUITextBlock(new Rectangle(0,0,0,20), job.Name, GUI.style, jobList);
GUIButton upButton = new GUIButton(new Rectangle(jobText.Rect.Width - 40, 0, 20, 20), "u", GUI.style, jobText); GUIButton upButton = new GUIButton(new Rectangle(jobText.Rect.Width - 40, 0, 20, 20), "u", GUI.style, jobText);
+5 -4
View File
@@ -61,6 +61,7 @@
<Compile Include="Characters\DelayedEffect.cs" /> <Compile Include="Characters\DelayedEffect.cs" />
<Compile Include="Characters\Job.cs" /> <Compile Include="Characters\Job.cs" />
<Compile Include="Characters\Jobs\Job.cs" /> <Compile Include="Characters\Jobs\Job.cs" />
<Compile Include="Characters\Jobs\JobPrefab.cs" />
<Compile Include="Characters\AI\SteeringManager.cs" /> <Compile Include="Characters\AI\SteeringManager.cs" />
<Compile Include="Characters\AI\SteeringPath.cs" /> <Compile Include="Characters\AI\SteeringPath.cs" />
<Compile Include="Rand.cs" /> <Compile Include="Rand.cs" />
@@ -197,6 +198,10 @@
<Compile Include="Map\Hull.cs" /> <Compile Include="Map\Hull.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="FarseerPhysics MonoGame, Version=3.5.0.30657, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Windows\Debug\FarseerPhysics MonoGame.dll</HintPath>
</Reference>
<Reference Include="Lidgren.Network, Version=3.3.0.2069, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Lidgren.Network, Version=3.3.0.2069, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>.\Lidgren.Network.dll</HintPath> <HintPath>.\Lidgren.Network.dll</HintPath>
@@ -715,10 +720,6 @@
<Folder Include="Data\Saves\" /> <Folder Include="Data\Saves\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Lataukset\Selain-lataukset\Farseer Physics Engine 3.5\Farseer Physics Engine 3.5\Farseer Physics MonoGame.csproj">
<Project>{0aad36e3-51a5-4a07-ab60-5c8a66bd38b7}</Project>
<Name>Farseer Physics MonoGame</Name>
</ProjectReference>
<ProjectReference Include="..\Subsurface_content\Subsurface_content\Subsurface_content.csproj"> <ProjectReference Include="..\Subsurface_content\Subsurface_content\Subsurface_content.csproj">
<Project>{1e6bf44d-6e31-40cc-8321-3d5958c983e7}</Project> <Project>{1e6bf44d-6e31-40cc-8321-3d5958c983e7}</Project>
<Name>Subsurface_content</Name> <Name>Subsurface_content</Name>
+1 -1
View File
@@ -9,6 +9,6 @@
<ErrorReportUrlHistory /> <ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture> <FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ProjectFiles</ProjectView> <ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
Binary file not shown.