Quests, new sounds, explosives, bugfixes, asdfasdf

This commit is contained in:
Regalis
2015-07-29 23:40:26 +03:00
parent 7155f1cef0
commit 5d0a453e23
81 changed files with 1374 additions and 819 deletions
+50 -17
View File
@@ -1,5 +1,6 @@
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Subsurface.Lights;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -8,29 +9,34 @@ namespace Subsurface
{
class Explosion
{
Vector2 position;
private Vector2 position;
private float range;
private float damage;
private float structureDamage;
private float stun;
float range;
float damage;
float structureDamage;
float stun;
private float force;
float force;
private LightSource light;
public Explosion(Vector2 position, float range, float damage, float structureDamage, float stun=0.0f, float force=0.0f)
public float CameraShake;
public Explosion(Vector2 position, float range, float damage, float structureDamage, float stun = 0.0f, float force = 0.0f)
{
this.position = position;
this.range = Math.Max(range,1.0f);
this.range = Math.Max(range, 1.0f);
this.damage = damage;
this.structureDamage = structureDamage;
this.stun = stun;
this.force = force;
CameraShake = range*10.0f;
}
public Explosion(XElement element)
{
range = Math.Max(ToolBox.GetAttributeFloat(element, "range", 1.0f),1.0f);
range = Math.Max(ToolBox.GetAttributeFloat(element, "range", 1.0f), 1.0f);
damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f);
structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f);
stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f);
@@ -43,18 +49,25 @@ namespace Subsurface
Explode(position);
}
public void Explode(Vector2 position)
public void Explode(Vector2 simPosition)
{
for (int i = 0; i<range*10; i++)
for (int i = 0; i < range * 10; i++)
{
Game1.particleManager.CreateParticle("explosionfire", position,
Game1.ParticleManager.CreateParticle("explosionfire", simPosition,
Rand.Vector(Rand.Range(3.0f, 4.0f)), 0.0f);
}
Vector2 displayPosition = ConvertUnits.ToDisplayUnits(position);
Vector2 displayPosition = ConvertUnits.ToDisplayUnits(simPosition);
float displayRange = ConvertUnits.ToDisplayUnits(range);
if (structureDamage>0.0f)
light = new LightSource(displayPosition, displayRange, Color.LightYellow);
CoroutineManager.StartCoroutine(DimLight());
float cameraDist = Vector2.Distance(Game1.GameScreen.Cam.Position, displayPosition)/2.0f;
Game1.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist)/displayRange, 0.0f);
if (structureDamage > 0.0f)
{
List<Structure> structureList = new List<Structure>();
@@ -84,7 +97,7 @@ namespace Subsurface
foreach (Character c in Character.CharacterList)
{
float dist = Vector2.Distance(c.SimPosition, position);
float dist = Vector2.Distance(c.SimPosition, simPosition);
if (dist > range) continue;
@@ -92,16 +105,36 @@ namespace Subsurface
foreach (Limb limb in c.AnimController.limbs)
{
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, position)/range;
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/range;
c.AddDamage(limb.SimPosition, DamageType.None, damage / c.AnimController.limbs.Length * distFactor, 0.0f, stun * distFactor);
if (force>0.0f)
{
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition-position)*distFactor*force);
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force);
}
}
}
}
private IEnumerable<Status> DimLight()
{
float currBrightness= 1.0f;
float startRange = light.Range;
while (light.Color.A > 0.0f)
{
light.Color = new Color(light.Color.R, light.Color.G, light.Color.B, currBrightness);
light.Range = startRange * currBrightness;
currBrightness -= 0.1f;
yield return Status.Running;
}
light.Remove();
yield return Status.Success;
}
}
}
+4 -4
View File
@@ -249,12 +249,12 @@ namespace Subsurface
{
pos.Y = ConvertUnits.ToSimUnits(MathHelper.Clamp(lowerSurface, rect.Y-rect.Height, rect.Y));
Game1.particleManager.CreateParticle("watersplash",
Game1.ParticleManager.CreateParticle("watersplash",
new Vector2(pos.X, pos.Y - Rand.Range(0.0f, 0.1f)),
new Vector2(flowForce.X * Rand.Range(0.005f, 0.007f), flowForce.Y * Rand.Range(0.005f, 0.007f)));
pos.Y = ConvertUnits.ToSimUnits(Rand.Range(lowerSurface, rect.Y - rect.Height));
Game1.particleManager.CreateParticle("bubbles", pos, flowForce / 200.0f);
Game1.ParticleManager.CreateParticle("bubbles", pos, flowForce / 200.0f);
}
else
{
@@ -262,12 +262,12 @@ namespace Subsurface
for (int i = 0; i < rect.Width; i += (int)Rand.Range(80, 100))
{
pos.X = ConvertUnits.ToSimUnits(Rand.Range(rect.X, rect.X+rect.Width));
Subsurface.Particles.Particle splash = Game1.particleManager.CreateParticle("watersplash", pos,
Subsurface.Particles.Particle splash = Game1.ParticleManager.CreateParticle("watersplash", pos,
new Vector2(flowForce.X * Rand.Range(0.005f, 0.008f), flowForce.Y * Rand.Range(0.005f, 0.008f)));
if (splash!=null) splash.Size = splash.Size * MathHelper.Clamp(rect.Width / 50.0f, 0.8f, 4.0f);
Game1.particleManager.CreateParticle("bubbles", pos, flowForce / 200.0f);
Game1.ParticleManager.CreateParticle("bubbles", pos, flowForce / 200.0f);
}
}
+1 -1
View File
@@ -210,7 +210,7 @@ namespace Subsurface
float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
if (maxDelta > Rand.Range(0.2f,10.0f))
{
Game1.particleManager.CreateParticle("mist",
Game1.ParticleManager.CreateParticle("mist",
ConvertUnits.ToSimUnits(new Vector2(rect.X + WaveWidth * i,surface + waveY[i])),
new Vector2(0.0f, -0.5f));
}
+59 -39
View File
@@ -38,9 +38,9 @@ namespace Subsurface
//List<Body> bodies;
private List<VoronoiCell> cells;
private BasicEffect basicEffect;
private static BasicEffect basicEffect;
private VertexPositionColor[] vertices;
private VertexPositionTexture[] vertices;
private VertexBuffer vertexBuffer;
private Vector2 startPosition;
@@ -50,6 +50,8 @@ namespace Subsurface
private List<Body> bodies = new List<Body>();
private List<Vector2> positionsOfInterest;
public Vector2 StartPosition
{
get { return startPosition; }
@@ -77,6 +79,11 @@ namespace Subsurface
get { return ConvertUnits.ToDisplayUnits(cells[0].body.Position); }
}
public List<Vector2> PositionsOfInterest
{
get { return positionsOfInterest; }
}
public string Seed
{
get { return seed; }
@@ -92,12 +99,24 @@ namespace Subsurface
{
if (shaftTexture == null) shaftTexture = Game1.TextureLoader.FromFile("Content/Map/shaft.png");
if (basicEffect==null)
{
basicEffect = new BasicEffect(Game1.CurrGraphicsDevice);
basicEffect.VertexColorEnabled = false;
basicEffect.TextureEnabled = true;
basicEffect.Texture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png");
}
this.seed = seed;
this.siteInterval = siteInterval;
this.Difficulty = difficulty;
positionsOfInterest = new List<Vector2>();
borders = new Rectangle(0, 0, width, height);
}
@@ -237,7 +256,7 @@ namespace Subsurface
endPosition = pathCells[pathCells.Count - 1].Center;
//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(
//borders.X + siteInterval * 2, borders.Y - siteInterval * 2,
@@ -252,10 +271,14 @@ namespace Subsurface
Vector2 end = new Vector2(x, y);
pathCells.AddRange
(
GeneratePath(rand, new List<Vector2> { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror)
);
var newPathCells = GeneratePath(rand, new List<Vector2> { start, end }, cells, pathBorders, 0.0f, 0.8f, mirror);
for (int n = 1; n < newPathCells.Count; n += 3)
{
positionsOfInterest.Add(newPathCells[n].Center);
}
pathCells.AddRange(newPathCells);
}
Debug.WriteLine("path: " + sw2.ElapsedMilliseconds + " ms");
@@ -329,13 +352,9 @@ namespace Subsurface
Debug.WriteLine("Generatelevel: " + sw2.ElapsedMilliseconds + " ms");
sw2.Restart();
vertexBuffer = new VertexBuffer(Game1.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
vertexBuffer = new VertexBuffer(Game1.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
vertexBuffer.SetData(vertices);
basicEffect = new BasicEffect(Game1.CurrGraphicsDevice);
basicEffect.VertexColorEnabled = true;
if (mirror)
{
Vector2 temp = startPosition;
@@ -555,7 +574,7 @@ int currentTargetIndex = 1;
private void GeneratePolygons(List<VoronoiCell> cells, List<VoronoiCell> emptyCells)
{
List<VertexPositionColor> verticeList = new List<VertexPositionColor>();
List<VertexPositionTexture> verticeList = new List<VertexPositionTexture>();
//bodies = new List<Body>();
List<Vector2> tempVertices = new List<Vector2>();
@@ -593,7 +612,7 @@ int currentTargetIndex = 1;
{
foreach (Vector2 vertex in triangles[i])
{
verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), new Color(n*30, (n * 60) % 255, (n * 90) % 255) * 0.5f));
verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 0.0f), vertex/1000.0f));
}
}
@@ -775,31 +794,31 @@ int currentTargetIndex = 1;
Vector2 observerPosition;
public void SetObserverPosition(Vector2 position)
{
observerPosition = position - this.Position;
int gridPosX = (int)Math.Floor(observerPosition.X / GridCellWidth);
int gridPosY = (int)Math.Floor(observerPosition.Y / GridCellWidth);
int searchOffset = 2;
//observerPosition = position - this.Position;
//int gridPosX = (int)Math.Floor(observerPosition.X / GridCellWidth);
//int gridPosY = (int)Math.Floor(observerPosition.Y / GridCellWidth);
//int searchOffset = 2;
int startX = Math.Max(gridPosX - searchOffset, 0);
int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1);
//int startX = Math.Max(gridPosX - searchOffset, 0);
//int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1);
int startY = Math.Max(gridPosY - searchOffset, 0);
int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1);
//int startY = Math.Max(gridPosY - searchOffset, 0);
//int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1);
for (int x = 0; x < cellGrid.GetLength(0); x++)
{
for (int y = 0; y < cellGrid.GetLength(1); y++)
{
for (int i = 0; i < cellGrid[x, y].Count; i++)
{
//foreach (Body b in cellGrid[x, y][i].bodies)
//{
if (cellGrid[x, y][i].body == null) continue;
cellGrid[x, y][i].body.Enabled = true;// (x >= startX && x <= endX && y >= startY && y <= endY);
//}
}
}
}
//for (int x = 0; x < cellGrid.GetLength(0); x++)
//{
// for (int y = 0; y < cellGrid.GetLength(1); y++)
// {
// for (int i = 0; i < cellGrid[x, y].Count; i++)
// {
// //foreach (Body b in cellGrid[x, y][i].bodies)
// //{
// if (cellGrid[x, y][i].body == null) continue;
// cellGrid[x, y][i].body.Enabled = true;// (x >= startX && x <= endX && y >= startY && y <= endY);
// //}
// }
// }
//}
}
@@ -897,11 +916,12 @@ int currentTargetIndex = 1;
basicEffect.World = Matrix.CreateTranslation(new Vector3(Position, 0.0f)) * cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
basicEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, (int)Math.Floor(vertices.Length / 3.0f));
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, (int)Math.Floor(vertices.Length / 3.0f));
}
private void Unload()
+15 -23
View File
@@ -8,7 +8,7 @@ namespace Subsurface.Lights
class ConvexHull
{
public static List<ConvexHull> list = new List<ConvexHull>();
static BasicEffect fowEffect;
static BasicEffect losEffect;
static BasicEffect shadowEffect;
private VertexPositionColor[] vertices;
@@ -87,14 +87,14 @@ namespace Subsurface.Lights
// }
//}
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, bool fow = true)
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, bool los = true)
{
if (!Enabled) return;
if (fowEffect == null)
if (losEffect == null)
{
fowEffect = new BasicEffect(graphicsDevice);
fowEffect.VertexColorEnabled = true;
losEffect = new BasicEffect(graphicsDevice);
losEffect.VertexColorEnabled = true;
}
if (shadowEffect==null)
{
@@ -140,7 +140,7 @@ namespace Subsurface.Lights
VertexPositionTexture[] penumbraVertices = new VertexPositionTexture[6];
if (fow)
if (los)
{
for (int n = 0; n < 4; n+=3)
{
@@ -162,26 +162,18 @@ namespace Subsurface.Lights
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
vertexDir.Normalize();
penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000;
if (i==0)
{
//penumbraVertices[n].Position -= normal*2.0f;
}
if (fow)
if (los)
{
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
}
else
{
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f):Vector2.Zero;
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero;
}
//penumbraVertices[i+1].Color = Color.Black;
}
if (n>0)
if (n > 0)
{
var temp = penumbraVertices[4];
penumbraVertices[4] = penumbraVertices[5];
@@ -210,12 +202,12 @@ namespace Subsurface.Lights
//one vertex on the hull
shadowVertices[svCount] = new VertexPositionColor();
shadowVertices[svCount].Color = fow ? Color.Black : Color.Transparent;
shadowVertices[svCount].Color = los ? Color.Black : Color.Transparent;
shadowVertices[svCount].Position = vertexPos;
//one extruded by the light direction
shadowVertices[svCount + 1] = new VertexPositionColor();
shadowVertices[svCount + 1].Color = fow ? Color.Black : Color.Transparent;
shadowVertices[svCount + 1].Color = los ? Color.Black : Color.Transparent;
Vector3 L2P = vertexPos - new Vector3(lightSourcePos, 0);
L2P.Normalize();
shadowVertices[svCount + 1].Position = new Vector3(lightSourcePos, 0) + L2P * 9000;
@@ -224,13 +216,13 @@ namespace Subsurface.Lights
currentIndex = (currentIndex + 1) % primitiveCount;
}
fowEffect.World = cam.ShaderTransform
losEffect.World = cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
fowEffect.CurrentTechnique.Passes[0].Apply();
losEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
if (fow)
if (los)
{
shadowEffect.World = cam.ShaderTransform
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
+3 -3
View File
@@ -16,7 +16,7 @@ namespace Subsurface.Lights
private List<LightSource> lights;
public bool FowEnabled = true;
public bool LosEnabled = true;
public bool LightingEnabled = true;
@@ -54,9 +54,9 @@ namespace Subsurface.Lights
lights.Remove(light);
}
public void DrawFow(GraphicsDevice graphics, Camera cam, Vector2 pos)
public void DrawLOS(GraphicsDevice graphics, Camera cam, Vector2 pos)
{
if (!FowEnabled) return;
if (!LosEnabled) return;
foreach (ConvexHull convexHull in ConvexHull.list)
{
convexHull.DrawShadows(graphics, cam, pos);
+38 -11
View File
@@ -19,7 +19,7 @@ namespace Subsurface
private List<LocationConnection> connections;
private int seed;
private string seed;
private int size;
private static Sprite iceTexture;
@@ -29,6 +29,8 @@ namespace Subsurface
private Location currentLocation;
private Location selectedLocation;
private LocationConnection selectedConnection;
public Location CurrentLocation
{
get { return currentLocation; }
@@ -44,12 +46,17 @@ namespace Subsurface
get { return selectedLocation; }
}
public int Seed
public LocationConnection SelectedConnection
{
get { return selectedConnection; }
}
public string Seed
{
get { return seed; }
}
public Map(int seed, int size)
public Map(string seed, int size)
{
this.seed = seed;
@@ -65,7 +72,7 @@ namespace Subsurface
if (iceCraters == null) iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png");
if (iceCrack == null) iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png");
Rand.SetSyncedSeed(this.seed);
Rand.SetSyncedSeed(this.seed.GetHashCode());
GenerateLocations();
@@ -288,9 +295,9 @@ namespace Subsurface
if (PlayerInput.LeftButtonClicked()&&
selectedLocation != highlightedLocation && highlightedLocation != null)
{
//currentLocation = highlightedLocation;
Game1.LobbyScreen.SelectLocation(highlightedLocation, connection);
selectedLocation = highlightedLocation;
selectedConnection = connection;
selectedLocation = highlightedLocation;
Game1.LobbyScreen.SelectLocation(highlightedLocation, connection);
}
}
@@ -368,14 +375,34 @@ namespace Subsurface
private Level level;
public float Difficulty;
public List<Vector2[]> CrackSegments;
private int questsCompleted;
private Quest quest;
public Quest Quest
{
get
{
if (quest==null || quest.Completed)
{
if (quest !=null && quest.Completed) questsCompleted++;
Random rand = new Random(GetHashCode() + questsCompleted);
quest = Quest.LoadRandom(rand);
}
return quest;
}
}
public Location[] Locations
{
get { return locations; }
}
public Level Level
{
get { return level; }
@@ -385,8 +412,8 @@ namespace Subsurface
public LocationConnection(Location location1, Location location2)
{
locations = new Location[] { location1, location2 };
//location1.connections.Add(this);
//location2.connections.Add(this);
questsCompleted = 0;
}
public Location OtherLocation(Location location)
+2 -4
View File
@@ -371,8 +371,6 @@ namespace Subsurface
if (Game1.Client==null)
SetDamage(sectionIndex, sections[sectionIndex].damage + damage);
}
public int FindSectionIndex(Vector2 pos)
@@ -408,9 +406,9 @@ namespace Subsurface
int i = FindSectionIndex(ConvertUnits.ToDisplayUnits(position));
if (i == -1) return new AttackResult(0.0f, 0.0f);
Game1.particleManager.CreateParticle("dustcloud", ConvertUnits.ToSimUnits(SectionPosition(i)), 0.0f, 0.0f);
Game1.ParticleManager.CreateParticle("dustcloud", ConvertUnits.ToSimUnits(SectionPosition(i)), 0.0f, 0.0f);
if (playSound)
if (playSound && !SectionHasHole(i))
{
DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash;
AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position);
+1
View File
@@ -8,6 +8,7 @@ using FarseerPhysics.Factories;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Items.Components;
using System;
using System.Collections.Generic;
using System.IO;