electricity bugfixes, destructable doors, ai improvements, removed rope, container changes

This commit is contained in:
Regalis
2015-05-27 01:02:30 +03:00
parent a1196d1876
commit 80648ffd46
51 changed files with 701 additions and 509 deletions
@@ -1,4 +1,6 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -32,7 +34,12 @@ namespace Subsurface.Items.Components
}
}
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
public override void Move(Vector2 amount)
{
base.Move(amount);
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
if (user!=character) return;
Connection.DrawConnections(spriteBatch, this, character);
@@ -44,8 +51,6 @@ namespace Subsurface.Items.Components
foreach (Connection c in connections)
{
//XElement newElement = new XElement(c.isOutput ? "output" : "input", new XAttribute("name", c.name));
c.Save(componentElement);
}
+79 -46
View File
@@ -11,20 +11,23 @@ namespace Subsurface.Items.Components
{
class Wire : ItemComponent
{
const float nodeDistance = 128.0f;
const float nodeDistance = 32.0f;
const float heightFromFloor = 128.0f;
static Sprite wireSprite;
List<Vector2> nodes;
Connection[] connections;
private Vector2 newNodePos;
public Wire(Item item, XElement element)
: base(item, element)
{
if (wireSprite==null)
if (wireSprite == null)
{
wireSprite = new Sprite("Content/Items/wireHorizontal.png",new Vector2(0.5f,0.5f));
wireSprite = new Sprite("Content/Items/wireHorizontal.png", new Vector2(0.5f, 0.5f));
wireSprite.Depth = 0.85f;
}
@@ -35,9 +38,9 @@ namespace Subsurface.Items.Components
public Connection OtherConnection(Connection connection)
{
if (connection==null) return null;
if (connection==connections[0]) return connections[1];
if (connection==connections[1]) return connections[0];
if (connection == null) return null;
if (connection == connections[0]) return connections[1];
if (connection == connections[1]) return connections[0];
return null;
}
@@ -49,7 +52,7 @@ namespace Subsurface.Items.Components
}
public void Connect(Connection newConnection, bool addNode = true)
{
{
for (int i = 0; i < 2; i++)
{
if (connections[i] == newConnection) return;
@@ -62,8 +65,8 @@ namespace Subsurface.Items.Components
connections[i] = newConnection;
if (!addNode) break;
if (i==0)
if (i == 0)
{
nodes.Insert(0, newConnection.Item.Position);
}
@@ -71,16 +74,18 @@ namespace Subsurface.Items.Components
{
nodes.Add(newConnection.Item.Position);
}
break;
}
if (connections[0]!=null && connections[1]!=null)
if (connections[0] != null && connections[1] != null)
{
item.Drop(null, false);
item.body.Enabled = false;
isActive = false;
CleanNodes();
}
@@ -98,61 +103,80 @@ namespace Subsurface.Items.Components
public override void Unequip(Character character)
{
ClearConnections();
isActive = false;
}
public override void Update(float deltaTime, Camera cam)
{
if (nodes.Count == 0) return;
if (Math.Abs(item.Position.X-nodes[nodes.Count-1].X)>nodeDistance)
{
nodes.Add(new Vector2(
ToolBox.Round(item.Position.X, Map.gridSize.X),
nodes[nodes.Count - 1].Y));
item.FindHull();
item.NewComponentEvent(this, true);
}
else if (Math.Abs(item.Position.Y-nodes[nodes.Count-1].Y)>nodeDistance)
Vector2 position = item.Position;
position.X = ToolBox.Round(item.Position.X, nodeDistance);
if (item.currentHull == null)
{
nodes.Add(new Vector2(nodes[nodes.Count - 1].X,
ToolBox.Round(item.Position.Y, Map.gridSize.Y)));
item.NewComponentEvent(this, true);
position.Y = ToolBox.Round(item.Position.Y, nodeDistance);
}
else
{
position.Y -= item.currentHull.Rect.Y - item.currentHull.Rect.Height;
position.Y = Math.Max(ToolBox.Round(position.Y, nodeDistance), heightFromFloor);
position.Y += item.currentHull.Rect.Y - item.currentHull.Rect.Height;
}
newNodePos = position;
//if (Vector2.Distance(position, nodes[nodes.Count - 1]) > nodeDistance*10)
//{
// nodes.Add(position);
// item.NewComponentEvent(this, true);
//}
//else if (Math.Abs(position.Y - nodes[nodes.Count - 1].Y) > nodeDistance)
//{
// nodes.Add(new Vector2(nodes[nodes.Count - 1].X,
// position.Y));
// item.NewComponentEvent(this, true);
//}
}
//public override bool Use(Character character = null)
//{
// Vector2 nodePos = item.Position;
// ToolBox.Round(nodePos.X, Map.gridSize.X);
// ToolBox.Round(nodePos.Y, Map.gridSize.Y);
public override bool Use(Character character = null)
{
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
nodes.Add(newNodePos);
newNodePos = Vector2.Zero;
}
// nodes.Add(nodePos);
// return true;
//}
return true;
}
public override void SecondaryUse(Character character = null)
{
if (nodes.Count > 0)
if (nodes.Count > 1)
{
nodes.RemoveAt(nodes.Count - 1);
item.NewComponentEvent(this, true);
}
}
public override bool Pick(Character picker)
{
ClearConnections();
return true;
}
private void ClearConnections()
{
nodes.Clear();
for (int i = 0; i < 2; i++ )
for (int i = 0; i < 2; i++)
{
if (connections[i] == null) continue;
int wireIndex = connections[i].FindWireIndex(item);
@@ -168,8 +192,8 @@ namespace Subsurface.Items.Components
{
for (int i = nodes.Count - 2; i > 0; i--)
{
if ((nodes[i-1].X == nodes[i].X || nodes[i-1].Y == nodes[i].Y) &&
(nodes[i+1].X == nodes[i].X || nodes[i+1].Y == nodes[i].Y))
if ((nodes[i - 1].X == nodes[i].X || nodes[i - 1].Y == nodes[i].Y) &&
(nodes[i + 1].X == nodes[i].X || nodes[i + 1].Y == nodes[i].Y))
{
if (Vector2.Distance(nodes[i - 1], nodes[i]) == Vector2.Distance(nodes[i + 1], nodes[i]))
{
@@ -199,29 +223,38 @@ namespace Subsurface.Items.Components
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
if (nodes.Count == 0) return;
for (int i = 0; i < nodes.Count; i++)
{
GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f);
}
for (int i = 1; i<nodes.Count; i++)
for (int i = 1; i < nodes.Count; i++)
{
DrawSection(spriteBatch, nodes[i], nodes[i - 1], i);
DrawSection(spriteBatch, nodes[i], nodes[i - 1], i, Color.White);
}
if (isActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
DrawSection(spriteBatch, nodes[nodes.Count - 1], newNodePos, nodes.Count, Color.White * 0.5f);
//nodes.Add(newNodePos);
}
}
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i)
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i, Color color)
{
start.Y = -start.Y;
end.Y = -end.Y;
spriteBatch.Draw(wireSprite.Texture,
start, null, Color.White,
start, null, color,
ToolBox.VectorToAngle(end - start),
new Vector2(0.0f, wireSprite.size.Y / 2.0f),
new Vector2((Vector2.Distance(start, end)) / wireSprite.Texture.Width, 0.3f),
SpriteEffects.None,
wireSprite.Depth +0.1f + i * 0.00001f);
wireSprite.Depth + 0.1f + i * 0.00001f);
}
public override XElement Save(XElement parentElement)
@@ -230,7 +263,7 @@ namespace Subsurface.Items.Components
if (nodes == null || nodes.Count == 0) return componentElement;
string[] nodeCoords = new string[nodes.Count()*2];
string[] nodeCoords = new string[nodes.Count() * 2];
for (int i = 0; i < nodes.Count(); i++)
{
nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture);
@@ -250,7 +283,7 @@ namespace Subsurface.Items.Components
if (nodeString == "") return;
string[] nodeCoords = nodeString.Split(';');
for (int i = 0; i<nodeCoords.Length/2; i++)
for (int i = 0; i < nodeCoords.Length / 2; i++)
{
float x = 0.0f, y = 0.0f;