Skip to content

Commit

Permalink
extremely rudimentary tile selection
Browse files Browse the repository at this point in the history
  • Loading branch information
triplezeta committed Aug 22, 2023
1 parent 001e1ff commit fe4e16b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
62 changes: 54 additions & 8 deletions Blocktest/BlocktestGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/// <inheritdoc />
public BlocktestGame()
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Blocktest/Code/Block System/Tilemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fe4e16b

Please sign in to comment.