Merge branch 'merloj-full_soldier_movement' into Development

This commit is contained in:
Maciekxdabu 2022-05-23 13:52:24 +02:00
commit ae04f9f4af
4 changed files with 34 additions and 11 deletions

View File

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

View File

@ -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<Soldier>();
if (isBase)
else
tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
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)

View File

@ -17,9 +17,9 @@ public class Soldier : Base
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
@ -51,6 +51,8 @@ public class Soldier : Base
[Header("Do-not-change-in-game values")]
[SerializeField] private Soldier target;
[SerializeField] private SoldierType enemyType;
[SerializeField] private SoldierType ourType;
[SerializeField] private Vector2Int tileCoord = Vector2Int.zero;
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
@ -59,7 +61,6 @@ public class Soldier : Base
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
// Start is called before the first frame update
void Start(){
base.Start();
setEnemyTag();
@ -145,7 +146,6 @@ public class Soldier : Base
return target != null;
}
// Update is called once per frame
void Update()
{
//if (target == null) return;

View File

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