From 6146d64dba55e259a9a7f4757e806beed37c6b8a Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Mon, 30 May 2022 13:13:39 +0200 Subject: [PATCH] feat: detect edges in formation --- theProject/.vscode/settings.json | 55 +++++++++++++++++++ theProject/Assets/Scripts/Formation.cs | 20 +++++-- .../Assets/Scripts/Managers/TilemapManager.cs | 6 +- 3 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 theProject/.vscode/settings.json diff --git a/theProject/.vscode/settings.json b/theProject/.vscode/settings.json new file mode 100644 index 00000000..e232cd65 --- /dev/null +++ b/theProject/.vscode/settings.json @@ -0,0 +1,55 @@ +{ + "files.exclude": + { + "**/.DS_Store":true, + "**/.git":true, + "**/.gitmodules":true, + "**/*.booproj":true, + "**/*.pidb":true, + "**/*.suo":true, + "**/*.user":true, + "**/*.userprefs":true, + "**/*.unityproj":true, + "**/*.dll":true, + "**/*.exe":true, + "**/*.pdf":true, + "**/*.mid":true, + "**/*.midi":true, + "**/*.wav":true, + "**/*.gif":true, + "**/*.ico":true, + "**/*.jpg":true, + "**/*.jpeg":true, + "**/*.png":true, + "**/*.psd":true, + "**/*.tga":true, + "**/*.tif":true, + "**/*.tiff":true, + "**/*.3ds":true, + "**/*.3DS":true, + "**/*.fbx":true, + "**/*.FBX":true, + "**/*.lxo":true, + "**/*.LXO":true, + "**/*.ma":true, + "**/*.MA":true, + "**/*.obj":true, + "**/*.OBJ":true, + "**/*.asset":true, + "**/*.cubemap":true, + "**/*.flare":true, + "**/*.mat":true, + "**/*.meta":true, + "**/*.prefab":true, + "**/*.unity":true, + "build/":true, + "Build/":true, + "Library/":true, + "library/":true, + "obj/":true, + "Obj/":true, + "ProjectSettings/":true, + "temp/":true, + "Temp/":true + } +} \ No newline at end of file diff --git a/theProject/Assets/Scripts/Formation.cs b/theProject/Assets/Scripts/Formation.cs index a731e3d4..56bc505c 100644 --- a/theProject/Assets/Scripts/Formation.cs +++ b/theProject/Assets/Scripts/Formation.cs @@ -5,7 +5,7 @@ using UnityEngine; public class Formation : MonoBehaviour { - [SerializeField] Squad squad; + [SerializeField] Squad squad; void Awake() { @@ -29,9 +29,21 @@ public class Formation : MonoBehaviour // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/in-parameter-modifier private Vector2Int CalculateSoldierCoordinates(in int soldierNumber, in Vector2Int coordinates) { - // Horizontal line we change x - Vector2Int soldierCoordinates = new Vector2Int(coordinates.x + soldierNumber, coordinates.y); - return soldierCoordinates; + // Horizontal line we change x + TilemapManager.TileState tileState = TilemapManager.GetTileState(coordinates.x + soldierNumber, coordinates.y); + if ( tileState == TilemapManager.TileState.free) + { + Vector2Int soldierCoordinates = new Vector2Int(coordinates.x + soldierNumber, coordinates.y); + return soldierCoordinates; + } else if (tileState == TilemapManager.TileState.taken) + { + Vector2Int soldierCoordinates = new Vector2Int(coordinates.x, coordinates.y); + return soldierCoordinates; + } else + { + Vector2Int soldierCoordinates = new Vector2Int(coordinates.x, coordinates.y); + return soldierCoordinates; + } } diff --git a/theProject/Assets/Scripts/Managers/TilemapManager.cs b/theProject/Assets/Scripts/Managers/TilemapManager.cs index 576273fa..efcafb41 100644 --- a/theProject/Assets/Scripts/Managers/TilemapManager.cs +++ b/theProject/Assets/Scripts/Managers/TilemapManager.cs @@ -174,12 +174,12 @@ public class TilemapManager : MonoBehaviour // ---------- private methods - private TileState GetTileState(int x, int y) + public static TileState GetTileState(int x, int y) { - if (x < 0 || y < 0 || x >= mapSize.x || y >= mapSize.y) + if (x < 0 || y < 0 || x >= ins.mapSize.x || y >= ins.mapSize.y) return TileState.outOfBounds; - if (tiles[x, y].standingEntity == null) + if (ins.tiles[x, y].standingEntity == null) return TileState.free; return TileState.taken;