Going to start using Wang tiles

This commit is contained in:
2020-07-01 10:37:52 -06:00
parent f31e1c3da3
commit 3cf42a3c83
15 changed files with 44 additions and 47 deletions

View File

@@ -18,19 +18,20 @@ namespace Collector.Character
private int _frameNumber;
private float _timeSinceLastFrame;
private readonly Main _main;
private readonly Chunks _chunks;
private readonly World _world;
private readonly Player _player;
private readonly PlayerMouse _playerMouse;
public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager, Main main, Chunks chunks, Player player)
public InputController(OrthographicCamera cam, SpriteBatch spriteBatch, ContentManager contentManager, Main main, World world, Player player, PlayerMouse playerMouse)
{
Input = "Down";
_cam = cam;
_spriteBatch = spriteBatch;
_main = main;
_chunks = chunks;
_world = world;
_player = player;
_playerMouse = playerMouse;
_frameNumber = 0;
_texture = contentManager.Load<Texture2D>("man");
const int tileSize = 32;
@@ -169,7 +170,7 @@ namespace Collector.Character
}
if (mouseState.LeftButton == ButtonState.Pressed)
{
_chunks.RemoveBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY());
_world.RemoveBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY());
}
if (mouseState.RightButton == ButtonState.Pressed)
{
@@ -179,7 +180,7 @@ namespace Collector.Character
private void PlaceSelectedBlock(Blocks selectedItem)
{
_chunks.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
_world.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
}
private void UpdateAnimationFrame(GameTime gameTime)

View File

@@ -8,7 +8,11 @@ public class Inventory {
public static Blocks GetSelectedItem()
{
return (Blocks) Gui._combo.SelectedIndex.Value;
if (Gui._combo.SelectedIndex != null) return (Blocks) Gui._combo.SelectedIndex.Value;
else
{
return Blocks.BlockAir;
}
}
public LinkedList<ItemStack> GetInventory() {

View File

@@ -11,26 +11,26 @@ namespace Collector.Character
public static float X { get; private set; }
public static float Y { get; private set; }
private RectangleF _playerBounds;
private Chunks _chunks { get; }
private World World { get; }
public Player(int x, int y, Chunks chunks)
public Player(int x, int y, World world)
{
X = x;
Y = y;
_chunks = chunks;
World = world;
_playerBounds = new RectangleF(x, y, IRestrictions.TileSize * 0.5f, IRestrictions.TileSize * 0.35f);
}
public void Move(OrthographicCamera cam, float x, float y)
{
Teleport(cam, x, 0);
if (_chunks.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(_playerBounds)))
if (World.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(_playerBounds)))
{
Teleport(cam, -x, 0);
}
Teleport(cam, 0, y);
if (_chunks.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(_playerBounds)))
if (World.LoadedCollisions.Values.Any(collisionsValue => collisionsValue.Rectangle.Intersects(_playerBounds)))
{
Teleport(cam, 0, -y);
}