This commit is contained in:
Regalis
2015-07-31 21:05:55 +03:00
parent 23d847a4ac
commit 85b0cda4ca
181 changed files with 4455 additions and 4073 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

+6
View File
@@ -34,6 +34,9 @@
<PropertyGroup> <PropertyGroup>
<StartupObject>Launcher.Program</StartupObject> <StartupObject>Launcher.Program</StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@@ -96,6 +99,9 @@
<Name>Subsurface</Name> <Name>Subsurface</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
@@ -2,8 +2,7 @@
<Items> <Items>
<Item <Item
name="Skyholder Artifact" name="Skyholder Artifact"
pickdistance="150" pickdistance="150">
price="100">
<Sprite texture="artifact.png" depth="0.8"/> <Sprite texture="artifact.png" depth="0.8"/>
+2 -1
View File
@@ -2,7 +2,8 @@
name="Button" name="Button"
type="Controller" type="Controller"
linkable="true" linkable="true"
pickdistance="150.0"> pickdistance="150.0"
price="10">
<Sprite texture ="button.png" depth="0.8"/> <Sprite texture ="button.png" depth="0.8"/>
+2 -2
View File
@@ -7,7 +7,7 @@
<Sprite texture ="door.png" sourcerect="0,0,48,208" 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" sourcerect="80,0,19,208" depth="0.4" origin="0.5,0.0"/> <Sprite texture ="door.png" sourcerect="80,0,19,208" depth="0.0" origin="0.5,0.0"/>
</Door> </Door>
<AiTarget sightrange="5000.0"/> <AiTarget sightrange="5000.0"/>
@@ -29,7 +29,7 @@
<Sprite texture ="door.png" sourcerect="0,0,48,208" 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 ="door.png" sourcerect="56,0,19,208" depth="0.4" origin="0.5,0.0"/> <Sprite texture ="door.png" sourcerect="56,0,19,208" depth="0.0" origin="0.5,0.0"/>
</Door> </Door>
<AiTarget sightrange="5000.0"/> <AiTarget sightrange="5000.0"/>
+4 -2
View File
@@ -3,7 +3,8 @@
<Item <Item
name="Medical Syringe" name="Medical Syringe"
Tags="smallitem" Tags="smallitem"
pickdistance="150"> pickdistance="150"
price="50">
<Sprite texture ="med.png" sourcerect="0,0,24,5" depth="0.6"/> <Sprite texture ="med.png" sourcerect="0,0,24,5" depth="0.6"/>
@@ -17,7 +18,8 @@
<Item <Item
name="Bandage" name="Bandage"
Tags="smallitem" Tags="smallitem"
pickdistance="150"> pickdistance="150"
price="20">
<Sprite texture ="med.png" sourcerect="0,14,14,18" depth="0.6"/> <Sprite texture ="med.png" sourcerect="0,14,14,18" depth="0.6"/>
+10 -5
View File
@@ -3,7 +3,8 @@
<Item <Item
name="Welding Tool" name="Welding Tool"
Tags="smallitem" Tags="smallitem"
pickdistance="200"> pickdistance="200"
price="100">
<Sprite texture ="weldingtool.png" depth="0.5"/> <Sprite texture ="weldingtool.png" depth="0.5"/>
@@ -45,7 +46,8 @@
<Item <Item
name="Plasma Cutter" name="Plasma Cutter"
Tags="smallitem" Tags="smallitem"
pickdistance="200"> pickdistance="200"
price="100">
<Sprite texture ="plasmacutter.png" depth="0.5"/> <Sprite texture ="plasmacutter.png" depth="0.5"/>
@@ -77,7 +79,8 @@
<Item <Item
name="Welding Fuel Tank" name="Welding Fuel Tank"
Tags="smallitem" Tags="smallitem"
pickdistance="150"> pickdistance="150"
price="50">
<Sprite texture ="fueltank.png" depth="0.5"/> <Sprite texture ="fueltank.png" depth="0.5"/>
@@ -90,7 +93,8 @@
<Item <Item
name="Screwdriver" name="Screwdriver"
Tags="smallitem" Tags="smallitem"
pickdistance="200"> pickdistance="200"
price="10">
<Sprite texture ="screwdriver.png" depth="0.5"/> <Sprite texture ="screwdriver.png" depth="0.5"/>
@@ -104,7 +108,8 @@
<Item <Item
name="Wrench" name="Wrench"
Tags="smallitem" Tags="smallitem"
pickdistance="200"> pickdistance="200"
price="10">
<Sprite texture ="wrench.png" depth="0.5"/> <Sprite texture ="wrench.png" depth="0.5"/>
@@ -4,7 +4,7 @@
name="C-4 Block" name="C-4 Block"
Tags="smallitem,explosive" Tags="smallitem,explosive"
pickdistance="150" pickdistance="150"
price="50"> price="100">
<Sprite texture="explosives.png" depth="0.8" sourcerect="0,0,16,7"/> <Sprite texture="explosives.png" depth="0.8" sourcerect="0,0,16,7"/>
+7 -3
View File
@@ -3,7 +3,8 @@
<Items> <Items>
<Item <Item
name="Spear" name="Spear"
pickdistance="200"> pickdistance="200"
price="50">
<Sprite texture ="spear.png" depth="0.55"/> <Sprite texture ="spear.png" depth="0.55"/>
@@ -17,7 +18,8 @@
<Item <Item
name="Harpoon Gun" name="Harpoon Gun"
pickdistance="200" > pickdistance="200"
price="500">
<Sprite texture ="harpoongun.png" depth="0.5"/> <Sprite texture ="harpoongun.png" depth="0.5"/>
@@ -39,7 +41,9 @@
<Item <Item
name="Stun Grenade" name="Stun Grenade"
pickdistance="200" > pickdistance="200"
price="200"
tags="smallitem">
<Sprite texture ="stungrenade.png" depth="0.04"/> <Sprite texture ="stungrenade.png" depth="0.04"/>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 253 B

+1 -4
View File
@@ -6,7 +6,7 @@
commonness="10" commonness="10"
reward="1000" reward="1000"
radarlabel="Infrasonic signal" radarlabel="Infrasonic signal"
failuremessage="fail" failuremessage="Retrieving the artifact failed"
successmessage="The artifact has been succesfully retrived" successmessage="The artifact has been succesfully retrived"
itemname="Skyholder Artifact"> itemname="Skyholder Artifact">
</SalvageQuest> </SalvageQuest>
@@ -17,7 +17,6 @@
commonness="10" commonness="10"
reward="1000" reward="1000"
radarlabel="Moloch" radarlabel="Moloch"
failuremessage="fail"
successmessage="The Moloch has been killed." successmessage="The Moloch has been killed."
monsterfile="Content/Characters/Moloch/moloch.xml"> monsterfile="Content/Characters/Moloch/moloch.xml">
</MonsterQuest> </MonsterQuest>
@@ -28,7 +27,6 @@
commonness="10" commonness="10"
reward="800" reward="800"
radarlabel="Tiger Thresher" radarlabel="Tiger Thresher"
failuremessage="fail"
successmessage="The Tiger Thresher has been killed." successmessage="The Tiger Thresher has been killed."
monsterfile="Content/Characters/TigerThresher/tigerthresher.xml"> monsterfile="Content/Characters/TigerThresher/tigerthresher.xml">
</MonsterQuest> </MonsterQuest>
@@ -39,7 +37,6 @@
commonness="5" commonness="5"
reward="1000" reward="1000"
radarlabel="Infrasonic signal" radarlabel="Infrasonic signal"
failuremessage="It turns out the signal picked up by [location1] was emitted by a Moloch."
successmessage="It turns out the signal was emitted by a Moloch. The researchers of [location1] have agreed to pay you the reward nevertheless for killing the Moloch." successmessage="It turns out the signal was emitted by a Moloch. The researchers of [location1] have agreed to pay you the reward nevertheless for killing the Moloch."
monsterfile="Content/Characters/Moloch/moloch.xml"> monsterfile="Content/Characters/Moloch/moloch.xml">
</MonsterQuest> </MonsterQuest>
Binary file not shown.
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 17 KiB

+2 -2
View File
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1.3")] [assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.0.1.3")] [assembly: AssemblyFileVersion("0.1.0.0")]
File diff suppressed because it is too large Load Diff
@@ -54,6 +54,12 @@ namespace Subsurface
{ {
XDocument doc = ToolBox.TryLoadXml(filePath); XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc==null)
{
DebugConsole.ThrowError("Couldn't load content package ''"+filePath+"''!");
return;
}
Path = filePath; Path = filePath;
name = ToolBox.GetAttributeString(doc.Root, "name", ""); name = ToolBox.GetAttributeString(doc.Root, "name", "");
@@ -136,6 +136,12 @@ namespace Subsurface
public static void ExecuteCommand(string command, Game1 game) public static void ExecuteCommand(string command, Game1 game)
{ {
if (Game1.Client!=null)
{
ThrowError("Console commands are disabled in multiplayer mode");
return;
}
if (command == "") return; if (command == "") return;
string[] commands = command.Split(' '); string[] commands = command.Split(' ');
@@ -253,12 +259,12 @@ namespace Subsurface
if (commands.Length < 2) break; if (commands.Length < 2) break;
Submarine.Load("Content/SavedMaps/" + string.Join(" ", commands.Skip(1))); Submarine.Load("Content/SavedMaps/" + string.Join(" ", commands.Skip(1)));
break; break;
case "savegame": //case "savegame":
SaveUtil.SaveGame(SaveUtil.SaveFolder+"save"); // SaveUtil.SaveGame();
break; // break;
case "loadgame": //case "loadgame":
SaveUtil.LoadGame(SaveUtil.SaveFolder + "save"); // SaveUtil.LoadGame(SaveUtil.SaveFolder + "save");
break; // break;
case "messagebox": case "messagebox":
if (commands.Length < 3) break; if (commands.Length < 3) break;
new GUIMessageBox(commands[1], commands[2]); new GUIMessageBox(commands[1], commands[2]);
@@ -121,8 +121,16 @@ namespace Subsurface
object instance = constructor.Invoke(new object[] { element }); object instance = constructor.Invoke(new object[] { element });
Quest quest = (Quest)instance; Quest quest = (Quest)instance;
quest.description = quest.description.Replace("[location1]", locations[0].Name);
quest.description = quest.description.Replace("[location2]", locations[1].Name); for (int n = 0; n<2; n++)
{
quest.description = quest.description.Replace("[location"+(n+1)+"]", locations[n].Name);
quest.successMessage = quest.successMessage.Replace("[location" + (n + 1) + "]", locations[n].Name);
quest.failureMessage = quest.failureMessage.Replace("[location" + (n + 1) + "]", locations[n].Name);
}
return quest; return quest;
} }
@@ -79,11 +79,24 @@ namespace Subsurface
y += 60; y += 60;
} }
} }
button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, GUI.style, pauseMenu);
button.UserData = (int)MainMenuScreen.Tabs.Main; if (Screen.Selected == Game1.LobbyScreen)
button.OnClicked += Game1.MainMenuScreen.SelectTab; {
SinglePlayerMode spMode = Game1.GameSession.gameMode as SinglePlayerMode;
if (spMode != null)
{
button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, GUI.style, pauseMenu);
button.OnClicked += QuitClicked;
button.OnClicked += TogglePauseMenu;
button.UserData = "save";
y += 60;
}
}
button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, GUI.style, pauseMenu);
button.OnClicked += QuitClicked;
button.OnClicked += TogglePauseMenu; button.OnClicked += TogglePauseMenu;
} }
@@ -96,6 +109,20 @@ namespace Subsurface
return true; return true;
} }
private static bool QuitClicked(GUIButton button, object obj)
{
if (button.UserData as string == "save")
{
SaveUtil.SaveGame(Game1.GameSession.SaveFile);
}
Game1.MainMenuScreen.Select();
Game1.MainMenuScreen.SelectTab(null, (int)MainMenuScreen.Tabs.Main);
return true;
}
public static void DrawLine(SpriteBatch sb, Vector2 start, Vector2 end, Color clr, float depth = 0.0f) public static void DrawLine(SpriteBatch sb, Vector2 start, Vector2 end, Color clr, float depth = 0.0f)
{ {
Vector2 edge = end - start; Vector2 edge = end - start;
@@ -297,6 +297,7 @@ namespace Subsurface
{ {
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch); Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
} }
//renderTimeElapsed = (int)renderTimer.Elapsed.Ticks; //renderTimeElapsed = (int)renderTimer.Elapsed.Ticks;
//renderTimer.Stop(); //renderTimer.Stop();
if (sw.Elapsed.TotalSeconds < Physics.step) if (sw.Elapsed.TotalSeconds < Physics.step)
@@ -25,7 +25,7 @@ namespace Subsurface
//private GUIListBox chatBox; //private GUIListBox chatBox;
//private GUITextBox textBox; //private GUITextBox textBox;
private string savePath; private string saveFile;
private Submarine submarine; private Submarine submarine;
@@ -60,22 +60,22 @@ namespace Subsurface
get { return submarine; } get { return submarine; }
} }
public string SavePath public string SaveFile
{ {
get { return savePath; } get { return saveFile; }
} }
public GameSession(Submarine submarine, GameModePreset gameModePreset) public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset)
:this(submarine, gameModePreset.Instantiate()) :this(submarine, saveFile, gameModePreset.Instantiate())
{ {
} }
public GameSession(Submarine selectedSub, GameMode gameMode = null) public GameSession(Submarine selectedSub, string saveFile, GameMode gameMode = null)
{ {
taskManager = new TaskManager(this); taskManager = new TaskManager(this);
savePath = SaveUtil.CreateSavePath(SaveUtil.SaveFolder); this.saveFile = saveFile;
guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent); guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent);
@@ -84,8 +84,8 @@ namespace Subsurface
} }
public GameSession(Submarine selectedSub, string savePath, string filePath) public GameSession(Submarine selectedSub, string saveFile, string filePath)
: this(selectedSub) : this(selectedSub, saveFile)
{ {
XDocument doc = ToolBox.TryLoadXml(filePath); XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null) return; if (doc == null) return;
@@ -96,8 +96,6 @@ namespace Subsurface
gameMode = new SinglePlayerMode(subElement); gameMode = new SinglePlayerMode(subElement);
} }
this.savePath = savePath;
} }
public void StartShift(TimeSpan duration, string levelSeed) public void StartShift(TimeSpan duration, string levelSeed)
@@ -130,7 +128,6 @@ namespace Subsurface
public void EndShift(string endMessage) public void EndShift(string endMessage)
{ {
if (Quest != null) Quest.End(); if (Quest != null) Quest.End();
if (Game1.Server!=null) if (Game1.Server!=null)
@@ -159,7 +156,7 @@ namespace Subsurface
public bool LoadPrevious(GUIButton button, object obj) public bool LoadPrevious(GUIButton button, object obj)
{ {
SaveUtil.LoadGame(savePath); SaveUtil.LoadGame(saveFile);
Game1.LobbyScreen.Select(); Game1.LobbyScreen.Select();
@@ -188,6 +185,9 @@ namespace Subsurface
XDocument doc = new XDocument( XDocument doc = new XDocument(
new XElement((XName)"Gamesession")); new XElement((XName)"Gamesession"));
var now = DateTime.Now;
doc.Root.Add(new XAttribute("savetime", now.Hour + ":" + now.Minute + ", " + now.ToShortDateString()));
((SinglePlayerMode)gameMode).Save(doc.Root); ((SinglePlayerMode)gameMode).Save(doc.Root);
try try
@@ -101,7 +101,7 @@ namespace Subsurface
if (!savedOnStart) if (!savedOnStart)
{ {
SaveUtil.SaveGame(Game1.GameSession.SavePath); SaveUtil.SaveGame(Game1.GameSession.SaveFile);
savedOnStart = true; savedOnStart = true;
} }
@@ -178,7 +178,11 @@ namespace Subsurface
public override void End(string endMessage = "") public override void End(string endMessage = "")
{ {
base.End(endMessage);
isRunning = false;
//if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
List<Character> casualties = crewManager.characters.FindAll(c => c.IsDead); List<Character> casualties = crewManager.characters.FindAll(c => c.IsDead);
@@ -187,7 +191,7 @@ namespace Subsurface
{ {
sb.Append("Your entire crew has died!"); sb.Append("Your entire crew has died!");
var msgBox = new GUIMessageBox("GG", sb.ToString(), new string[] { "Load game", "Quit" }); var msgBox = new GUIMessageBox("", sb.ToString(), new string[] { "Load game", "Quit" });
msgBox.Buttons[0].OnClicked += Game1.GameSession.LoadPrevious; msgBox.Buttons[0].OnClicked += Game1.GameSession.LoadPrevious;
msgBox.Buttons[0].OnClicked += msgBox.Close; msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = Game1.LobbyScreen.QuitToMainMenu; msgBox.Buttons[1].OnClicked = Game1.LobbyScreen.QuitToMainMenu;
@@ -213,7 +217,7 @@ namespace Subsurface
map.MoveToNextLocation(); map.MoveToNextLocation();
} }
SaveUtil.SaveGame(Game1.GameSession.SavePath); SaveUtil.SaveGame(Game1.GameSession.SaveFile);
} }
crewManager.EndShift(); crewManager.EndShift();
@@ -1,325 +1,325 @@
using System; using System;
using System.IO; using System.IO;
using System.Xml.Linq; using System.Xml.Linq;
using FarseerPhysics; using FarseerPhysics;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories; using FarseerPhysics.Factories;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Subsurface.Lights; using Subsurface.Lights;
namespace Subsurface.Items.Components namespace Subsurface.Items.Components
{ {
class Door : ItemComponent class Door : ItemComponent
{ {
Gap linkedGap; Gap linkedGap;
Rectangle window; Rectangle window;
ConvexHull convexHull; ConvexHull convexHull;
ConvexHull convexHull2; ConvexHull convexHull2;
private float stuck; private float stuck;
public float Stuck public float Stuck
{ {
get { return stuck; } get { return stuck; }
set set
{ {
if (isOpen) return; if (isOpen) return;
stuck = MathHelper.Clamp(value, 0.0f, 100.0f); stuck = MathHelper.Clamp(value, 0.0f, 100.0f);
if (stuck == 0.0f) isStuck = false; if (stuck == 0.0f) isStuck = false;
if (stuck == 100.0f) isStuck = true; if (stuck == 100.0f) isStuck = true;
} }
} }
private bool isStuck; private bool isStuck;
Gap LinkedGap Gap LinkedGap
{ {
get get
{ {
if (linkedGap != null) return linkedGap; if (linkedGap != null) return linkedGap;
foreach (MapEntity e in item.linkedTo) foreach (MapEntity e in item.linkedTo)
{ {
linkedGap = e as Gap; linkedGap = e as Gap;
if (linkedGap != null) return linkedGap; if (linkedGap != null) return linkedGap;
} }
linkedGap = new Gap(item.Rect); linkedGap = new Gap(item.Rect);
linkedGap.Open = openState; linkedGap.Open = openState;
item.linkedTo.Add(linkedGap); item.linkedTo.Add(linkedGap);
return linkedGap; return linkedGap;
} }
} }
bool isOpen; bool isOpen;
float openState; float openState;
[HasDefaultValue("0.0,0.0,0.0,0.0", false)] [HasDefaultValue("0.0,0.0,0.0,0.0", false)]
public string Window public string Window
{ {
get { return ToolBox.Vector4ToString(new Vector4(window.X, window.Y, window.Width, window.Height)); } get { return ToolBox.Vector4ToString(new Vector4(window.X, window.Y, window.Width, window.Height)); }
set set
{ {
Vector4 vector = ToolBox.ParseToVector4(value); Vector4 vector = ToolBox.ParseToVector4(value);
if (vector.Z!=0.0f || vector.W !=0.0f) if (vector.Z!=0.0f || vector.W !=0.0f)
{ {
window = new Rectangle((int)vector.X, (int)vector.Y, (int)vector.Z, (int)vector.W); window = new Rectangle((int)vector.X, (int)vector.Y, (int)vector.Z, (int)vector.W);
} }
} }
} }
[Editable, HasDefaultValue(false, true)] [Editable, HasDefaultValue(false, true)]
public bool IsOpen public bool IsOpen
{ {
get { return isOpen; } get { return isOpen; }
set set
{ {
isOpen = value; isOpen = value;
OpenState = (isOpen) ? 1.0f : 0.0f; OpenState = (isOpen) ? 1.0f : 0.0f;
} }
} }
private Rectangle doorRect; private Rectangle doorRect;
public float OpenState public float OpenState
{ {
get { return openState; } get { return openState; }
set set
{ {
float prevValue = openState; float prevValue = openState;
openState = MathHelper.Clamp(value, 0.0f, 1.0f); openState = MathHelper.Clamp(value, 0.0f, 1.0f);
if (openState == prevValue) return; if (openState == prevValue) return;
UpdateConvexHulls(); UpdateConvexHulls();
} }
} }
PhysicsBody body; PhysicsBody body;
Sprite doorSprite; Sprite doorSprite;
public Door(Item item, XElement element) public Door(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
//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()) 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( doorRect = new Rectangle(
item.Rect.Center.X - (int)(doorSprite.size.X / 2), item.Rect.Center.X - (int)(doorSprite.size.X / 2),
item.Rect.Y, item.Rect.Y,
(int)doorSprite.size.X, (int)doorSprite.size.X,
(int)doorSprite.size.Y); (int)doorSprite.size.Y);
body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.World, body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.World,
ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)), ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)),
ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)), ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)),
1.5f)); 1.5f));
body.CollisionCategories = Physics.CollisionWall; body.CollisionCategories = Physics.CollisionWall;
body.UserData = item; body.UserData = item;
body.BodyType = BodyType.Static; body.BodyType = BodyType.Static;
body.SetTransform( body.SetTransform(
ConvertUnits.ToSimUnits(new Vector2(doorRect.Center.X, doorRect.Y - doorRect.Height / 2)), ConvertUnits.ToSimUnits(new Vector2(doorRect.Center.X, doorRect.Y - doorRect.Height / 2)),
0.0f); 0.0f);
body.Friction = 0.5f; body.Friction = 0.5f;
//string spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\"+ ToolBox.GetAttributeString(element, "sprite", ""); //string spritePath = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\"+ ToolBox.GetAttributeString(element, "sprite", "");
Vector2[] corners = GetConvexHullCorners(doorRect); Vector2[] corners = GetConvexHullCorners(doorRect);
convexHull = new ConvexHull(corners, Color.Black); convexHull = new ConvexHull(corners, Color.Black);
if (window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black); if (window!=Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black);
UpdateConvexHulls(); UpdateConvexHulls();
isActive = true; isActive = true;
} }
private void UpdateConvexHulls() private void UpdateConvexHulls()
{ {
Rectangle rect = doorRect; Rectangle rect = doorRect;
rect.Height = (int)(rect.Height * (1.0f - openState)); rect.Height = (int)(rect.Height * (1.0f - openState));
if (window.Height == 0 || window.Width == 0) if (window.Height == 0 || window.Width == 0)
{ {
} }
else else
{ {
//Rectangle rect = item.Rect; //Rectangle rect = item.Rect;
//rect.Height = (int)(rect.Height * (1.0f - openState)); //rect.Height = (int)(rect.Height * (1.0f - openState));
rect.Height = -window.Y; rect.Height = -window.Y;
rect.Y += (int)(doorRect.Height * openState); rect.Y += (int)(doorRect.Height * openState);
rect.Height = Math.Max(rect.Height - (rect.Y - doorRect.Y), 0); rect.Height = Math.Max(rect.Height - (rect.Y - doorRect.Y), 0);
rect.Y = Math.Min(doorRect.Y, rect.Y); rect.Y = Math.Min(doorRect.Y, rect.Y);
if (convexHull2 != null) if (convexHull2 != null)
{ {
Rectangle rect2 = doorRect; Rectangle rect2 = doorRect;
rect2.Y = rect2.Y + window.Y - window.Height; rect2.Y = rect2.Y + window.Y - window.Height;
rect2.Y += (int)(doorRect.Height * openState); rect2.Y += (int)(doorRect.Height * openState);
rect2.Y = Math.Min(doorRect.Y, rect2.Y); rect2.Y = Math.Min(doorRect.Y, rect2.Y);
rect2.Height = rect2.Y - (doorRect.Y - (int)(doorRect.Height * (1.0f - openState))); rect2.Height = rect2.Y - (doorRect.Y - (int)(doorRect.Height * (1.0f - openState)));
//convexHull2.SetVertices(GetConvexHullCorners(rect2)); //convexHull2.SetVertices(GetConvexHullCorners(rect2));
if (rect2.Height == 0) if (rect2.Height == 0)
{ {
convexHull2.Enabled = false; convexHull2.Enabled = false;
} }
else else
{ {
convexHull2.Enabled = true; convexHull2.Enabled = true;
convexHull2.SetVertices(GetConvexHullCorners(rect2)); convexHull2.SetVertices(GetConvexHullCorners(rect2));
} }
} }
} }
if (rect.Height == 0) if (rect.Height == 0)
{ {
convexHull.Enabled = false; convexHull.Enabled = false;
} }
else else
{ {
convexHull.Enabled = true; convexHull.Enabled = true;
convexHull.SetVertices(GetConvexHullCorners(rect)); convexHull.SetVertices(GetConvexHullCorners(rect));
} }
} }
private Vector2[] GetConvexHullCorners(Rectangle rect) private Vector2[] GetConvexHullCorners(Rectangle rect)
{ {
Vector2[] corners = new Vector2[4]; Vector2[] corners = new Vector2[4];
corners[0] = new Vector2(rect.X, rect.Y - rect.Height); corners[0] = new Vector2(rect.X, rect.Y - rect.Height);
corners[1] = new Vector2(rect.X, rect.Y); corners[1] = new Vector2(rect.X, rect.Y);
corners[2] = new Vector2(rect.Right, rect.Y); corners[2] = new Vector2(rect.Right, rect.Y);
corners[3] = new Vector2(rect.Right, rect.Y - rect.Height); corners[3] = new Vector2(rect.Right, rect.Y - rect.Height);
return corners; return corners;
} }
public override void Move(Vector2 amount) public override void Move(Vector2 amount)
{ {
base.Move(amount); base.Move(amount);
//LinkedGap.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); if (convexHull2 != null) convexHull2.Move(amount);
} }
public override bool Pick(Character picker) public override bool Pick(Character picker)
{ {
isOpen = !isOpen; isOpen = !isOpen;
return true; return true;
} }
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (!isStuck) if (!isStuck)
{ {
OpenState += deltaTime * ((isOpen) ? 3.0f : -3.0f); OpenState += deltaTime * ((isOpen) ? 3.0f : -3.0f);
LinkedGap.Open = openState; LinkedGap.Open = openState;
} }
item.SendSignal((isOpen) ? "1" : "0", "state_out"); item.SendSignal((isOpen) ? "1" : "0", "state_out");
} }
public override void UpdateBroken(float deltaTime, Camera cam) public override void UpdateBroken(float deltaTime, Camera cam)
{ {
body.Enabled = false; body.Enabled = false;
convexHull.Enabled = false; convexHull.Enabled = false;
linkedGap.Open = 1.0f; linkedGap.Open = 1.0f;
if (convexHull2 != null) convexHull2.Enabled = false; if (convexHull2 != null) convexHull2.Enabled = false;
} }
public override void Draw(SpriteBatch spriteBatch, bool editing) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
Color color = (item.IsSelected) ? Color.Green : Color.White; Color color = (item.IsSelected) ? Color.Green : Color.White;
color = color * (item.Condition / 100.0f); color = color * (item.Condition / 100.0f);
color.A = 255; color.A = 255;
//prefab.sprite.Draw(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color); //prefab.sprite.Draw(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color);
if (openState == 1.0f) if (openState == 1.0f)
{ {
body.Enabled = false; body.Enabled = false;
} }
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(doorSprite.SourceRect.X, (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);
if (openState == 0.0f) if (openState == 0.0f)
{ {
body.Enabled = true; body.Enabled = true;
} }
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,
item.Rect.Height * (1.0f - openState))); item.Rect.Height * (1.0f - openState)));
foreach (Character c in Character.CharacterList) foreach (Character c in Character.CharacterList)
{ {
int dir = Math.Sign(c.AnimController.limbs[0].SimPosition.X - simPos.X); int dir = Math.Sign(c.AnimController.limbs[0].SimPosition.X - simPos.X);
foreach (Limb l in c.AnimController.limbs) foreach (Limb l in c.AnimController.limbs)
{ {
if (l.SimPosition.Y < simPos.Y || l.SimPosition.Y > simPos.Y - simSize.Y) continue; if (l.SimPosition.Y < simPos.Y || l.SimPosition.Y > simPos.Y - simSize.Y) continue;
if (Math.Abs(l.SimPosition.X - simPos.X) > simSize.X * 2.0f) continue; if (Math.Abs(l.SimPosition.X - simPos.X) > simSize.X * 2.0f) continue;
l.body.ApplyForce(new Vector2(dir * 10.0f, 0.0f)); l.body.ApplyForce(new Vector2(dir * 10.0f, 0.0f));
} }
} }
} }
} }
} }
public override void Remove() public override void Remove()
{ {
base.Remove(); base.Remove();
Game1.World.RemoveBody(body.FarseerBody); Game1.World.RemoveBody(body.FarseerBody);
if (linkedGap!=null) linkedGap.Remove(); if (linkedGap!=null) linkedGap.Remove();
doorSprite.Remove(); doorSprite.Remove();
convexHull.Remove(); convexHull.Remove();
if (convexHull2 != null) convexHull2.Remove(); if (convexHull2 != null) convexHull2.Remove();
} }
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{ {
if (connection.Name=="toggle") if (connection.Name=="toggle")
{ {
isOpen = !isOpen; isOpen = !isOpen;
} }
else if (connection.Name == "set_state") else if (connection.Name == "set_state")
{ {
isOpen = (signal!="0"); isOpen = (signal!="0");
} }
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More