DrawLine part of RenderHelper

This commit is contained in:
2012-10-05 12:11:32 +02:00
parent b1f723580d
commit e89a657740
4 changed files with 237 additions and 211 deletions
+12 -6
View File
@@ -16,7 +16,7 @@ namespace DepthsBelow
/// </summary> /// </summary>
public class Core : Microsoft.Xna.Framework.Game public class Core : Microsoft.Xna.Framework.Game
{ {
GraphicsDeviceManager graphics; public static GraphicsDeviceManager GraphicsDeviceManager;
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
public Camera Camera; public Camera Camera;
@@ -26,18 +26,20 @@ namespace DepthsBelow
public List<SmallEnemy> Swarm; public List<SmallEnemy> Swarm;
public static Map Map; public static Map Map;
public SmallEnemy TestMonster;
public Core() public Core()
{ {
graphics = new GraphicsDeviceManager(this); GraphicsDeviceManager = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = 1280; GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720; GraphicsDeviceManager.PreferredBackBufferHeight = 720;
graphics.IsFullScreen = false; GraphicsDeviceManager.IsFullScreen = false;
//graphics.SynchronizeWithVerticalRetrace = false; //graphics.SynchronizeWithVerticalRetrace = false;
this.IsFixedTimeStep = false; this.IsFixedTimeStep = false;
graphics.ApplyChanges(); GraphicsDeviceManager.ApplyChanges();
this.IsMouseVisible = true; this.IsMouseVisible = true;
} }
@@ -55,6 +57,8 @@ namespace DepthsBelow
Squad = new List<Soldier>(); Squad = new List<Soldier>();
Swarm = new List<SmallEnemy>(); Swarm = new List<SmallEnemy>();
TestMonster = new SmallEnemy(this, ref Swarm);
base.Initialize(); base.Initialize();
} }
@@ -144,6 +148,8 @@ namespace DepthsBelow
// Draw mouse input visuals // Draw mouse input visuals
MouseInput.Draw(spriteBatch); MouseInput.Draw(spriteBatch);
TestMonster.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
spriteBatch.End(); spriteBatch.End();
base.Draw(gameTime); base.Draw(gameTime);
@@ -135,6 +135,7 @@
<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="SmallEnemy.cs" /> <Compile Include="SmallEnemy.cs" />
<Compile Include="Soldier.cs" /> <Compile Include="Soldier.cs" />
<Compile Include="Component\PixelTransform.cs" /> <Compile Include="Component\PixelTransform.cs" />
+2 -13
View File
@@ -144,7 +144,7 @@ namespace DepthsBelow
} }
else else
{ {
*/unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y, mouseWorldPos.X - unit.Transform.World.X);/* */unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.X);/*
}*/ }*/
//Console.WriteLine(angle); //Console.WriteLine(angle);
//unit.GetComponent<Component.Transform>().World.Rotation = angle; //unit.GetComponent<Component.Transform>().World.Rotation = angle;
@@ -170,21 +170,10 @@ namespace DepthsBelow
if (checkingDirection == true) if (checkingDirection == true)
{ {
Texture2D blank = new Texture2D(core.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); RenderHelpers.DrawLine(spriteBatch, Color.White, 2, directionStart, directionNow);
blank.SetData(new[] { Color.White });
DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow);
} }
} }
void DrawLine(SpriteBatch batch, Texture2D blank, float width, Color color, Vector2 point1, Vector2 point2)
{
float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
float length = Vector2.Distance(point1, point2);
batch.Draw(blank, point1, null, color,
angle, Vector2.Zero, new Vector2(length, width),
SpriteEffects.None, 0);
}
} }
} }
+30
View File
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace DepthsBelow
{
static class RenderHelpers
{
static Texture2D blank;
public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end)
{
if (blank == null)
{
blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
blank.SetData(new[] { color });
}
float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X);
float length = Vector2.Distance(start, end);
batch.Draw(blank, start, null, color,
angle, Vector2.Zero, new Vector2(length, width),
SpriteEffects.None, 0);
}
}
}