basic movement done

+ soldier tries to move directly into the target position
- if it cannot move, it does nothing
This commit is contained in:
Gabriel Ksawery Skowron-Rodriguez 2022-05-27 13:33:29 +02:00
parent 0ff19d299b
commit 8589ee8007
5 changed files with 35 additions and 7 deletions

View File

@ -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

View File

@ -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:

View File

@ -21,7 +21,9 @@ public class Entity : MonoBehaviour
[HideInInspector] public UnityEvent<Entity> OnDeath = new UnityEvent<Entity>();
protected Vector2Int tileCoord;
[SerializeField] protected Vector2Int tileCoord;
[SerializeField] protected Vector3 WORLD_SPACE_OFFSET = new Vector3(0.5f, 0.5f, 0.5f);
public Team GetOwnTeam()
{

View File

@ -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);

View File

@ -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;
}