Added back the crosshair

This commit is contained in:
2020-04-22 11:43:46 -06:00
parent 85af72cfa1
commit 042d350877
5 changed files with 28 additions and 14 deletions

View File

@@ -73,12 +73,12 @@ public class InputController : IRestrictions {
if (keyboardState.IsKeyDown(Keys.Q))
{
_cam.ZoomIn(0.05f);
_cam.ZoomIn(0.01f);
}
if (keyboardState.IsKeyDown(Keys.E))
{
_cam.ZoomOut(0.05f);
_cam.ZoomOut(0.01f);
}
}

View File

@@ -1,33 +1,47 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
namespace Collector.Character
{
public class Mouse : IRestrictions {
public class Mouse : IRestrictions
{
private SpriteBatch _spriteBatch;
private ContentManager _contentManager;
private OrthographicCamera _cam;
private Texture2D Crosshair { get; set; }
public Mouse(ContentManager contentManager, SpriteBatch spriteBatch)
public Mouse(ContentManager contentManager, SpriteBatch spriteBatch, OrthographicCamera cam)
{
_spriteBatch = spriteBatch;
_cam = cam;
_contentManager = contentManager;
Crosshair = _contentManager.Load<Texture2D>("crosshair");
}
public void Draw()
{
_spriteBatch.Draw(Crosshair, new Vector2(Player.X, Player.Y),Color.Aqua);
_spriteBatch.Draw(
Crosshair,
new Vector2(
GetSelectedX(Microsoft.Xna.Framework.Input.Mouse.GetState().X-(IRestrictions.TileSize/2f)) + (_cam.Position.X)+(IRestrictions.TileSize/2f),
GetSelectedY(Microsoft.Xna.Framework.Input.Mouse.GetState().Y-(IRestrictions.TileSize/2f)) + (_cam.Position.Y)+(IRestrictions.TileSize/2f)
),
Color.White
);
}
public int GetSelectedX(Vector3 mousePos) {
return ((int)(mousePos.X)>>4)<<4;
private static int GetSelectedX(float x)
{
return ((int) x >> 5) << 5;
}
public int GetSelectedY(Vector3 mousePos) {
return ((int)(mousePos.Y)>>4)<<4;
private static int GetSelectedY(float y)
{
return ((int) y >> 5) << 5;
}
}
}
}

View File

@@ -59,7 +59,7 @@ namespace Collector.Dimension
DrawWorld(_spriteBatch, 0);
_inputController.Draw();
DrawWorld(_spriteBatch, 1);
//mouseCrosshair(batch);
_mouse.Draw();
_inputController.PlayerInput(_main,_spriteBatch);
}
}