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

@@ -38,7 +38,7 @@ namespace Collector
_cam.LookAt(new Vector2(Player.X,Player.Y)); _cam.LookAt(new Vector2(Player.X,Player.Y));
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
_mouse = new Mouse(Content,_spriteBatch); _mouse = new Mouse(Content,_spriteBatch,_cam);
_inputController = new InputController(_player,_mouse,_cam,_spriteBatch,Content); _inputController = new InputController(_player,_mouse,_cam,_spriteBatch,Content);
WorldRenderer = new WorldRenderer(_mouse,_inputController,_player,_spriteBatch,this,_cam); WorldRenderer = new WorldRenderer(_mouse,_inputController,_player,_spriteBatch,this,_cam);
} }

View File

@@ -10,7 +10,7 @@ public interface Restrictions {
int FREE_SPEED = 2; int FREE_SPEED = 2;
int KEY_DELAY = 0; int KEY_DELAY = 0;
int TILE_SIZE = 16; int TILE_SIZE = 32;
int CHUNK_SIZE = 8; int CHUNK_SIZE = 8;
int SUPER_CHUNK_SIZE = 1; int SUPER_CHUNK_SIZE = 1;

View File

@@ -73,12 +73,12 @@ public class InputController : IRestrictions {
if (keyboardState.IsKeyDown(Keys.Q)) if (keyboardState.IsKeyDown(Keys.Q))
{ {
_cam.ZoomIn(0.05f); _cam.ZoomIn(0.01f);
} }
if (keyboardState.IsKeyDown(Keys.E)) 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;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
namespace Collector.Character namespace Collector.Character
{ {
public class Mouse : IRestrictions { public class Mouse : IRestrictions
{
private SpriteBatch _spriteBatch; private SpriteBatch _spriteBatch;
private ContentManager _contentManager; private ContentManager _contentManager;
private OrthographicCamera _cam;
private Texture2D Crosshair { get; set; } private Texture2D Crosshair { get; set; }
public Mouse(ContentManager contentManager, SpriteBatch spriteBatch) public Mouse(ContentManager contentManager, SpriteBatch spriteBatch, OrthographicCamera cam)
{ {
_spriteBatch = spriteBatch; _spriteBatch = spriteBatch;
_cam = cam;
_contentManager = contentManager; _contentManager = contentManager;
Crosshair = _contentManager.Load<Texture2D>("crosshair"); Crosshair = _contentManager.Load<Texture2D>("crosshair");
} }
public void Draw() 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) { private static int GetSelectedX(float x)
return ((int)(mousePos.X)>>4)<<4; {
return ((int) x >> 5) << 5;
} }
public int GetSelectedY(Vector3 mousePos) { private static int GetSelectedY(float y)
return ((int)(mousePos.Y)>>4)<<4; {
return ((int) y >> 5) << 5;
} }
} }
} }

View File

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