From fe4e16b11249394eceff7670eed400b7da2a1878 Mon Sep 17 00:00:00 2001 From: Zeta Date: Tue, 22 Aug 2023 12:23:45 -0600 Subject: [PATCH] extremely rudimentary tile selection --- Blocktest/BlocktestGame.cs | 62 ++++++++++++++++++++++---- Blocktest/Code/Block System/Tilemap.cs | 4 +- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Blocktest/BlocktestGame.cs b/Blocktest/BlocktestGame.cs index c2e76e5..945e042 100644 --- a/Blocktest/BlocktestGame.cs +++ b/Blocktest/BlocktestGame.cs @@ -8,6 +8,11 @@ public class BlocktestGame : Game { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; + bool latch = false; //latch for button pressing + private bool latchBlockSelect = false; + bool buildMode = true; //true for build, false for destroy + private int blockSelected = 0; + /// public BlocktestGame() @@ -56,16 +61,57 @@ protected override void Update(GameTime gameTime) Exit(); } + if (Keyboard.GetState().IsKeyUp(Keys.E)) + { + latch = false; + } + else if (latch == false) + { + //buildMode = !buildMode; + latch = true; + } MouseState currentState = Mouse.GetState(); - if (currentState.LeftButton == ButtonState.Pressed) + + if (Keyboard.GetState().IsKeyUp(Keys.Q)) + { + latchBlockSelect = false; + } + else if (latchBlockSelect == false) + { + blockSelected++; + if (blockSelected >= BlockManager.AllBlocks.Length) + { + blockSelected = 0; + } + + latchBlockSelect = true; + } + + if (buildMode) + { + if(currentState.LeftButton == ButtonState.Pressed) + { + BuildSystem.PlaceBlockCell(BlockManager.AllBlocks[blockSelected], true, + new Vector2Int(MathHelper.Clamp(currentState.X / Globals.gridSize.X, 0, Globals.maxX), + MathHelper.Clamp(currentState.Y / Globals.gridSize.Y, 0, Globals.maxY))); + } else if (currentState.RightButton == ButtonState.Pressed) { + BuildSystem.PlaceBlockCell(BlockManager.AllBlocks[blockSelected], false, + new Vector2Int(MathHelper.Clamp(currentState.X / Globals.gridSize.X, 0, Globals.maxX), + MathHelper.Clamp(currentState.Y / Globals.gridSize.Y, 0, Globals.maxY))); + } + } + else { - BuildSystem.PlaceBlockCell(BlockManager.AllBlocks[0], true, - new Vector2(MathHelper.Clamp(currentState.X / Globals.gridSize.X, 0, Globals.maxX), - MathHelper.Clamp(currentState.Y / Globals.gridSize.Y, 0, Globals.maxY))); - } else if (currentState.RightButton == ButtonState.Pressed) { - BuildSystem.PlaceBlockCell(BlockManager.AllBlocks[0], false, - new Vector2(MathHelper.Clamp(currentState.X / Globals.gridSize.X, 0, Globals.maxX), - MathHelper.Clamp(currentState.Y / Globals.gridSize.Y, 0, Globals.maxY))); + if(currentState.LeftButton == ButtonState.Pressed) + { + BuildSystem.BreakBlockCell( true, + new Vector2Int(MathHelper.Clamp(currentState.X / Globals.gridSize.X, 0, Globals.maxX), + MathHelper.Clamp(currentState.Y / Globals.gridSize.Y, 0, Globals.maxY))); + } else if (currentState.RightButton == ButtonState.Pressed) { + BuildSystem.BreakBlockCell( false, + new Vector2Int(MathHelper.Clamp(currentState.X / Globals.gridSize.X, 0, Globals.maxX), + MathHelper.Clamp(currentState.Y / Globals.gridSize.Y, 0, Globals.maxY))); + } } base.Update(gameTime); diff --git a/Blocktest/Code/Block System/Tilemap.cs b/Blocktest/Code/Block System/Tilemap.cs index a640384..1654cc3 100644 --- a/Blocktest/Code/Block System/Tilemap.cs +++ b/Blocktest/Code/Block System/Tilemap.cs @@ -183,10 +183,10 @@ public void UpdateAdjacencies(Vector2Int position, Tilemap tilemap) int bitmask = 0; // Using bitmask smoothing, look it up if (HasSmoothableTile(position + Vector2Int.Up, tilemap)) { - bitmask += 1; + bitmask += 2; } if (HasSmoothableTile(position + Vector2Int.Down, tilemap)) { - bitmask += 2; + bitmask += 1; } if (HasSmoothableTile(position + Vector2Int.Right, tilemap)) { bitmask += 4;