From 313167e2a31a40058315a315fc9b813cf3da6a7c Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Thu, 27 Sep 2012 19:10:10 +0200 Subject: [PATCH] Added Grid, Inserted gridRectangle --- DepthsBelow/DepthsBelow/Core.cs | 3 ++ DepthsBelow/DepthsBelow/DepthsBelow.csproj | 1 + DepthsBelow/DepthsBelow/Grid.cs | 33 ++++++++++++++++++++++ DepthsBelow/DepthsBelow/MouseInput.cs | 12 ++++++++ 4 files changed, 49 insertions(+) create mode 100644 DepthsBelow/DepthsBelow/Grid.cs diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index 752f8e9..5f538a6 100644 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -22,6 +22,7 @@ namespace DepthsBelow public Camera camera; MouseInput mouseInput; public Soldier soldier; + public Grid GridChecker; private Map map; public Core() @@ -68,6 +69,8 @@ namespace DepthsBelow Soldier.LoadContent(this); soldier = new Soldier(this); + GridChecker = new Grid(); + mouseInput = new MouseInput(this); mouseInput.LoadContent(); } diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj index 7679bfa..6ba8661 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -121,6 +121,7 @@ + diff --git a/DepthsBelow/DepthsBelow/Grid.cs b/DepthsBelow/DepthsBelow/Grid.cs new file mode 100644 index 0000000..2fc0fce --- /dev/null +++ b/DepthsBelow/DepthsBelow/Grid.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace DepthsBelow +{ + public class Grid + { + public const int TilePixelSize = 32; + public int TileSize() { return TilePixelSize; } + /*public Vector2 GridToScreen(Vector2 gridPos); + public Vector2 ScreenToGrid(Vector2 screenPos);*/ + + public Vector2 GridToScreen; + public Vector2 ScreenToGrid; + + public Grid() + { + + } + + public Vector2 FindScreenPos(Vector2 gridPos) + { + return gridPos * TileSize(); + } + public Vector2 FindGridPos(Vector2 screenPos) + { + return screenPos / TileSize(); + } + } +} diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 40a3c22..b207ee0 100644 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -17,6 +17,9 @@ namespace DepthsBelow Rectangle selectionRectangle; Texture2D selectionTexture; + Rectangle gridRectangle; + Texture2D gridTexture; + public MouseInput(Core core) { this.core = core; @@ -28,6 +31,9 @@ namespace DepthsBelow { selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); selectionTexture.SetData(new Color[] { Color.White }); + + gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); + gridTexture.SetData(new Color[] { Color.White }); } public void Update(GameTime gameTime) @@ -60,12 +66,18 @@ namespace DepthsBelow selectionRectangle = Rectangle.Empty; } + Vector2 currentGrid = core.GridChecker.FindGridPos(new Vector2(ms.X + core.camera.Position.X - core.GridChecker.TileSize() / 2, ms.Y + core.camera.Position.Y - core.GridChecker.TileSize() / 2)); + currentGrid.X = Convert.ToInt32(currentGrid.X); + currentGrid.Y = Convert.ToInt32(currentGrid.Y); + Vector2 currentScreen = core.GridChecker.FindScreenPos(currentGrid); + gridRectangle = new Rectangle((int)currentScreen.X, (int)currentScreen.Y, core.GridChecker.TileSize(), core.GridChecker.TileSize()); lastMouseState = ms; } public void Draw(SpriteBatch spriteBatch) { + spriteBatch.Draw(gridTexture, gridRectangle, Color.Yellow * 0.3f); spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f); } }