Skip to content

Commit

Permalink
fixes deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
triplezeta committed Aug 22, 2023
1 parent fe4e16b commit d758bb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Blocktest/BlocktestGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override void Update(GameTime gameTime)
}
else if (latch == false)
{
//buildMode = !buildMode;
buildMode = !buildMode;
latch = true;
}
MouseState currentState = Mouse.GetState();
Expand Down
26 changes: 13 additions & 13 deletions Blocktest/Code/BuildSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public static class BuildSystem
/// <param name="tilePosition">The position of the block to destroy (grid coords)</param>
public static void BreakBlockCell(bool foreground, Vector2Int tilePosition)
{
if (foreground && Globals.ForegroundTilemap.HasTile(tilePosition)) {
Tile prevTile = Globals.ForegroundTilemap.GetTile(tilePosition);
prevTile.SourceBlock.OnBreak(tilePosition, true);
Tilemap tilemap = foreground ? Globals.ForegroundTilemap : Globals.BackgroundTilemap;

if (tilemap.HasTile(tilePosition))
{
tilemap.GetTile(tilePosition).SourceBlock.OnBreak(tilePosition, true);

Globals.ForegroundTilemap.SetTile(tilePosition, null);
tilemap.SetTile(tilePosition, null);
currentWorld[tilePosition.X, tilePosition.Y, 0] = 0;
} else if (!foreground && Globals.BackgroundTilemap.HasTile(tilePosition)) {
Tile prevTile = Globals.BackgroundTilemap.GetTile(tilePosition);
prevTile.SourceBlock.OnBreak(tilePosition, false);

Globals.BackgroundTilemap.SetTile(tilePosition, null);
currentWorld[tilePosition.X, tilePosition.Y, 1] = 0;
}
else
{
return;
}

Tilemap tilemap = foreground ? Globals.ForegroundTilemap : Globals.BackgroundTilemap;

foreach (Vector2Int loc in new List<Vector2Int>() { Vector2Int.Up, Vector2Int.Down, Vector2Int.Left, Vector2Int.Right }) { // Refreshes all blocks in cardinal dirs
tilemap.GetTile(tilePosition + loc).UpdateAdjacencies(tilePosition + loc, tilemap);
if(tilemap.HasTile(tilePosition + loc)){
tilemap.GetTile(tilePosition + loc).UpdateAdjacencies(tilePosition + loc, tilemap);
}
}

}
Expand Down

0 comments on commit d758bb9

Please sign in to comment.