Improved map rendering, shops, light bugfix, junction boxes wont break as easily

This commit is contained in:
Regalis
2015-07-27 23:45:20 +03:00
parent 4238301ad3
commit 7155f1cef0
37 changed files with 472 additions and 300 deletions

View File

@@ -32,15 +32,15 @@ namespace Subsurface
public readonly Dictionary<string, PropertyDescriptor> properties;
float lethalPressure;
private float lethalPressure;
float surface;
float volume;
float pressure;
private float surface;
private float volume;
private float pressure;
float oxygen;
private float oxygen;
bool update;
private bool update;
float[] waveY; //displacement from the surface of the water
float[] waveVel; //velocity of the point

View File

@@ -300,6 +300,7 @@ namespace Subsurface
for (int n = -1; n < 2; n += 2)
{
int cellIndex = FindCellIndex(new Vector2(tunnelStart.X + minWidth * 0.5f * n, tunnelStart.Y), 3);
foreach (GraphEdge ge in cells[cellIndex].edges)
{
if (ge.point1.Y > cells[cellIndex].Center.Y) ge.point1.Y = borders.Height + shaftHeight;

View File

@@ -57,5 +57,10 @@ namespace Subsurface.Lights
float scale = range / ((float)lightTexture.Width / 2.0f);
spriteBatch.Draw(lightTexture, new Vector2(Position.X, -Position.Y), null, color, 0, center, scale, SpriteEffects.None, 1);
}
public void Remove()
{
Game1.LightManager.RemoveLight(this);
}
}
}

View File

@@ -76,13 +76,11 @@ namespace Subsurface.Lights
foreach (LightSource light in lights)
{
if (light.Color.A < 0.01f || light.Range < 0.01f) continue;
if (!MathUtils.CircleIntersectsRectangle(light.Position, light.Range, viewRect)) continue;
//clear alpha to 1
ClearAlphaToOne(graphics, spriteBatch);
ClearAlphaToOne(graphics, spriteBatch);
if (!MathUtils.CircleIntersectsRectangle(light.Position, light.Range, viewRect)) continue;
//draw all shadows
//write only to the alpha channel, which sets alpha to 0
graphics.RasterizerState = RasterizerState.CullNone;

View File

@@ -29,6 +29,7 @@ namespace Subsurface
get { return mapPosition; }
}
public bool Discovered;
public LocationType Type
{

View File

@@ -19,6 +19,8 @@ namespace Subsurface
private List<string> nameFormats;
private Sprite sprite;
public bool HasHireableCharacters
{
get;
@@ -35,6 +37,11 @@ namespace Subsurface
get { return nameFormats; }
}
public Sprite Sprite
{
get { return sprite; }
}
private LocationType(XElement element)
{
name = element.Name.ToString();
@@ -49,6 +56,10 @@ namespace Subsurface
{
nameFormats.Add(nameFormat.Value.ToString());
}
string spritePath = ToolBox.GetAttributeString(element, "symbol", "Content/Map/beaconSymbol.png");
sprite = new Sprite(spritePath, null, new Microsoft.Xna.Framework.Vector2(-32, -32));
}
public static LocationType Random()

View File

@@ -22,7 +22,7 @@ namespace Subsurface
private int seed;
private int size;
private static Texture2D iceTexture;
private static Sprite iceTexture;
private static Texture2D iceCraters;
private static Texture2D iceCrack;
@@ -61,7 +61,7 @@ namespace Subsurface
connections = new List<LocationConnection>();
if (iceTexture==null) iceTexture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png");
if (iceTexture==null) iceTexture = new Sprite("Content/Map/iceSurface.png", Vector2.Zero);
if (iceCraters == null) iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png");
if (iceCrack == null) iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png");
@@ -244,14 +244,18 @@ namespace Subsurface
}
private Location highlightedLocation;
public void Draw(SpriteBatch spriteBatch, Rectangle rect)
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f)
{
//GUI.DrawRectangle(spriteBatch, rect, Color.DarkBlue, true);
spriteBatch.Draw(iceTexture, rect, Color.White);
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
Vector2 offset = -currentLocation.MapPosition;
Vector2 rectCorner = new Vector2(rect.X, rect.Y);
Vector2 scale = new Vector2((float)rect.Width/ size, (float)rect.Height/size);
iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), offset, Color.White);
//spriteBatch.Draw(iceTexture, offset, rect, null, null, 0f, null, Color.White, SpriteEffects.None, 0.0f);
//Vector2 scale = new Vector2((float)rect.Width/ size, (float)rect.Height/size);
float maxDist = 20.0f;
float closestDist = 0.0f;
@@ -259,9 +263,11 @@ namespace Subsurface
for (int i = 0; i < locations.Count;i++ )
{
Location location = locations[i];
Vector2 pos = rectCorner + location.MapPosition * scale;
Vector2 pos = rectCenter + (location.MapPosition+offset) * scale;
float dist = Vector2.Distance(PlayerInput.MousePosition, new Vector2(pos.X, pos.Y));
if (!rect.Contains(pos)) continue;
float dist = Vector2.Distance(PlayerInput.MousePosition, pos);
if (dist < maxDist && (highlightedLocation == null || dist < closestDist))
{
closestDist = dist;
@@ -272,7 +278,7 @@ namespace Subsurface
foreach (LocationConnection connection in connections)
{
Color crackColor = Color.Lerp(Color.LightGreen, Color.DarkRed, connection.Difficulty/100.0f);
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 0.5f);
if (highlightedLocation != currentLocation &&
connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
@@ -297,32 +303,42 @@ namespace Subsurface
foreach (Vector2[] segment in connection.CrackSegments)
{
Vector2 start = segment[0] * scale + rectCorner;
Vector2 end = segment[1] * scale + rectCorner;
Vector2 start = rectCenter + (segment[0] + offset) * scale;
Vector2 end = rectCenter + (segment[1] + offset) * scale;
if (!rect.Contains(start) || !rect.Contains(end)) continue;
float dist = Vector2.Distance(start, end);
//spriteBatch.Draw(iceCrack,
// new Rectangle((int)((start.X + end.X) / 2.0f), (int)((start.Y + end.Y) / 2.0f), (int)dist, 30),
// new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(start - end),
// new Vector2(dist / 2, 30), SpriteEffects.None, 0.01f);
GUI.DrawLine(spriteBatch,
segment[0] * scale + rectCorner,
segment[1] * scale + rectCorner, crackColor);
spriteBatch.Draw(iceCrack,
new Rectangle((int)start.X, (int)start.Y, (int)dist+2, 30),
new Rectangle(0, 0, iceCrack.Width, 60), crackColor, MathUtils.VectorToAngle(end -start),
new Vector2(0, 30), SpriteEffects.None, 0.01f);
}
}
for (int i = 0; i < locations.Count; i++)
{
Location location = locations[i];
Vector2 pos = rectCorner + location.MapPosition * scale;
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
if (!rect.Contains(pos)) continue;
int imgIndex = i % 16;
int xCell = imgIndex % 4;
int yCell = (int)Math.Floor(imgIndex / 4.0f);
spriteBatch.Draw(iceCraters, pos,
new Rectangle(xCell * 64, yCell * 64, 64, 64),
Color.White, i,
new Vector2(32, 32), 0.5f*scale, SpriteEffects.None, 0.0f);
Color color = location.Connections.Find(c => c.Locations.Contains(currentLocation))==null ? Color.White : Color.Green;
color *= (location.Discovered) ? 0.8f : 0.4f;
if (location == currentLocation) color = Color.Orange;
location.Type.Sprite.Draw(spriteBatch, pos, color);
//int imgIndex = i % 16;
//int xCell = imgIndex % 4;
//int yCell = (int)Math.Floor(imgIndex / 4.0f);
//spriteBatch.Draw(iceCraters, pos,
// new Rectangle(xCell * 64, yCell * 64, 64, 64),
// Color.White, i,
// new Vector2(32, 32), 0.5f*scale, SpriteEffects.None, 0.0f);
}
@@ -333,14 +349,13 @@ namespace Subsurface
if (location == null) continue;
Vector2 pos = rectCorner + location.MapPosition * scale;
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
pos.X = (int)pos.X;
pos.Y = (int)pos.Y;
if (highlightedLocation==location)
if (highlightedLocation == location)
{
spriteBatch.DrawString(GUI.Font, location.Name, pos + new Vector2(-50, -20), Color.DarkRed);
spriteBatch.DrawString(GUI.Font, location.Name, pos + new Vector2(0, 50), Color.DarkRed, 0.0f, GUI.Font.MeasureString(location.Name)/2.0f, 1.0f, SpriteEffects.None, 0.0f);
}
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - 4, (int)pos.Y - 4, 5 + 8, 5 + 8), Color.DarkRed, false);
}
}

View File

@@ -29,6 +29,8 @@ namespace Subsurface
//which prefab has been selected for placing
protected static MapEntityPrefab selected;
protected int price;
public string Name
{
get { return name; }
@@ -54,6 +56,11 @@ namespace Subsurface
get { return resizeVertical; }
}
public int Price
{
get { return price; }
}
public static void Init()
{
MapEntityPrefab ep = new MapEntityPrefab();

View File

@@ -10,7 +10,7 @@ using System.Collections.ObjectModel;
namespace Subsurface
{
public enum SpawnType { None, Human, Enemy };
public enum SpawnType { None, Human, Enemy, Cargo };
class WayPoint : MapEntity
{
public static List<WayPoint> WayPointList = new List<WayPoint>();
@@ -52,6 +52,7 @@ namespace Subsurface
WayPointList.Add(this);
}
public override void Draw(SpriteBatch spriteBatch, bool editing)
{
if (!editing && !Game1.DebugDraw) return;
@@ -59,7 +60,7 @@ namespace Subsurface
Point pos = new Point((int)Position.X, (int)Position.Y);
Color clr = (isSelected) ? Color.Red : Color.LightGreen;
GUI.DrawRectangle(spriteBatch, new Rectangle(pos.X, -pos.Y, rect.Width, rect.Height), clr, true);
GUI.DrawRectangle(spriteBatch, new Rectangle(pos.X - rect.Width / 2, -pos.Y - rect.Height / 2, rect.Width, rect.Height), clr, true);
foreach (MapEntity e in linkedTo)
{
@@ -102,7 +103,7 @@ namespace Subsurface
spawnType += (int)button.UserData;
if (spawnType > SpawnType.Enemy) spawnType = SpawnType.None;
if (spawnType > SpawnType.Cargo) spawnType = SpawnType.None;
if (spawnType < SpawnType.None) spawnType = SpawnType.Enemy;
spawnTypeText.Text = spawnType.ToString();