Experimental selection code
This commit is contained in:
@@ -7,7 +7,7 @@ using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
class Camera
|
||||
public class Camera
|
||||
{
|
||||
public float Zoom;
|
||||
public Matrix Transform;
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace DepthsBelow
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
|
||||
Camera camera;
|
||||
public Camera camera;
|
||||
MouseControl mouse;
|
||||
Soldier soldier;
|
||||
|
||||
public Core()
|
||||
@@ -59,6 +60,9 @@ namespace DepthsBelow
|
||||
// TODO: use this.Content to load your game content here
|
||||
Soldier.LoadContent(this);
|
||||
soldier = new Soldier(this);
|
||||
|
||||
mouse = new MouseControl(this);
|
||||
mouse.LoadContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,6 +86,7 @@ namespace DepthsBelow
|
||||
this.Exit();
|
||||
|
||||
camera.Update(gameTime);
|
||||
mouse.Update(gameTime);
|
||||
|
||||
// TODO: Add your update logic here
|
||||
soldier.Update(gameTime);
|
||||
@@ -104,6 +109,8 @@ namespace DepthsBelow
|
||||
if (rc != null)
|
||||
rc.Draw(spriteBatch);
|
||||
|
||||
mouse.Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
<Compile Include="Component\GridTransform.cs" />
|
||||
<Compile Include="Core.cs" />
|
||||
<Compile Include="Entity.cs" />
|
||||
<Compile Include="MouseControl.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Program.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