new doors

This commit is contained in:
Regalis
2015-05-25 19:41:30 +03:00
parent fadb89ae9e
commit a1196d1876
12 changed files with 3494 additions and 3446 deletions
-3
View File
@@ -105,9 +105,7 @@ namespace Subsurface
get { return pressureProtection; } get { return pressureProtection; }
set set
{ {
//if (!value && pressureProtection) Debug.WriteLine("pp set: " + value);
pressureProtection = MathHelper.Clamp(value, 0.0f, 100.0f); pressureProtection = MathHelper.Clamp(value, 0.0f, 100.0f);
} }
} }
@@ -490,7 +488,6 @@ namespace Subsurface
{ {
if (isDead) return; if (isDead) return;
Debug.WriteLine("pp: " + PressureProtection);
if (PressureProtection==0.0f && if (PressureProtection==0.0f &&
(animController.CurrentHull == null || animController.CurrentHull.LethalPressure >= 100.0f)) (animController.CurrentHull == null || animController.CurrentHull.LethalPressure >= 100.0f))
{ {
+4 -4
View File
@@ -4,10 +4,10 @@
linkable="true" linkable="true"
pickdistance="150.0"> pickdistance="150.0">
<Sprite texture ="doorframe.png" depth="0.8" origin="0.5,0.5"/> <Sprite texture ="door.png" sourcerect="0,0,48,208" depth="0.8" origin="0.5,0.5"/>
<Door> <Door>
<Sprite texture ="door.png" depth="0.4" origin="0.5,0.0"/> <Sprite texture ="door.png" sourcerect="80,0,19,208" depth="0.4" origin="0.5,0.0"/>
</Door> </Door>
<ConnectionPanel canbeselected = "true"> <ConnectionPanel canbeselected = "true">
@@ -24,10 +24,10 @@
linkable="true" linkable="true"
pickdistance="150.0"> pickdistance="150.0">
<Sprite texture ="doorframe.png" depth="0.8" origin="0.5,0.5"/> <Sprite texture ="door.png" sourcerect="0,0,48,208" depth="0.8" origin="0.5,0.5"/>
<Door window="0,-18,10,89"> <Door window="0,-18,10,89">
<Sprite texture ="windowedDoor.png" depth="0.4" origin="0.5,0.0"/> <Sprite texture ="door.png" sourcerect="56,0,19,208" depth="0.4" origin="0.5,0.0"/>
</Door> </Door>
<ConnectionPanel canbeselected = "true"> <ConnectionPanel canbeselected = "true">
+7 -7
View File
@@ -3,7 +3,7 @@
<watersplash sprite="Content/Particles/spatter.png" <watersplash sprite="Content/Particles/spatter.png"
startsizemin="0.15,0.15" startsizemax="0.3,0.3" startsizemin="0.15,0.15" startsizemax="0.3,0.3"
sizechangemin="0.9,0.9" sizechangemax="1.2,1.2" sizechangemin="0.9,0.9" sizechangemax="1.2,1.2"
startrotationmin ="0.0" startrotationmax="3.14" startrotationmin ="0.0" startrotationmax="6.28"
startcolor="1.0, 1.0, 1.0" startalpha="0.8" startcolor="1.0, 1.0, 1.0" startalpha="0.8"
colorchange="0.0, 0.0, 0.0, -0.25" colorchange="0.0, 0.0, 0.0, -0.25"
lifetime="3" lifetime="3"
@@ -11,9 +11,9 @@
velocitychange="0.0, -9.8"/> velocitychange="0.0, -9.8"/>
<mist sprite="Content/Particles/spatter.png" <mist sprite="Content/Particles/spatter.png"
startsizemin="0.2,0.2" startsizemax="0.3,0.3" startsizemin="0.4,0.4" startsizemax="0.5,0.5"
sizechangemin="0.5,0.5" sizechangemax="0.5,0.5" sizechangemin="0.25,0.25" sizechangemax="0.3,0.3"
startrotationmin ="0.0" startrotationmax="3.14" startrotationmin ="0.0" startrotationmax="6.28"
startcolor="1.0, 1.0, 1.0" startalpha="0.5" startcolor="1.0, 1.0, 1.0" startalpha="0.5"
colorchange="0.0, 0.0, 0.0, -0.25" colorchange="0.0, 0.0, 0.0, -0.25"
lifetime="3" lifetime="3"
@@ -22,7 +22,7 @@
<dustcloud sprite="Content/Particles/spatter.png" <dustcloud sprite="Content/Particles/spatter.png"
startsizemin="0.8,0.8" startsizemax="1.0,1.0" startsizemin="0.8,0.8" startsizemax="1.0,1.0"
sizechangemin="0.0,0.0" sizechangemax="0.0,0.0" sizechangemin="0.0,0.0" sizechangemax="0.0,0.0"
startrotationmin ="0.0" startrotationmax="3.14" startrotationmin ="0.0" startrotationmax="6.28"
startcolor="0.2, 0.2, 0.2" startalpha="0.5" startcolor="0.2, 0.2, 0.2" startalpha="0.5"
colorchange="0.0, 0.0, 0.0, -0.3" colorchange="0.0, 0.0, 0.0, -0.3"
lifetime="3" lifetime="3"
@@ -53,7 +53,7 @@
<waterblood sprite="Content/Particles/spatter.png" <waterblood sprite="Content/Particles/spatter.png"
startsizemin="0.1,0.1" startsizemax="0.1,0.1" startsizemin="0.1,0.1" startsizemax="0.1,0.1"
sizechangemin="0.15,0.15" sizechangemax="0.2,0.2" sizechangemin="0.15,0.15" sizechangemax="0.2,0.2"
startrotationmin ="0.0" startrotationmax="3.14" startrotationmin ="0.0" startrotationmax="6.28"
startcolor="0.5, 0.0, 0.0" startalpha="1.0" startcolor="0.5, 0.0, 0.0" startalpha="1.0"
colorchange="0.0, 0.0, 0.0, -0.25" colorchange="0.0, 0.0, 0.0, -0.25"
lifetime="5.0" lifetime="5.0"
@@ -63,7 +63,7 @@
<explosionfire sprite="Content/Particles/explosion.png" <explosionfire sprite="Content/Particles/explosion.png"
startsizemin="1.5,1.5" startsizemax="3.0,3.0" startsizemin="1.5,1.5" startsizemax="3.0,3.0"
sizechangemin="0.5,0.5" sizechangemax="0.6,0.6" sizechangemin="0.5,0.5" sizechangemax="0.6,0.6"
startrotationmin ="0.0" startrotationmax="3.14" startrotationmin ="0.0" startrotationmax="6.28"
startcolor="1.0, 1.0, 1.0" startalpha="1.0" startcolor="1.0, 1.0, 1.0" startalpha="1.0"
colorchange="-0.4, -0.4, -0.4, -0.3" colorchange="-0.4, -0.4, -0.4, -0.3"
lifetime="5.0" lifetime="5.0"
+69 -32
View File
@@ -64,6 +64,9 @@ namespace Subsurface.Items.Components
} }
} }
private Rectangle doorRect;
public float OpenState public float OpenState
{ {
get { return openState; } get { return openState; }
@@ -85,23 +88,45 @@ namespace Subsurface.Items.Components
//Rectangle rect = item.Rect; //Rectangle rect = item.Rect;
//rect.Height = (int)(rect.Height * (1.0f - openState)); //rect.Height = (int)(rect.Height * (1.0f - openState));
Rectangle rect1 = item.Rect; Rectangle rect1 = doorRect;
rect1.Height = -window.Y; rect1.Height = -window.Y;
rect1.Y += (int)(item.Rect.Height * openState); rect1.Y += (int)(doorRect.Height * openState);
rect1.Height = Math.Max(rect1.Height - (rect1.Y - item.Rect.Y), 0); rect1.Height = Math.Max(rect1.Height - (rect1.Y - doorRect.Y), 0);
rect1.Y = Math.Min(item.Rect.Y, rect1.Y); rect1.Y = Math.Min(doorRect.Y, rect1.Y);
if (rect1.Height == 0)
{
convexHull.Enabled = false;
}
else
{
convexHull.SetVertices(GetConvexHullCorners(rect1));
}
if (convexHull2 != null)
{
Rectangle rect2 = doorRect;
rect2.Y = rect2.Y + window.Y - window.Height;
rect2.Y += (int)(doorRect.Height * openState);
rect2.Y = Math.Min(doorRect.Y, rect2.Y);
rect2.Height = rect2.Y - (doorRect.Y - (int)(doorRect.Height * (1.0f - openState)));
convexHull2.SetVertices(GetConvexHullCorners(rect2));
if (rect2.Height == 0)
{
convexHull2.Enabled = false;
}
else
{
convexHull2.SetVertices(GetConvexHullCorners(rect2));
}
}
Rectangle rect2 = item.Rect;
rect2.Y = rect2.Y + window.Y - window.Height;
rect2.Y += (int)(item.Rect.Height * openState);
//rect2.Height = Math.Max(rect2.Height - (rect2.Y - item.Rect.Y), 0);
rect2.Y = Math.Min(item.Rect.Y, rect2.Y);
rect2.Height = rect2.Y - (item.Rect.Y - (int)(item.Rect.Height * (1.0f - openState)));
convexHull.SetVertices(GetConvexHullCorners(rect1));
if (convexHull2!=null) convexHull2.SetVertices(GetConvexHullCorners(rect2));
} }
} }
@@ -117,31 +142,40 @@ namespace Subsurface.Items.Components
//Vector2 position = new Vector2(newRect.X, newRect.Y); //Vector2 position = new Vector2(newRect.X, newRect.Y);
// isOpen = false; // isOpen = false;
foreach (XElement subElement in element.Elements())
body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.world,
ConvertUnits.ToSimUnits(Math.Max(item.Rect.Width, 1)),
ConvertUnits.ToSimUnits(Math.Max(item.Rect.Height, 1)),
1.5f));
body.BodyType = BodyType.Static;
body.SetTransform(
ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + item.Rect.Width / 2, item.Rect.Y - item.Rect.Height / 2)),
0.0f);
body.Friction = 0.5f;
//string spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\"+ ToolBox.GetAttributeString(element, "sprite", "");
foreach (XElement subElement in element.Elements())
{ {
if (subElement.Name.ToString().ToLower() != "sprite") continue; if (subElement.Name.ToString().ToLower() != "sprite") continue;
doorSprite = new Sprite(subElement, Path.GetDirectoryName(item.Prefab.ConfigFile)); doorSprite = new Sprite(subElement, Path.GetDirectoryName(item.Prefab.ConfigFile));
break; break;
} }
doorRect = new Rectangle(
item.Rect.Center.X - (int)(doorSprite.size.X / 2),
item.Rect.Y,
(int)doorSprite.size.X,
(int)doorSprite.size.Y);
body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.world,
ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)),
ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)),
1.5f));
body.BodyType = BodyType.Static;
body.SetTransform(
ConvertUnits.ToSimUnits(new Vector2(doorRect.Center.X, doorRect.Y - doorRect.Height / 2)),
0.0f);
body.Friction = 0.5f;
//string spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\"+ ToolBox.GetAttributeString(element, "sprite", "");
isActive = true; isActive = true;
Vector2[] corners = GetConvexHullCorners(item.Rect);
Vector2[] corners = GetConvexHullCorners(doorRect);
convexHull = new ConvexHull(corners, Color.Black); convexHull = new ConvexHull(corners, Color.Black);
if (window!=null) convexHull2 = new ConvexHull(corners, Color.Black); if (window!=null) convexHull2 = new ConvexHull(corners, Color.Black);
@@ -167,9 +201,12 @@ namespace Subsurface.Items.Components
{ {
base.Move(amount); base.Move(amount);
linkedGap.Move(amount);
body.SetTransform(body.Position + ConvertUnits.ToSimUnits(amount), 0.0f); body.SetTransform(body.Position + ConvertUnits.ToSimUnits(amount), 0.0f);
convexHull.Move(amount); convexHull.Move(amount);
if (convexHull2 != null) convexHull2.Move(amount);
} }
@@ -205,7 +242,7 @@ namespace Subsurface.Items.Components
else else
{ {
spriteBatch.Draw(doorSprite.Texture, new Vector2(item.Rect.Center.X, -item.Rect.Y), spriteBatch.Draw(doorSprite.Texture, new Vector2(item.Rect.Center.X, -item.Rect.Y),
new Rectangle(0, (int)(doorSprite.size.Y * openState), new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.size.Y * openState),
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))), (int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth); color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
@@ -217,8 +254,6 @@ namespace Subsurface.Items.Components
} }
else else
{ {
//push characters out of the doorway when the door is closing/opening //push characters out of the doorway when the door is closing/opening
Vector2 simPos = ConvertUnits.ToSimUnits(new Vector2(item.Rect.X, item.Rect.Y)); Vector2 simPos = ConvertUnits.ToSimUnits(new Vector2(item.Rect.X, item.Rect.Y));
Vector2 simSize = ConvertUnits.ToSimUnits(new Vector2(item.Rect.Width, Vector2 simSize = ConvertUnits.ToSimUnits(new Vector2(item.Rect.Width,
@@ -245,6 +280,8 @@ namespace Subsurface.Items.Components
Game1.world.RemoveBody(body.FarseerBody); Game1.world.RemoveBody(body.FarseerBody);
linkedGap.Remove();
doorSprite.Remove(); doorSprite.Remove();
convexHull.Remove(); convexHull.Remove();
+1 -2
View File
@@ -60,8 +60,7 @@ namespace Subsurface
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam) public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
{ {
Vector2 position = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y); Vector2 position = Map.MouseToWorldGrid(cam);
position = cam.ScreenToWorld(position);
if (!resizeHorizontal && !resizeVertical) if (!resizeHorizontal && !resizeVertical)
{ {
+6
View File
@@ -88,6 +88,12 @@ namespace Subsurface
} }
} }
public override bool Contains(Vector2 position)
{
return (Map.RectContains(rect, position) &&
!Map.RectContains(new Rectangle(rect.X + 4, rect.Y - 4, rect.Width - 8, rect.Height - 8), position));
}
private void FindHulls() private void FindHulls()
{ {
Hull hull1 = null, hull2 = null; Hull hull1 = null, hull2 = null;
+2 -2
View File
@@ -151,7 +151,7 @@ namespace Subsurface
public override bool Contains(Vector2 position) public override bool Contains(Vector2 position)
{ {
return (Map.RectContains(rect, position) && return (Map.RectContains(rect, position) &&
!Map.RectContains(new Rectangle(rect.X + 8, rect.Y - 8, rect.Width -16, rect.Height -16), position)); !Map.RectContains(new Rectangle(rect.X + 8, rect.Y - 8, rect.Width - 16, rect.Height - 16), position));
} }
public int GetWaveIndex(Vector2 position) public int GetWaveIndex(Vector2 position)
@@ -213,7 +213,7 @@ namespace Subsurface
if (maxDelta > ToolBox.RandomFloat(0.2f,10.0f)) if (maxDelta > ToolBox.RandomFloat(0.2f,10.0f))
{ {
Game1.particleManager.CreateParticle(ConvertUnits.ToSimUnits(new Vector2(rect.X + WaveWidth * i,surface + waveY[i])), Game1.particleManager.CreateParticle(ConvertUnits.ToSimUnits(new Vector2(rect.X + WaveWidth * i,surface + waveY[i])),
0.0f, new Vector2(0.0f, waveVel[i]/10.0f-1.0f), "mist"); ToolBox.RandomFloat(0.0f,6.2f), new Vector2(0.0f, -0.5f), "mist");
} }
waveY[i] = waveY[i] + waveVel[i]; waveY[i] = waveY[i] + waveVel[i];
-8
View File
@@ -25,13 +25,6 @@ namespace Subsurface.Lights
set; set;
} }
//private Vector2 position = Vector2.Zero;
//public Vector2 Position
//{
// get { return position; }
// set { position = value; }
//}
public ConvexHull(Vector2[] points, Color color) public ConvexHull(Vector2[] points, Color color)
{ {
int vertexCount = points.Length; int vertexCount = points.Length;
@@ -57,7 +50,6 @@ namespace Subsurface.Lights
} }
backFacing = new bool[vertexCount]; backFacing = new bool[vertexCount];
Enabled = true; Enabled = true;
list.Add(this); list.Add(this);
+18 -1
View File
@@ -19,6 +19,8 @@ namespace Subsurface
static class Map static class Map
{ {
static string MapFolder = "Content/SavedMaps";
public static Vector2 gridSize = new Vector2(16.0f, 16.0f); public static Vector2 gridSize = new Vector2(16.0f, 16.0f);
private static Vector2 lastPickedPosition; private static Vector2 lastPickedPosition;
@@ -244,9 +246,24 @@ namespace Subsurface
public static string[] GetMapFilePaths() public static string[] GetMapFilePaths()
{ {
string[] mapFilePaths; string[] mapFilePaths;
if (!Directory.Exists(MapFolder))
{
try
{
Directory.CreateDirectory(MapFolder);
}
catch
{
DebugConsole.ThrowError("Directory ''Content/SavedMaps'' not found and creating the directory failed.");
return null;
}
}
try try
{ {
mapFilePaths = Directory.GetFiles("Content/SavedMaps"); mapFilePaths = Directory.GetFiles(MapFolder);
} }
catch (Exception e) catch (Exception e)
{ {
+1 -1
View File
@@ -258,7 +258,7 @@ namespace Subsurface
{ {
if (dummyCharacter != null && dummyCharacter.SelectedConstruction != null) if (dummyCharacter != null && dummyCharacter.SelectedConstruction != null)
{ {
if (Character.Controlled.SelectedConstruction == dummyCharacter.ClosestItem) if (dummyCharacter.SelectedConstruction == dummyCharacter.ClosestItem)
{ {
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter); dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
} }
+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>ShowAllFiles</ProjectView> <ProjectView>ProjectFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
Binary file not shown.