Added Collision component

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-09-25 20:43:11 +02:00
parent 3778d9dc2b
commit d4c5282a67
6 changed files with 41 additions and 1 deletions
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
class Collision : Component
{
public Rectangle Rectangle;
public int Width;
public int Height;
public Collision(Entity parent, int width, int height)
: base(parent)
{
this.Width = width;
this.Height = height;
this.Rectangle = new Rectangle(0, 0, width, height);
}
public void Update(GameTime gameTime)
{
PixelTransform pt = this.Parent.GetComponent<PixelTransform>();
this.Rectangle.X = (int)pt.X;
this.Rectangle.Y = (int)pt.Y;
}
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ namespace DepthsBelow
graphics.PreferredBackBufferHeight = 720;
graphics.IsFullScreen = false;
graphics.SynchronizeWithVerticalRetrace = false;
//graphics.SynchronizeWithVerticalRetrace = false;
this.IsFixedTimeStep = false;
graphics.ApplyChanges();
@@ -121,6 +121,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Camera.cs" />
<Compile Include="Component\Collision.cs" />
<Compile Include="Component\Component.cs" />
<Compile Include="Component\GridTransform.cs" />
<Compile Include="Core.cs" />
+3
View File
@@ -9,6 +9,7 @@ namespace DepthsBelow
List<Component.Component> Components;
public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform;
public Component.Collision collision;
public Entity()
{
@@ -17,6 +18,8 @@ namespace DepthsBelow
AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this);
AddComponent(gridTransform);
collision = new Component.Collision(this, 32, 32);
AddComponent(collision);
}
public T GetComponent<T>() where T : Component.Component
+4
View File
@@ -49,6 +49,10 @@ namespace DepthsBelow
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
{
/*if (selectionRectangle.Intersects())
{
}*/
selectionRectangle = Rectangle.Empty;
}
+1
View File
@@ -13,6 +13,7 @@ namespace DepthsBelow
class Soldier : Entity
{
Core game;
bool selected = false;
static Texture2D Texture;
private KeyboardState lastKeyboardState;