Added Grid, Inserted gridRectangle

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-09-27 19:10:10 +02:00
parent 0bcc4503ea
commit 313167e2a3
4 changed files with 49 additions and 0 deletions
+3
View File
@@ -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();
}
@@ -121,6 +121,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Camera.cs" />
<Compile Include="Grid.cs" />
<Compile Include="Component\Collision.cs" />
<Compile Include="Component\Component.cs" />
<Compile Include="Component\GridTransform.cs" />
+33
View File
@@ -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();
}
}
}
+12
View File
@@ -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);
}
}