mirror of
https://github.com/zoriya/Goulag-Prototype.git
synced 2026-05-29 17:02:00 +00:00
Update Assets/Script/EnvironementManager.cs
This commit is contained in:
@@ -21,6 +21,7 @@ public class EnvironementManager : MonoBehaviour
|
||||
{
|
||||
tilemap.SetTile(pos, null);
|
||||
|
||||
//Check directly affected tiles
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x - 1, pos.y, pos.z)) != null && !BlockIsStable(new Vector3Int(pos.x - 1, pos.y, pos.z)))
|
||||
{
|
||||
BreakTile(new Vector3Int(pos.x - 1, pos.y, pos.z));
|
||||
@@ -41,65 +42,93 @@ public class EnvironementManager : MonoBehaviour
|
||||
BreakTile(new Vector3Int(pos.x, pos.y - 1, pos.z));
|
||||
SpawnFallingBlock(new Vector3Int(pos.x, pos.y - 1, pos.z));
|
||||
}
|
||||
|
||||
//Check tiles affected by weight
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x - 3, pos.y + 1, pos.z)) != null && !BlockIsStable(new Vector3Int(pos.x - 3, pos.y + 1, pos.z)))
|
||||
{
|
||||
BreakTile(new Vector3Int(pos.x - 3, pos.y + 1, pos.z));
|
||||
SpawnFallingBlock(new Vector3Int(pos.x - 3, pos.y + 1, pos.z));
|
||||
}
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x + 3, pos.y + 1, pos.z)) != null && !BlockIsStable(new Vector3Int(pos.x + 3, pos.y + 1, pos.z)))
|
||||
{
|
||||
BreakTile(new Vector3Int(pos.x + 3, pos.y + 1, pos.z));
|
||||
SpawnFallingBlock(new Vector3Int(pos.x + 3, pos.y + 1, pos.z));
|
||||
}
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x, pos.y - 3, pos.z)) != null && !BlockIsStable(new Vector3Int(pos.x, pos.y - 3, pos.z)))
|
||||
{
|
||||
BreakTile(new Vector3Int(pos.x, pos.y - 3, pos.z));
|
||||
SpawnFallingBlock(new Vector3Int(pos.x, pos.y - 3, pos.z));
|
||||
}
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x - 1, pos.y - 3, pos.z)) != null && !BlockIsStable(new Vector3Int(pos.x - 1, pos.y - 3, pos.z)))
|
||||
{
|
||||
BreakTile(new Vector3Int(pos.x - 1, pos.y - 3, pos.z));
|
||||
SpawnFallingBlock(new Vector3Int(pos.x - 1, pos.y - 3, pos.z));
|
||||
}
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x + 1, pos.y - 3, pos.z)) != null && !BlockIsStable(new Vector3Int(pos.x + 1, pos.y - 3, pos.z)))
|
||||
{
|
||||
BreakTile(new Vector3Int(pos.x + 1, pos.y - 3, pos.z));
|
||||
SpawnFallingBlock(new Vector3Int(pos.x + 1, pos.y - 3, pos.z));
|
||||
}
|
||||
}
|
||||
|
||||
bool BlockIsStable(Vector3Int pos, bool checkedBottom = false, bool checkedTop = false, bool checkedLeft = false, bool checkedRight = false, int loopUnder = 0, int loopTop = 0, int loopLeft = 0, int loopRight = 0)
|
||||
{
|
||||
if (!checkedBottom && BlockStableUnder(pos, loopUnder))
|
||||
if (!checkedBottom && BlockStableUnder(pos, checkedLeft, checkedRight, loopUnder))
|
||||
return true;
|
||||
|
||||
if (!checkedLeft && BlockStableLeft(pos, checkedBottom, loopLeft))
|
||||
if (!checkedLeft && BlockStableLeft(pos, checkedBottom, checkedTop, loopLeft))
|
||||
return true;
|
||||
|
||||
if (!checkedRight && BlockStableRight(pos, checkedBottom, loopRight))
|
||||
if (!checkedRight && BlockStableRight(pos, checkedBottom, checkedTop, loopRight))
|
||||
return true;
|
||||
|
||||
if (!checkedTop && BlockStableTop(pos, loopTop))
|
||||
if (!checkedTop && BlockStableTop(pos, checkedLeft, checkedRight, loopTop))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BlockStableUnder(Vector3Int pos, int loop)
|
||||
bool BlockStableUnder(Vector3Int pos, bool checkedLeft, bool checkedRight, int loop)
|
||||
{
|
||||
if (tilemap.GetTile(pos) == imuable)
|
||||
return true;
|
||||
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x, pos.y - 1, pos.z)) != null && (loop > 0 || BlockIsStable(new Vector3Int(pos.x, pos.y - 1, pos.z), false, true, false, false, loop + 1)))
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x, pos.y - 1, pos.z)) != null && (loop > 0 || BlockIsStable(new Vector3Int(pos.x, pos.y - 1, pos.z), false, true, checkedLeft, checkedRight, loop + 1)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BlockStableLeft(Vector3Int pos, bool checkedUnder, int loop)
|
||||
bool BlockStableLeft(Vector3Int pos, bool checkedUnder, bool checkedTop, int loop)
|
||||
{
|
||||
if (tilemap.GetTile(pos) == imuable)
|
||||
return true;
|
||||
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x - 1, pos.y, pos.z)) != null && loop < 3 && BlockIsStable(new Vector3Int(pos.x - 1, pos.y, pos.z), checkedUnder, false, false, true, 0, 0, loop + 1, 0))
|
||||
if (loop < 3 && tilemap.GetTile(new Vector3Int(pos.x - 1, pos.y, pos.z)) != null && BlockIsStable(new Vector3Int(pos.x - 1, pos.y, pos.z), checkedUnder, checkedTop, false, true, 0, 0, loop + 1, 0))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BlockStableRight(Vector3Int pos, bool checkedUnder, int loop)
|
||||
bool BlockStableRight(Vector3Int pos, bool checkedUnder, bool checkedTop, int loop)
|
||||
{
|
||||
Debug.Log("Loop Right: " + loop);
|
||||
if (tilemap.GetTile(pos) == imuable)
|
||||
return true;
|
||||
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x + 1, pos.y, pos.z)) != null && loop < 3 && BlockIsStable(new Vector3Int(pos.x + 1, pos.y, pos.z), checkedUnder, false, true, false, 0, 0, 0, loop + 1))
|
||||
if (loop < 3 && tilemap.GetTile(new Vector3Int(pos.x + 1, pos.y, pos.z)) != null && BlockIsStable(new Vector3Int(pos.x + 1, pos.y, pos.z), checkedUnder, checkedTop, true, false, 0, 0, 0, loop + 1))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BlockStableTop(Vector3Int pos, int loop)
|
||||
bool BlockStableTop(Vector3Int pos, bool checkedLeft, bool checkedRight, int loop)
|
||||
{
|
||||
if (tilemap.GetTile(pos) == imuable)
|
||||
return true;
|
||||
|
||||
if (tilemap.GetTile(new Vector3Int(pos.x, pos.y + 1, pos.z)) != null && loop == 0 && BlockIsStable(new Vector3Int(pos.x, pos.y + 1, pos.z), true, false, false, false, 0, loop + 1))
|
||||
return true;
|
||||
//if (tilemap.GetTile(new Vector3Int(pos.x, pos.y + 1, pos.z)) != null && loop == 0 && BlockIsStable(new Vector3Int(pos.x, pos.y + 1, pos.z), true, false, checkedLeft, checkedRight, 0, loop + 1))
|
||||
// return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user