Experimental selection code
This commit is contained in:
@@ -7,7 +7,7 @@ using Microsoft.Xna.Framework.Input;
|
|||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
class Camera
|
public class Camera
|
||||||
{
|
{
|
||||||
public float Zoom;
|
public float Zoom;
|
||||||
public Matrix Transform;
|
public Matrix Transform;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace DepthsBelow
|
|||||||
GraphicsDeviceManager graphics;
|
GraphicsDeviceManager graphics;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
|
|
||||||
Camera camera;
|
public Camera camera;
|
||||||
|
MouseControl mouse;
|
||||||
Soldier soldier;
|
Soldier soldier;
|
||||||
|
|
||||||
public Core()
|
public Core()
|
||||||
@@ -59,6 +60,9 @@ namespace DepthsBelow
|
|||||||
// 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(this);
|
||||||
soldier = new Soldier(this);
|
soldier = new Soldier(this);
|
||||||
|
|
||||||
|
mouse = new MouseControl(this);
|
||||||
|
mouse.LoadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -82,6 +86,7 @@ namespace DepthsBelow
|
|||||||
this.Exit();
|
this.Exit();
|
||||||
|
|
||||||
camera.Update(gameTime);
|
camera.Update(gameTime);
|
||||||
|
mouse.Update(gameTime);
|
||||||
|
|
||||||
// TODO: Add your update logic here
|
// TODO: Add your update logic here
|
||||||
soldier.Update(gameTime);
|
soldier.Update(gameTime);
|
||||||
@@ -104,6 +109,8 @@ namespace DepthsBelow
|
|||||||
if (rc != null)
|
if (rc != null)
|
||||||
rc.Draw(spriteBatch);
|
rc.Draw(spriteBatch);
|
||||||
|
|
||||||
|
mouse.Draw(spriteBatch);
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
|
|||||||
@@ -125,6 +125,7 @@
|
|||||||
<Compile Include="Component\GridTransform.cs" />
|
<Compile Include="Component\GridTransform.cs" />
|
||||||
<Compile Include="Core.cs" />
|
<Compile Include="Core.cs" />
|
||||||
<Compile Include="Entity.cs" />
|
<Compile Include="Entity.cs" />
|
||||||
|
<Compile Include="MouseControl.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" />
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using Microsoft.Xna.Framework.Media;
|
||||||
|
|
||||||
|
namespace DepthsBelow
|
||||||
|
{
|
||||||
|
class MouseControl
|
||||||
|
{
|
||||||
|
Core core;
|
||||||
|
MouseState lastMouseState;
|
||||||
|
Rectangle selectionRectangle;
|
||||||
|
Texture2D selectionTexture;
|
||||||
|
|
||||||
|
public MouseControl(Core core)
|
||||||
|
{
|
||||||
|
this.core = core;
|
||||||
|
|
||||||
|
selectionRectangle = Rectangle.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadContent()
|
||||||
|
{
|
||||||
|
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
|
||||||
|
selectionTexture.SetData(new Color[] { Color.White });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
MouseState ms = Mouse.GetState();
|
||||||
|
|
||||||
|
if (ms.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (selectionRectangle == Rectangle.Empty)
|
||||||
|
{
|
||||||
|
selectionRectangle = new Rectangle(ms.X + (int)core.camera.Position.X, ms.Y + (int)core.camera.Position.Y, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectionRectangle.Width = ms.X - selectionRectangle.X + (int)core.camera.Position.X;
|
||||||
|
selectionRectangle.Height = ms.Y - selectionRectangle.Y + (int)core.camera.Position.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
|
||||||
|
{
|
||||||
|
selectionRectangle = Rectangle.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastMouseState = ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user