Did stuff
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DepthsBelow
|
||||
namespace DepthsBelow.Component
|
||||
{
|
||||
public class Component
|
||||
{
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DepthsBelow.Component
|
||||
{
|
||||
public class GridTransform : Component
|
||||
{
|
||||
public Vector2 Position;
|
||||
public float X
|
||||
{
|
||||
get
|
||||
{
|
||||
return Position.X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Position.X = X;
|
||||
}
|
||||
}
|
||||
public float Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return Position.Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Position.Y = Y;
|
||||
}
|
||||
}
|
||||
|
||||
public GridTransform(Entity parent) : base(parent)
|
||||
{
|
||||
Position = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DepthsBelow.Component
|
||||
{
|
||||
public class PixelTransform : Component
|
||||
{
|
||||
public Vector2 Position;
|
||||
public float X
|
||||
{
|
||||
get
|
||||
{
|
||||
return Position.X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Position.X = X;
|
||||
}
|
||||
}
|
||||
public float Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return Position.Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Position.Y = Y;
|
||||
}
|
||||
}
|
||||
public float Rotation;
|
||||
public Point Origin;
|
||||
|
||||
public PixelTransform(Entity parent)
|
||||
: base(parent)
|
||||
{
|
||||
Position = Vector2.Zero;
|
||||
Rotation = 0.0f;
|
||||
Origin = Point.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace DepthsBelow.Component
|
||||
{
|
||||
public class SpriteRenderer : Component
|
||||
{
|
||||
public Texture2D Texture;
|
||||
public Color Color;
|
||||
|
||||
public SpriteRenderer(Entity parent) : base(parent)
|
||||
{
|
||||
this.Color = Color.White;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
PixelTransform tc = this.Parent.GetComponent<PixelTransform>();
|
||||
spriteBatch.Draw(Texture, tc.Position, this.Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace DepthsBelow
|
||||
|
||||
graphics.PreferredBackBufferWidth = 1280;
|
||||
graphics.PreferredBackBufferHeight = 720;
|
||||
graphics.IsFullScreen = false;
|
||||
graphics.IsFullScreen = true;
|
||||
|
||||
this.IsMouseVisible = true;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace DepthsBelow
|
||||
|
||||
// TODO: Add your drawing code here
|
||||
spriteBatch.Begin();
|
||||
SpriteRenderComponent rc = soldier.GetComponent<SpriteRenderComponent>();
|
||||
Component.SpriteRenderer rc = soldier.GetComponent<Component.SpriteRenderer>();
|
||||
if (rc != null)
|
||||
rc.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
|
||||
@@ -120,14 +120,15 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Component.cs" />
|
||||
<Compile Include="Component\Component.cs" />
|
||||
<Compile Include="Component\GridTransform.cs" />
|
||||
<Compile Include="Core.cs" />
|
||||
<Compile Include="Entity.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="RenderComponent.cs" />
|
||||
<Compile Include="Component\SpriteRenderer.cs" />
|
||||
<Compile Include="Soldier.cs" />
|
||||
<Compile Include="TransformComponent.cs" />
|
||||
<Compile Include="Component\PixelTransform.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Game.ico" />
|
||||
|
||||
@@ -2,22 +2,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class Entity
|
||||
{
|
||||
List<Component> Components;
|
||||
public TransformComponent transform;
|
||||
List<Component.Component> Components;
|
||||
public Component.PixelTransform pixelTransform;
|
||||
public Component.GridTransform gridTransform;
|
||||
|
||||
public Entity()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Components = new List<Component.Component>();
|
||||
pixelTransform = new Component.PixelTransform(this);
|
||||
AddComponent(pixelTransform);
|
||||
gridTransform = new Component.GridTransform(this);
|
||||
AddComponent(gridTransform);
|
||||
}
|
||||
|
||||
public T GetComponent<T>() where T : Component
|
||||
public T GetComponent<T>() where T : Component.Component
|
||||
{
|
||||
foreach (Component c in Components)
|
||||
foreach (Component.Component c in Components)
|
||||
{
|
||||
if (c is T)
|
||||
return (T)c;
|
||||
@@ -26,12 +30,9 @@ namespace DepthsBelow
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddComponent(Component c)
|
||||
public void AddComponent(Component.Component c)
|
||||
{
|
||||
Components.Add(c);
|
||||
|
||||
if (c is TransformComponent)
|
||||
this.transform =(TransformComponent)c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
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 SpriteRenderComponent : Component
|
||||
{
|
||||
public Texture2D Texture;
|
||||
|
||||
public SpriteRenderComponent(Entity parent) : base(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
TransformComponent tc = this.Parent.GetComponent<TransformComponent>();
|
||||
spriteBatch.Draw(Texture, tc.Position, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ namespace DepthsBelow
|
||||
Core game;
|
||||
static Texture2D Texture;
|
||||
|
||||
private KeyboardState lastKeyboardState;
|
||||
|
||||
static public void LoadContent(Core game)
|
||||
{
|
||||
Texture = game.Content.Load<Texture2D>("images/soldier");
|
||||
@@ -25,18 +27,24 @@ namespace DepthsBelow
|
||||
if (Texture == null)
|
||||
LoadContent(game);
|
||||
|
||||
SpriteRenderComponent rc = new SpriteRenderComponent(this);
|
||||
Component.SpriteRenderer rc = new Component.SpriteRenderer(this);
|
||||
rc.Texture = Texture;
|
||||
rc.Color = Color.HotPink;
|
||||
this.AddComponent(rc);
|
||||
|
||||
this.AddComponent(new TransformComponent(this));
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
KeyboardState ks = Keyboard.GetState();
|
||||
if (ks.IsKeyDown(Keys.Left))
|
||||
transform.Position.X--;
|
||||
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
|
||||
gridTransform.Position.X += 1;
|
||||
lastKeyboardState = ks;
|
||||
|
||||
Console.WriteLine(pixelTransform.X + " " + gridTransform.X);
|
||||
if (pixelTransform.Position.X < gridTransform.X * 32)
|
||||
{
|
||||
pixelTransform.Position.X += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class TransformComponent : Component
|
||||
{
|
||||
public Vector2 Position;
|
||||
public float Rotation;
|
||||
public Point Origin;
|
||||
|
||||
public TransformComponent(Entity parent) : base(parent)
|
||||
{
|
||||
Position = Vector2.Zero;
|
||||
Rotation = 0.0f;
|
||||
Origin = Point.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="images\soldier.bmp">
|
||||
<Compile Include="images\soldier.png">
|
||||
<Name>soldier</Name>
|
||||
<Importer>TextureImporter</Importer>
|
||||
<Processor>TextureProcessor</Processor>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 405 B |
Reference in New Issue
Block a user