Created and implemented EntityManager. PixelTransform and GridTransform phased out.

This commit is contained in:
Simon Holmberg
2012-10-17 23:44:58 +02:00
parent 8e1f18d233
commit c59ff9778a
11 changed files with 352 additions and 450 deletions
@@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
[Obsolete("Deprecated in favour of Component.Transform")]
public class GridTransform : Component
{
public Point Position;
public int X
{
get
{
return Position.X;
}
set
{
Position.X = value;
}
}
public int Y
{
get
{
return Position.Y;
}
set
{
Position.Y = value;
}
}
public GridTransform(Entity parent) : base(parent)
{
Position = Point.Zero;
}
public Vector2 ToWorld()
{
return Grid.GridToWorld(Position);
}
}
}
@@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
[Obsolete("Deprecated in favour of Component.Transform")]
public class PixelTransform : Component
{
public Vector2 Position;
public float X
{
get
{
return Position.X;
}
set
{
Position.X = value;
}
}
public float Y
{
get
{
return Position.Y;
}
set
{
Position.Y = value;
}
}
public float Rotation;
public Vector2 Origin;
public PixelTransform(Entity parent)
: base(parent)
{
Position = Vector2.Zero;
Rotation = 0.0f;
Origin = Vector2.Zero;
}
public Point ToGrid()
{
return Grid.WorldToGrid(Position);
}
}
}
+16 -45
View File
@@ -22,7 +22,9 @@ namespace DepthsBelow
public static GraphicsDeviceManager GraphicsDeviceManager; public static GraphicsDeviceManager GraphicsDeviceManager;
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
public Lua Lua; public Lua Lua;
public EntityManager EntityManager;
public Camera Camera; public Camera Camera;
@@ -63,14 +65,13 @@ namespace DepthsBelow
/// </summary> /// </summary>
protected override void Initialize() protected override void Initialize()
{ {
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
EntityManager = new EntityManager();
Camera = new Camera(this); Camera = new Camera(this);
Squad = new List<Soldier>(); Squad = new List<Soldier>();
Swarm = new List<SmallEnemy>(); Swarm = new List<SmallEnemy>();
Volley = new List<Shot>(); Volley = new List<Shot>();
TestMonster = new SmallEnemy(this, ref Swarm);
// Run scripts after everything is initialized // Run scripts after everything is initialized
Lua = new Lua(); Lua = new Lua();
Lua.LoadScripts(); Lua.LoadScripts();
@@ -92,20 +93,18 @@ namespace DepthsBelow
Map.ParseObjects(this); Map.ParseObjects(this);
// TODO: use this.Content to load your game content here // TODO: use this.Content to load your game content here
Soldier.LoadContent(this); Soldier.LoadContent();
SmallEnemy.LoadContent(this); SmallEnemy.LoadContent();
Shot.LoadContent(this); Shot.LoadContent();
MouseInput = new MouseInput(this); MouseInput = new MouseInput(this);
MouseInput.LoadContent(); MouseInput.LoadContent();
KeyboardInput = new KeyboardInput(this); KeyboardInput = new KeyboardInput(this);
TestMonster = new SmallEnemy(EntityManager, ref Swarm);
TestMonster.X = 12;
TestMonster.Y = 4;
Swarm.Add(TestMonster); Swarm.Add(TestMonster);
TestMonster.X = 12;
TestMonster.Y = 4;
//frame.AddChild(text);
} }
/// <summary> /// <summary>
@@ -132,17 +131,8 @@ namespace DepthsBelow
MouseInput.Update(gameTime); MouseInput.Update(gameTime);
KeyboardInput.Update(gameTime); KeyboardInput.Update(gameTime);
// Update soldiers in squad EntityManager.Update(gameTime);
foreach (var soldier in Squad)
soldier.Update(gameTime);
foreach (var body in Swarm)
body.Update(gameTime);
foreach (var bullet in Volley)
bullet.Update(gameTime);
TestMonster.Update(gameTime);
GUIManager.Update(gameTime); GUIManager.Update(gameTime);
base.Update(gameTime); base.Update(gameTime);
@@ -163,25 +153,8 @@ namespace DepthsBelow
// Draw the level // Draw the level
Map.Draw(spriteBatch); Map.Draw(spriteBatch);
// Draw units // Draw entities
foreach (var soldier in Squad) EntityManager.Draw(spriteBatch);
{
var sr = soldier.GetComponent<Component.SpriteRenderer>();
if (sr != null)
sr.Draw(spriteBatch);
}
foreach (var body in Swarm)
{
var sr = body.GetComponent<Component.SpriteRenderer>();
if (sr != null)
sr.Draw(spriteBatch);
}
foreach (var bullet in Volley)
{
var sr = bullet.GetComponent<Component.SpriteRenderer>();
if (sr != null)
sr.Draw(spriteBatch);
}
// Draw mouse input visuals // Draw mouse input visuals
MouseInput.Draw(spriteBatch); MouseInput.Draw(spriteBatch);
@@ -197,7 +170,5 @@ namespace DepthsBelow
base.Draw(gameTime); base.Draw(gameTime);
} }
} }
} }
+201 -202
View File
@@ -1,204 +1,203 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ProjectGuid>{94683C5B-052D-4143-96D8-35C67E831000}</ProjectGuid> <ProjectGuid>{94683C5B-052D-4143-96D8-35C67E831000}</ProjectGuid>
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DepthsBelow</RootNamespace> <RootNamespace>DepthsBelow</RootNamespace>
<AssemblyName>DepthsBelow</AssemblyName> <AssemblyName>DepthsBelow</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile> <TargetFrameworkProfile>Client</TargetFrameworkProfile>
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion> <XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform> <XnaPlatform>Windows</XnaPlatform>
<XnaProfile>HiDef</XnaProfile> <XnaProfile>HiDef</XnaProfile>
<XnaCrossPlatformGroupID>faa0577e-a03e-43cf-89c7-0a03f4c22717</XnaCrossPlatformGroupID> <XnaCrossPlatformGroupID>faa0577e-a03e-43cf-89c7-0a03f4c22717</XnaCrossPlatformGroupID>
<XnaOutputType>Game</XnaOutputType> <XnaOutputType>Game</XnaOutputType>
<ApplicationIcon>Game.ico</ApplicationIcon> <ApplicationIcon>Game.ico</ApplicationIcon>
<Thumbnail>GameThumbnail.png</Thumbnail> <Thumbnail>GameThumbnail.png</Thumbnail>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode> <UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision> <ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted> <PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\x86\Debug</OutputPath> <OutputPath>bin\x86\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants> <DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib> <NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>false</XnaCompressContent> <XnaCompressContent>false</XnaCompressContent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\x86\Release</OutputPath> <OutputPath>bin\x86\Release</OutputPath>
<DefineConstants>TRACE;WINDOWS</DefineConstants> <DefineConstants>TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib> <NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>true</XnaCompressContent> <XnaCompressContent>true</XnaCompressContent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ManifestCertificateThumbprint>ECE66DEF071576E8D2F7D57232C0569623E3E2DF</ManifestCertificateThumbprint> <ManifestCertificateThumbprint>ECE66DEF071576E8D2F7D57232C0569623E3E2DF</ManifestCertificateThumbprint>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ManifestKeyFile>DepthsBelow_TemporaryKey.pfx</ManifestKeyFile> <ManifestKeyFile>DepthsBelow_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<GenerateManifests>true</GenerateManifests> <GenerateManifests>true</GenerateManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignManifests>true</SignManifests> <SignManifests>true</SignManifests>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86"> <Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86">
<HintPath>..\..\LuaInterface\LuaInterface.dll</HintPath> <HintPath>..\..\LuaInterface\LuaInterface.dll</HintPath>
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.GamerServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.GamerServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Video, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Video, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Avatar, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Avatar, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Xna.Framework.Storage, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> <Reference Include="Microsoft.Xna.Framework.Storage, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="mscorlib"> <Reference Include="mscorlib">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System"> <Reference Include="System">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Core"> <Reference Include="System.Core">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Net"> <Reference Include="System.Net">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Camera.cs" /> <Compile Include="Camera.cs" />
<Compile Include="CustomExtensions.cs" /> <Compile Include="CustomExtensions.cs" />
<Compile Include="GameServices.cs" /> <Compile Include="EntityManager.cs" />
<Compile Include="Interface.cs" /> <Compile Include="GameServices.cs" />
<Compile Include="Lua.cs" /> <Compile Include="Interface.cs" />
<Compile Include="Shot.cs" /> <Compile Include="Lua.cs" />
<Compile Include="Component\Stat.cs" /> <Compile Include="Shot.cs" />
<Compile Include="GUIManager.cs" /> <Compile Include="Component\Stat.cs" />
<Compile Include="GUI\Button.cs" /> <Compile Include="GUIManager.cs" />
<Compile Include="GUI\Frame.cs" /> <Compile Include="GUI\Button.cs" />
<Compile Include="GUI\Text.cs" /> <Compile Include="GUI\Frame.cs" />
<Compile Include="KeyboardInput.cs" /> <Compile Include="GUI\Text.cs" />
<Compile Include="Component\PathFinder.cs" /> <Compile Include="KeyboardInput.cs" />
<Compile Include="Component\Transform.cs" /> <Compile Include="Component\PathFinder.cs" />
<Compile Include="Grid.cs" /> <Compile Include="Component\Transform.cs" />
<Compile Include="Component\Collision.cs" /> <Compile Include="Grid.cs" />
<Compile Include="Component\Component.cs" /> <Compile Include="Component\Collision.cs" />
<Compile Include="Component\GridTransform.cs" /> <Compile Include="Component\Component.cs" />
<Compile Include="Core.cs" /> <Compile Include="Core.cs" />
<Compile Include="Entity.cs" /> <Compile Include="Entity.cs" />
<Compile Include="Map.cs" /> <Compile Include="Map.cs" />
<Compile Include="MouseInput.cs" /> <Compile Include="MouseInput.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Component\SpriteRenderer.cs" /> <Compile Include="Component\SpriteRenderer.cs" />
<Compile Include="RenderHelpers.cs" /> <Compile Include="RenderHelpers.cs" />
<Compile Include="SmallEnemy.cs" /> <Compile Include="SmallEnemy.cs" />
<Compile Include="Soldier.cs" /> <Compile Include="Soldier.cs" />
<Compile Include="Component\PixelTransform.cs" /> <Compile Include="Utility.cs" />
<Compile Include="Utility.cs" /> </ItemGroup>
</ItemGroup> <ItemGroup>
<ItemGroup> <Content Include="Game.ico" />
<Content Include="Game.ico" /> <Content Include="GameThumbnail.png" />
<Content Include="GameThumbnail.png" /> </ItemGroup>
</ItemGroup> <ItemGroup>
<ItemGroup> <ProjectReference Include="..\..\AStar\AStar.csproj">
<ProjectReference Include="..\..\AStar\AStar.csproj"> <Project>{CD3F949D-54AA-4D38-99DB-92905A375D84}</Project>
<Project>{CD3F949D-54AA-4D38-99DB-92905A375D84}</Project> <Name>AStar</Name>
<Name>AStar</Name> </ProjectReference>
</ProjectReference> <ProjectReference Include="..\DepthsBelowContent\DepthsBelowContent.contentproj">
<ProjectReference Include="..\DepthsBelowContent\DepthsBelowContent.contentproj"> <Name>DepthsBelowContent %28Content%29</Name>
<Name>DepthsBelowContent %28Content%29</Name> <XnaReferenceType>Content</XnaReferenceType>
<XnaReferenceType>Content</XnaReferenceType> <Project>{433A77A2-DE52-4875-A4EF-232CF59C2DD3}</Project>
<Project>{433A77A2-DE52-4875-A4EF-232CF59C2DD3}</Project> </ProjectReference>
</ProjectReference> </ItemGroup>
</ItemGroup> <ItemGroup>
<ItemGroup> <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client"> <Visible>False</Visible>
<Visible>False</Visible> <ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName> <Install>true</Install>
<Install>true</Install> </BootstrapperPackage>
</BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <Visible>False</Visible>
<Visible>False</Visible> <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> <Install>false</Install>
<Install>false</Install> </BootstrapperPackage>
</BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> <Visible>False</Visible>
<Visible>False</Visible> <ProductName>.NET Framework 3.5 SP1</ProductName>
<ProductName>.NET Framework 3.5 SP1</ProductName> <Install>false</Install>
<Install>false</Install> </BootstrapperPackage>
</BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> <Visible>False</Visible>
<Visible>False</Visible> <ProductName>Windows Installer 3.1</ProductName>
<ProductName>Windows Installer 3.1</ProductName> <Install>true</Install>
<Install>true</Install> </BootstrapperPackage>
</BootstrapperPackage> <BootstrapperPackage Include="Microsoft.Xna.Framework.4.0">
<BootstrapperPackage Include="Microsoft.Xna.Framework.4.0"> <Visible>False</Visible>
<Visible>False</Visible> <ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName>
<ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName> <Install>true</Install>
<Install>true</Install> </BootstrapperPackage>
</BootstrapperPackage> </ItemGroup>
</ItemGroup> <ItemGroup>
<ItemGroup> <None Include="App.config" />
<None Include="App.config" /> <None Include="DepthsBelow_TemporaryKey.pfx" />
<None Include="DepthsBelow_TemporaryKey.pfx" /> </ItemGroup>
</ItemGroup> <ItemGroup />
<ItemGroup /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.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.
@@ -206,5 +205,5 @@
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>
+27 -17
View File
@@ -6,13 +6,11 @@ using Microsoft.Xna.Framework;
namespace DepthsBelow namespace DepthsBelow
{ {
public class Entity public class Entity : IDisposable
{ {
List<Component.Component> Components; List<Component.Component> Components;
public Component.Transform Transform; public Component.Transform Transform;
public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform;
public Component.Stat stat;
public int X public int X
{ {
get { return this.Transform.Grid.X; } get { return this.Transform.Grid.X; }
@@ -28,23 +26,35 @@ namespace DepthsBelow
{ {
this.Transform.Grid.Y = value; this.Transform.Grid.Y = value;
} }
} }
protected Core core; private EntityManager entityManager;
public Entity(Core core)
{
this.core = core;
public Entity(EntityManager entityManager)
{
this.entityManager = entityManager;
entityManager.Add(this);
Components = new List<Component.Component>(); Components = new List<Component.Component>();
Transform = new Component.Transform(this); Transform = new Component.Transform(this);
AddComponent(Transform); AddComponent(Transform);
pixelTransform = new Component.PixelTransform(this); }
AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this); public virtual void Dispose()
AddComponent(gridTransform); {
stat = new Component.Stat(this);
AddComponent(stat); }
public virtual void Remove()
{
entityManager.Remove(this);
Dispose();
}
public virtual void Kill()
{
Remove();
} }
public T GetComponent<T>() where T : Component.Component public T GetComponent<T>() where T : Component.Component
+55
View File
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace DepthsBelow
{
public class EntityManager : IDisposable
{
private List<Entity> entities;
public EntityManager()
{
entities = new List<Entity>();
}
public void Dispose()
{
foreach (var entity in entities)
entity.Dispose();
}
public void Add(Entity entity)
{
entities.Add(entity);
}
public void Remove(Entity entity)
{
entities.Remove(entity);
}
public void Reset()
{
foreach (var entity in entities)
entity.Dispose();
entities.Clear();
}
public void Update(GameTime gameTime)
{
foreach (var entity in entities)
entity.Update(gameTime);
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (var entity in entities)
entity.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
}
}
}
+2 -2
View File
@@ -82,7 +82,7 @@ namespace DepthsBelow
{ {
if (soldier.Selected == true && soldier.Fired == false) if (soldier.Selected == true && soldier.Fired == false)
{ {
core.Volley.Add(new Shot(core)); core.Volley.Add(new Shot(core.EntityManager));
soldier.Fired = true; soldier.Fired = true;
foreach (var shot in core.Volley) foreach (var shot in core.Volley)
{ {
@@ -139,7 +139,7 @@ namespace DepthsBelow
current = 0; current = 0;
if (soldier.Selected == true && soldier.Fired == false && hit == true) if (soldier.Selected == true && soldier.Fired == false && hit == true)
{ {
core.Volley.Add(new Shot(core)); core.Volley.Add(new Shot(core.EntityManager));
soldier.Fired = true; soldier.Fired = true;
foreach (var shot in core.Volley) foreach (var shot in core.Volley)
{ {
+1 -1
View File
@@ -72,7 +72,7 @@ namespace DepthsBelow
{ {
if (mapObject.Type == "SquadStart") if (mapObject.Type == "SquadStart")
{ {
var soldier = new Soldier(core, ref core.Squad); var soldier = new Soldier(core.EntityManager, ref core.Squad);
// HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91) // HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91)
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
+8 -22
View File
@@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DepthsBelow.Component; using DepthsBelow.Component;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@@ -28,11 +29,11 @@ namespace DepthsBelow
public Vector2 direction = Vector2.Zero; public Vector2 direction = Vector2.Zero;
public Shot(Core core) public Shot(EntityManager entityManager)
: base(core) : base(entityManager)
{ {
if (Texture == null) if (Texture == null)
LoadContent(core); LoadContent();
Transform.World.Origin = new Vector2(16, 16); Transform.World.Origin = new Vector2(16, 16);
@@ -44,9 +45,9 @@ namespace DepthsBelow
AddComponent(cc); AddComponent(cc);
} }
public static void LoadContent(Core core) public static void LoadContent()
{ {
Texture = core.Content.Load<Texture2D>("images/Shot"); Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
@@ -55,21 +56,6 @@ namespace DepthsBelow
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
List<Point> soldierCollisions = new List<Point>(); List<Point> soldierCollisions = new List<Point>();
foreach (var body in core.Swarm)
{
if (this.GetComponent<Collision>().Rectangle.Intersects(body.GetComponent<Collision>().Rectangle))
{
}
}
foreach (var soldier in core.Squad)
{
if (this.GetComponent<Collision>().Rectangle.Intersects(soldier.GetComponent<Collision>().Rectangle))
{
}
}
// HACK: Make this work properly with other speeds... // HACK: Make this work properly with other speeds...
float speed = 4f; float speed = 4f;
Transform.World.Position += speed * direction; Transform.World.Position += speed * direction;
+20 -28
View File
@@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DepthsBelow.Component; using DepthsBelow.Component;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@@ -30,11 +31,11 @@ namespace DepthsBelow
} }
} }
public SmallEnemy(Core core, ref List<SmallEnemy> swarm) public SmallEnemy(EntityManager entityManager, ref List<SmallEnemy> swarm)
: base(core) : base(entityManager)
{ {
if (Texture == null) if (Texture == null)
LoadContent(core); LoadContent();
this.Swarm = swarm; this.Swarm = swarm;
@@ -48,13 +49,17 @@ namespace DepthsBelow
AddComponent(cc); AddComponent(cc);
var pfc = new PathFinder(this); var pfc = new PathFinder(this);
AddComponent(pfc); AddComponent(pfc);
stat.Life = 2; var stat = new Component.Stat(this)
stat.Defence = 0; {
stat.Strength = 5000; Life = 2,
stat.GetAim = 100; Defence = 0,
stat.GetDodge = 50; Strength = 5000,
GetAim = 100,
GetDodge = 50
};
AddComponent(stat);
} }
public bool Selected public bool Selected
@@ -67,9 +72,9 @@ namespace DepthsBelow
} }
} }
public static void LoadContent(Core core) public static void LoadContent()
{ {
Texture = core.Content.Load<Texture2D>("images/Monster"); Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster");
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
@@ -85,6 +90,7 @@ namespace DepthsBelow
{ {
List<Point> soldierCollisions = new List<Point>(); List<Point> soldierCollisions = new List<Point>();
// Collision with moving units
foreach (var body in Swarm) foreach (var body in Swarm)
{ {
if (body != this) if (body != this)
@@ -99,20 +105,6 @@ namespace DepthsBelow
} }
} }
foreach (var soldier in core.Squad)
{
var pathFinder = soldier.GetComponent<PathFinder>();
var position = nextNode.Position;
if (soldier.Transform.Grid == position)
{
soldierCollisions.Add(soldier.Transform.Grid);
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
nextNode = GetComponent<PathFinder>().Next();
break;
}
Utility.HitTest(this, soldier, Utility.CalculateHitChance(this, soldier));
}
if (nextNode != null) if (nextNode != null)
{ {
var nodeWorldPos = Grid.GridToWorld(nextNode.Position); var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
+22 -36
View File
@@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DepthsBelow.Component; using DepthsBelow.Component;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@@ -41,12 +42,13 @@ namespace DepthsBelow
{ {
currentStep = value; currentStep = value;
} }
} }
public Soldier(Core core, ref List<Soldier> squad) : base(core) public Soldier(EntityManager entityManager, ref List<Soldier> squad)
: base(entityManager)
{ {
if (Texture == null) if (Texture == null)
LoadContent(core); LoadContent();
this.Squad = squad; this.Squad = squad;
@@ -60,13 +62,17 @@ namespace DepthsBelow
AddComponent(cc); AddComponent(cc);
var pfc = new PathFinder(this); var pfc = new PathFinder(this);
AddComponent(pfc); AddComponent(pfc);
stat.Life = 10; var stat = new Component.Stat(this)
stat.Defence = 10; {
stat.Strength = 10; Life = 10,
stat.GetAim = 10; Defence = 10,
stat.GetDodge = 20; Strength = 10,
GetAim = 10,
GetDodge = 20
};
AddComponent(stat);
} }
public bool Selected public bool Selected
@@ -79,9 +85,9 @@ namespace DepthsBelow
} }
} }
public static void LoadContent(Core core) public static void LoadContent()
{ {
Texture = core.Content.Load<Texture2D>("images/soldier2"); Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/soldier2");
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
@@ -97,6 +103,7 @@ namespace DepthsBelow
{ {
List<Point> soldierCollisions = new List<Point>(); List<Point> soldierCollisions = new List<Point>();
// Collision with units at a standstill
foreach (var soldier in Squad) foreach (var soldier in Squad)
{ {
if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving) if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving)
@@ -104,14 +111,8 @@ namespace DepthsBelow
soldierCollisions.Add(soldier.Transform.Grid); soldierCollisions.Add(soldier.Transform.Grid);
} }
} }
foreach (var enemy in core.Swarm)
{
if (!enemy.GetComponent<PathFinder>().IsMoving)
{
soldierCollisions.Add(enemy.Transform.Grid);
}
}
// Collision with moving units
foreach (var soldier in Squad) foreach (var soldier in Squad)
{ {
if (soldier != this) if (soldier != this)
@@ -127,18 +128,6 @@ namespace DepthsBelow
} }
} }
} }
foreach (var enemy in core.Swarm)
{
var pathFinder = enemy.GetComponent<PathFinder>();
var position = nextNode.Position;
if (enemy.Transform.Grid == position)
{
soldierCollisions.Add(enemy.Transform.Grid);
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
nextNode = GetComponent<PathFinder>().Next();
break;
}
}
if (nextNode != null) if (nextNode != null)
{ {
@@ -169,10 +158,7 @@ namespace DepthsBelow
} }
} }
} }
} }
/**/
} }
} }
} }