From d758bb9cf8233813c9d1694f14869119c2175a78 Mon Sep 17 00:00:00 2001 From: Zeta Date: Tue, 22 Aug 2023 13:24:52 -0600 Subject: [PATCH] fixes deletion --- Blocktest/BlocktestGame.cs | 2 +- Blocktest/Code/BuildSystem.cs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Blocktest/BlocktestGame.cs b/Blocktest/BlocktestGame.cs index 945e042..a40257d 100644 --- a/Blocktest/BlocktestGame.cs +++ b/Blocktest/BlocktestGame.cs @@ -67,7 +67,7 @@ protected override void Update(GameTime gameTime) } else if (latch == false) { - //buildMode = !buildMode; + buildMode = !buildMode; latch = true; } MouseState currentState = Mouse.GetState(); diff --git a/Blocktest/Code/BuildSystem.cs b/Blocktest/Code/BuildSystem.cs index 703d1aa..a822f0f 100644 --- a/Blocktest/Code/BuildSystem.cs +++ b/Blocktest/Code/BuildSystem.cs @@ -21,24 +21,24 @@ public static class BuildSystem /// The position of the block to destroy (grid coords) 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.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); + } } }