Static is fun!

This commit is contained in:
Simon Holmberg
2012-09-27 19:26:31 +02:00
parent 313167e2a3
commit 832ef9d850
3 changed files with 15 additions and 32 deletions
-3
View File
@@ -22,7 +22,6 @@ namespace DepthsBelow
public Camera camera;
MouseInput mouseInput;
public Soldier soldier;
public Grid GridChecker;
private Map map;
public Core()
@@ -69,8 +68,6 @@ namespace DepthsBelow
Soldier.LoadContent(this);
soldier = new Soldier(this);
GridChecker = new Grid();
mouseInput = new MouseInput(this);
mouseInput.LoadContent();
}
+11 -26
View File
@@ -1,33 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
namespace DepthsBelow
{
public class Grid
public static class Grid
{
public const int TilePixelSize = 32;
public int TileSize() { return TilePixelSize; }
/*public Vector2 GridToScreen(Vector2 gridPos);
public Vector2 ScreenToGrid(Vector2 screenPos);*/
public const int TileSize = 32;
public Vector2 GridToScreen;
public Vector2 ScreenToGrid;
public Grid()
{
}
public Vector2 FindScreenPos(Vector2 gridPos)
{
return gridPos * TileSize();
}
public Vector2 FindGridPos(Vector2 screenPos)
{
return screenPos / TileSize();
}
public static Vector2 GridToScreen(Vector2 gridPos)
{
return gridPos * TileSize;
}
public static Vector2 ScreenToGrid(Vector2 screenPos)
{
return screenPos / TileSize;
}
}
}
+4 -3
View File
@@ -66,11 +66,12 @@ 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));
Vector2 currentGrid = Grid.ScreenToGrid(new Vector2(ms.X + core.camera.Position.X - Grid.TileSize / 2, ms.Y + core.camera.Position.Y - Grid.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());
Vector2 currentScreen = Grid.GridToScreen(currentGrid);
gridRectangle = new Rectangle((int)currentScreen.X, (int)currentScreen.Y, Grid.TileSize, Grid.TileSize;
lastMouseState = ms;
}