diff --git a/theProject/Assets/Scenes/Merloj.unity b/theProject/Assets/Scenes/Merloj.unity index 3674d26c..2e91c7df 100644 --- a/theProject/Assets/Scenes/Merloj.unity +++ b/theProject/Assets/Scenes/Merloj.unity @@ -154,15 +154,19 @@ MonoBehaviour: m_EditorClassIdentifier: mapSize: {x: 10, y: 10} WORLD_SPACE_OFFSET: {x: 0.5, y: 1, z: 0.5} + allyBaseCoord: {x: 0, y: 0} soldierStartingPositions: - {x: 0, y: 0} - - {x: 0, y: 5} + - {x: 0, y: 0} + enemyBaseCoord: {x: 0, y: 0} enemyStartingPositions: - - {x: 1, y: 0} - - {x: 9, y: 5} + - {x: 0, y: 0} + - {x: 0, y: 0} tilemap: {fileID: 1853262998} soldierPrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2, type: 3} + basePrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2, + type: 3} --- !u!4 &282616949 Transform: m_ObjectHideFlags: 0 diff --git a/theProject/Assets/Scripts/Managers/TilemapManager.cs b/theProject/Assets/Scripts/Managers/TilemapManager.cs index bdd22ae9..c59aa607 100644 --- a/theProject/Assets/Scripts/Managers/TilemapManager.cs +++ b/theProject/Assets/Scripts/Managers/TilemapManager.cs @@ -40,7 +40,7 @@ public class TilemapManager : MonoBehaviour // private (do not edit) variables - [Header("Debug (do not change)")] + private static TilemapManager ins; private Tile[,] tiles = null; @@ -48,6 +48,8 @@ public class TilemapManager : MonoBehaviour private void Awake() { + ins = this; + tiles = new Tile[mapSize.x, mapSize.y]; } @@ -100,7 +102,7 @@ public class TilemapManager : MonoBehaviour if (isBase) tiles[x, y].standingSoldier = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent(); - if (isBase) + else tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent(); if (isAlly) @@ -111,6 +113,8 @@ public class TilemapManager : MonoBehaviour if (tiles[x, y].standingSoldier != null) return true; + tiles[x, y].standingSoldier.SetTileCoords(new Vector2Int(x, y)); + return false; } @@ -151,9 +155,12 @@ public class TilemapManager : MonoBehaviour { if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free) { + // change proper values tiles[x2, y2].standingSoldier = tiles[x1, y1].standingSoldier; tiles[x1, y1].standingSoldier = null; + tiles[x2, y2].standingSoldier.SetTileCoords(new Vector2Int(x2, y2)); + // change Soldier world position tiles[x2, y2].standingSoldier.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0)); return true; @@ -162,6 +169,13 @@ public class TilemapManager : MonoBehaviour return false; } + // ---------- public statics methods + + public static bool MoveSoldierS(int x1, int y1, int x2, int y2) + { + return ins.MoveSoldier(x1, y1, x2, y2); + } + // ---------- private methods private TileState GetTileState(int x, int y) diff --git a/theProject/Assets/Scripts/Soldier.cs b/theProject/Assets/Scripts/Soldier.cs index dbeba977..de607e41 100644 --- a/theProject/Assets/Scripts/Soldier.cs +++ b/theProject/Assets/Scripts/Soldier.cs @@ -17,9 +17,9 @@ public class Soldier : MonoBehaviour private class Movement : Action { public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs) - {//TO DO: CALL PROPER FUNCTION TO MOVE - throw new System.NotImplementedException($"(tick: {tickEventArgs.tickNumber}) Trying to teleport to {soldier.movementDestination}"); - //??tileMap.Teleport(movementDestination) + { + // move solider to previously set destination + TilemapManager.MoveSoldierS(soldier.tileCoord.x, soldier.tileCoord.y, soldier.movementDestination.x, soldier.movementDestination.y); } } private class TryAttack : Action @@ -60,6 +60,7 @@ public class Soldier : MonoBehaviour [SerializeField] private Soldier target; [SerializeField] private SoldierType enemyType; [SerializeField] private SoldierType ourType; + [SerializeField] private Vector2Int tileCoord = Vector2Int.zero; [SerializeField] private Vector2Int movementDestination = Vector2Int.zero; @@ -72,7 +73,6 @@ public class Soldier : MonoBehaviour return ourType; } - // Start is called before the first frame update void Start(){ healthPoints = maxHealthPoints; // initialize health UpdateHPDisplay(); @@ -97,6 +97,11 @@ public class Soldier : MonoBehaviour } } + public void SetTileCoords(Vector2Int tileCoordinates) + { + tileCoord = tileCoordinates; + } + public void setOwnTag(SoldierType type) { ourType = type; @@ -183,7 +188,6 @@ public class Soldier : MonoBehaviour return target != null; } - // Update is called once per frame void Update() { //if (target == null) return; diff --git a/theProject/Assets/Scripts/Squad.cs b/theProject/Assets/Scripts/Squad.cs index a9a7c5d5..32b602d1 100644 --- a/theProject/Assets/Scripts/Squad.cs +++ b/theProject/Assets/Scripts/Squad.cs @@ -44,7 +44,12 @@ public class Squad : MonoBehaviour TickSystem.OnTick += HandleTick; } - private void HandleTick(TickSystem.OnTickEventArgs eventArgs) + private void Start() + { + + } + + private void HandleTick(TickSystem.OnTickEventArgs eventArgs) {// pass a single order to all soldiers if (orders.Count < 1) return; // for now nothing to do here