diff --git a/theProject/Assets/Prefabs/Soldier.prefab b/theProject/Assets/Prefabs/Soldier.prefab index 5c6a309f..ec0e2ef3 100644 --- a/theProject/Assets/Prefabs/Soldier.prefab +++ b/theProject/Assets/Prefabs/Soldier.prefab @@ -86,6 +86,8 @@ MonoBehaviour: OnDeath: m_PersistentCalls: m_Calls: [] + tileCoord: {x: 0, y: 0} + WORLD_SPACE_OFFSET: {x: 0.5, y: 0.5, z: 0.5} rangeAttack: 3 rangeView: 1 damageAttack: 25 @@ -94,6 +96,7 @@ MonoBehaviour: target: {fileID: 0} enemyType: 0 movementDestination: {x: 0, y: 0} + hasReachedDestination: 1 --- !u!1 &1997457243244158843 GameObject: m_ObjectHideFlags: 0 diff --git a/theProject/Assets/Scenes/Main.unity b/theProject/Assets/Scenes/Main.unity index b148d040..be29aa57 100644 --- a/theProject/Assets/Scenes/Main.unity +++ b/theProject/Assets/Scenes/Main.unity @@ -156,7 +156,7 @@ MonoBehaviour: WORLD_SPACE_OFFSET: {x: 0.5, y: 0.5, z: 0.5} allyBaseCoord: {x: 0, y: 0} soldierStartingPositions: - - {x: 1, y: 1} + - {x: 2, y: 1} - {x: 2, y: 2} enemyBaseCoord: {x: 9, y: 9} enemyStartingPositions: diff --git a/theProject/Assets/Scripts/Entities/Entity.cs b/theProject/Assets/Scripts/Entities/Entity.cs index 1b78bb74..2a593dce 100644 --- a/theProject/Assets/Scripts/Entities/Entity.cs +++ b/theProject/Assets/Scripts/Entities/Entity.cs @@ -21,7 +21,9 @@ public class Entity : MonoBehaviour [HideInInspector] public UnityEvent OnDeath = new UnityEvent(); - protected Vector2Int tileCoord; + [SerializeField] protected Vector2Int tileCoord; + + [SerializeField] protected Vector3 WORLD_SPACE_OFFSET = new Vector3(0.5f, 0.5f, 0.5f); public Team GetOwnTeam() { diff --git a/theProject/Assets/Scripts/Entities/Soldier.cs b/theProject/Assets/Scripts/Entities/Soldier.cs index 403f1011..013a59f2 100644 --- a/theProject/Assets/Scripts/Entities/Soldier.cs +++ b/theProject/Assets/Scripts/Entities/Soldier.cs @@ -18,7 +18,23 @@ public class Soldier : Entity { public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs) { - TilemapManager.MoveSoldierS(soldier.tileCoord.x, soldier.tileCoord.y, soldier.movementDestination.x, soldier.movementDestination.y); + if (soldier.tileCoord == soldier.movementDestination) + {// reached position - do nothing now + soldier.hasReachedDestination = true; + return; + } + + Vector2Int movementStep = (soldier.movementDestination - soldier.tileCoord); + movementStep.Clamp(-Vector2Int.one, Vector2Int.one); + Vector2Int movementStepDestination = soldier.tileCoord + movementStep; + + + if (!TilemapManager.MoveSoldierS(soldier.tileCoord.x, soldier.tileCoord.y, movementStepDestination.x, movementStepDestination.y)) + return; + + //soldier.transform.position = Mathf.Lerp(soldier.transform.position, new Vector3(movementStepDestination.x, movementStepDestination.y, 0f) + soldier.WORLD_SPACE_OFFSET, 0.1f); + soldier.transform.position = new Vector3(movementStepDestination.x, movementStepDestination.y, 0f) + soldier.WORLD_SPACE_OFFSET; + //tiles[x2, y2].standingEntity.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0)) + WORLD_SPACE_OFFSET; } } private class TryAttack : Action @@ -36,6 +52,7 @@ public class Soldier : Entity public void HandleMovementOrder(Vector2Int destination) { movementDestination = destination; + hasReachedDestination = false; interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination } #endregion @@ -52,7 +69,7 @@ public class Soldier : Entity [SerializeField] private Team enemyType; [SerializeField] private Vector2Int movementDestination = Vector2Int.zero; - + [SerializeField] private bool hasReachedDestination = true; // Start is called before the first frame update protected override void Start(){ base.Start(); @@ -77,7 +94,12 @@ public class Soldier : Entity queueToHandle.Dequeue().Execute(this, tickEventArgs); else { - if(lastAttackTick + speedAttack <= tickEventArgs.tickNumber) + if(!hasReachedDestination) + {// enqueue movement + queueToHandle.Enqueue(new Movement()); + queueToHandle.Dequeue().Execute(this, tickEventArgs); + } + else if(lastAttackTick + speedAttack <= tickEventArgs.tickNumber) { queueToHandle.Enqueue(new TryAttack()); queueToHandle.Dequeue().Execute(this, tickEventArgs); diff --git a/theProject/Assets/Scripts/Managers/TilemapManager.cs b/theProject/Assets/Scripts/Managers/TilemapManager.cs index 85ac469f..576273fa 100644 --- a/theProject/Assets/Scripts/Managers/TilemapManager.cs +++ b/theProject/Assets/Scripts/Managers/TilemapManager.cs @@ -20,7 +20,8 @@ public class TilemapManager : MonoBehaviour [Header("Common Values")] [SerializeField] private Vector2Int mapSize = new Vector2Int(5,5); - [SerializeField] private Vector3 WORLD_SPACE_OFFSET = new Vector3(0.5f, 1f, 0.5f); + [SerializeField] private Vector3 WORLD_SPACE_OFFSET = new Vector3(0.5f, 0.5f, 1f); //REFACTOR REMOVE THIS AND REFER TO ENTITIE'S WSO INSTEAD WHEN USED HERE + //public Vector3 GetWorldSpaceOffset() { return WORLD_SPACE_OFFSET; } [Header("Soldiers values")] @@ -157,7 +158,7 @@ public class TilemapManager : MonoBehaviour tiles[x2, y2].standingEntity.SetTileCoords(new Vector2Int(x2, y2)); // change Soldier world position - tiles[x2, y2].standingEntity.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0)) + WORLD_SPACE_OFFSET; + //tiles[x2, y2].standingEntity.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0)) + WORLD_SPACE_OFFSET; return true; }