mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 19:23:07 +02:00
merloj: final movement
This commit is contained in:
parent
16365477b0
commit
5fb48804ad
@ -154,15 +154,19 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
mapSize: {x: 10, y: 10}
|
mapSize: {x: 10, y: 10}
|
||||||
WORLD_SPACE_OFFSET: {x: 0.5, y: 1, z: 0.5}
|
WORLD_SPACE_OFFSET: {x: 0.5, y: 1, z: 0.5}
|
||||||
|
allyBaseCoord: {x: 0, y: 0}
|
||||||
soldierStartingPositions:
|
soldierStartingPositions:
|
||||||
- {x: 0, y: 0}
|
- {x: 0, y: 0}
|
||||||
- {x: 0, y: 5}
|
- {x: 0, y: 0}
|
||||||
|
enemyBaseCoord: {x: 0, y: 0}
|
||||||
enemyStartingPositions:
|
enemyStartingPositions:
|
||||||
- {x: 1, y: 0}
|
- {x: 0, y: 0}
|
||||||
- {x: 9, y: 5}
|
- {x: 0, y: 0}
|
||||||
tilemap: {fileID: 1853262998}
|
tilemap: {fileID: 1853262998}
|
||||||
soldierPrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2,
|
soldierPrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
basePrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2,
|
||||||
|
type: 3}
|
||||||
--- !u!4 &282616949
|
--- !u!4 &282616949
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
// private (do not edit) variables
|
// private (do not edit) variables
|
||||||
|
|
||||||
[Header("Debug (do not change)")]
|
private static TilemapManager ins;
|
||||||
|
|
||||||
private Tile[,] tiles = null;
|
private Tile[,] tiles = null;
|
||||||
|
|
||||||
@ -48,6 +48,8 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
ins = this;
|
||||||
|
|
||||||
tiles = new Tile[mapSize.x, mapSize.y];
|
tiles = new Tile[mapSize.x, mapSize.y];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
if (isBase)
|
if (isBase)
|
||||||
tiles[x, y].standingSoldier = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
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>();
|
tiles[x, y].standingSoldier = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
||||||
|
|
||||||
if (isAlly)
|
if (isAlly)
|
||||||
@ -111,6 +113,8 @@ public class TilemapManager : MonoBehaviour
|
|||||||
if (tiles[x, y].standingSoldier != null)
|
if (tiles[x, y].standingSoldier != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
tiles[x, y].standingSoldier.SetTileCoords(new Vector2Int(x, y));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,9 +155,12 @@ public class TilemapManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
if (GetTileState(x1, y1) == TileState.taken && GetTileState(x2, y2) == TileState.free)
|
||||||
{
|
{
|
||||||
|
// change proper values
|
||||||
tiles[x2, y2].standingSoldier = tiles[x1, y1].standingSoldier;
|
tiles[x2, y2].standingSoldier = tiles[x1, y1].standingSoldier;
|
||||||
tiles[x1, y1].standingSoldier = null;
|
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));
|
tiles[x2, y2].standingSoldier.transform.position = tilemap.CellToWorld(new Vector3Int(x2, y2, 0));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -162,6 +169,13 @@ public class TilemapManager : MonoBehaviour
|
|||||||
return false;
|
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 methods
|
||||||
|
|
||||||
private TileState GetTileState(int x, int y)
|
private TileState GetTileState(int x, int y)
|
||||||
|
|||||||
@ -17,9 +17,9 @@ public class Soldier : MonoBehaviour
|
|||||||
private class Movement : Action
|
private class Movement : Action
|
||||||
{
|
{
|
||||||
public override void Execute(Soldier soldier, TickSystem.OnTickEventArgs tickEventArgs)
|
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}");
|
// move solider to previously set destination
|
||||||
//??tileMap.Teleport(movementDestination)
|
TilemapManager.MoveSoldierS(soldier.tileCoord.x, soldier.tileCoord.y, soldier.movementDestination.x, soldier.movementDestination.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class TryAttack : Action
|
private class TryAttack : Action
|
||||||
@ -60,6 +60,7 @@ public class Soldier : MonoBehaviour
|
|||||||
[SerializeField] private Soldier target;
|
[SerializeField] private Soldier target;
|
||||||
[SerializeField] private SoldierType enemyType;
|
[SerializeField] private SoldierType enemyType;
|
||||||
[SerializeField] private SoldierType ourType;
|
[SerializeField] private SoldierType ourType;
|
||||||
|
[SerializeField] private Vector2Int tileCoord = Vector2Int.zero;
|
||||||
|
|
||||||
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
||||||
|
|
||||||
@ -72,7 +73,6 @@ public class Soldier : MonoBehaviour
|
|||||||
return ourType;
|
return ourType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called before the first frame update
|
|
||||||
void Start(){
|
void Start(){
|
||||||
healthPoints = maxHealthPoints; // initialize health
|
healthPoints = maxHealthPoints; // initialize health
|
||||||
UpdateHPDisplay();
|
UpdateHPDisplay();
|
||||||
@ -97,6 +97,11 @@ public class Soldier : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetTileCoords(Vector2Int tileCoordinates)
|
||||||
|
{
|
||||||
|
tileCoord = tileCoordinates;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOwnTag(SoldierType type)
|
public void setOwnTag(SoldierType type)
|
||||||
{
|
{
|
||||||
ourType = type;
|
ourType = type;
|
||||||
@ -183,7 +188,6 @@ public class Soldier : MonoBehaviour
|
|||||||
return target != null;
|
return target != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
//if (target == null) return;
|
//if (target == null) return;
|
||||||
|
|||||||
@ -44,7 +44,12 @@ public class Squad : MonoBehaviour
|
|||||||
TickSystem.OnTick += HandleTick;
|
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
|
{// pass a single order to all soldiers
|
||||||
if (orders.Count < 1)
|
if (orders.Count < 1)
|
||||||
return; // for now nothing to do here
|
return; // for now nothing to do here
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user