mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 15:43:16 +02:00
merloj: final movement
This commit is contained in:
parent
16365477b0
commit
5fb48804ad
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user