DrawLine part of RenderHelper
This commit is contained in:
@@ -16,7 +16,7 @@ namespace DepthsBelow
|
||||
/// </summary>
|
||||
public class Core : Microsoft.Xna.Framework.Game
|
||||
{
|
||||
GraphicsDeviceManager graphics;
|
||||
public static GraphicsDeviceManager GraphicsDeviceManager;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
public Camera Camera;
|
||||
@@ -26,18 +26,20 @@ namespace DepthsBelow
|
||||
public List<SmallEnemy> Swarm;
|
||||
public static Map Map;
|
||||
|
||||
public SmallEnemy TestMonster;
|
||||
|
||||
public Core()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||
Content.RootDirectory = "Content";
|
||||
|
||||
graphics.PreferredBackBufferWidth = 1280;
|
||||
graphics.PreferredBackBufferHeight = 720;
|
||||
graphics.IsFullScreen = false;
|
||||
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
||||
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
||||
GraphicsDeviceManager.IsFullScreen = false;
|
||||
|
||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
||||
this.IsFixedTimeStep = false;
|
||||
graphics.ApplyChanges();
|
||||
GraphicsDeviceManager.ApplyChanges();
|
||||
|
||||
this.IsMouseVisible = true;
|
||||
}
|
||||
@@ -55,6 +57,8 @@ namespace DepthsBelow
|
||||
Squad = new List<Soldier>();
|
||||
Swarm = new List<SmallEnemy>();
|
||||
|
||||
TestMonster = new SmallEnemy(this, ref Swarm);
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
@@ -144,6 +148,8 @@ namespace DepthsBelow
|
||||
// Draw mouse input visuals
|
||||
MouseInput.Draw(spriteBatch);
|
||||
|
||||
TestMonster.GetComponent<Component.SpriteRenderer>().Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Component\SpriteRenderer.cs" />
|
||||
<Compile Include="RenderHelpers.cs" />
|
||||
<Compile Include="SmallEnemy.cs" />
|
||||
<Compile Include="Soldier.cs" />
|
||||
<Compile Include="Component\PixelTransform.cs" />
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace DepthsBelow
|
||||
}
|
||||
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);
|
||||
//unit.GetComponent<Component.Transform>().World.Rotation = angle;
|
||||
@@ -170,21 +170,10 @@ namespace DepthsBelow
|
||||
|
||||
if (checkingDirection == true)
|
||||
{
|
||||
Texture2D blank = new Texture2D(core.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
|
||||
blank.SetData(new[] { Color.White });
|
||||
DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow);
|
||||
RenderHelpers.DrawLine(spriteBatch, Color.White, 2, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+30
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user