mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 22:43:18 +02:00
feat: add formation calculation
This commit is contained in:
parent
973ab6af6f
commit
4ee480cdc0
36
theProject/Assets/Scripts/Formation.cs
Normal file
36
theProject/Assets/Scripts/Formation.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Formation : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] Squad squad;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
this.squad = squad.GetComponent(typeof(Squad));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<Soldier, Vector2Int> calculatePositions(Vector2int coordinates)
|
||||||
|
{
|
||||||
|
List<Soldier> soldiers = this.squad.getSoldiers();
|
||||||
|
Dictionary<Soldier, Vector2Int> soldierNewCoordinate = new Dictionary<Soldier, Vector2Int>();
|
||||||
|
int soldierNumber = 0;
|
||||||
|
foreach (Soldier soldier in soldiers)
|
||||||
|
{
|
||||||
|
soldierNewCoordinate.Add(soldier, calculateSoldierCoordinates(soldierNumber, coordinates));
|
||||||
|
MoveSoldierS(x, y, soldierNewCoordinate.Item1, soldierNewCoordinate.Item2);
|
||||||
|
}
|
||||||
|
return soldierNewCoordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/in-parameter-modifier
|
||||||
|
private Vector2Int calculateSoldierCoordinates(in int soldierNumber, in Vector2Int coordinates)
|
||||||
|
{
|
||||||
|
// Horizontal line we change x
|
||||||
|
Vector2Int coordinates = new Vector2Int(coordinates.Item1 + soldierNumber, coordinates.Item1);
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
11
theProject/Assets/Scripts/Formation.cs.meta
Normal file
11
theProject/Assets/Scripts/Formation.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5175e17e18d002001bf1ebde5de11b49
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -31,9 +31,14 @@ public class Squad : MonoBehaviour
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
[SerializeField] private Formation formation = new Formation();
|
||||||
[SerializeField] private List<Soldier> soldiers = new List<Soldier>(); // soldiers belonging to the squad
|
[SerializeField] private List<Soldier> soldiers = new List<Soldier>(); // soldiers belonging to the squad
|
||||||
private Queue<Order> orders = new Queue<Order>(); // orders given to the squad
|
private Queue<Order> orders = new Queue<Order>(); // orders given to the squad
|
||||||
|
|
||||||
|
public List<Soldier> getSoldiers()
|
||||||
|
{
|
||||||
|
return soldiers;
|
||||||
|
}
|
||||||
public void TempAddSoldierToSquad(Soldier soldier)
|
public void TempAddSoldierToSquad(Soldier soldier)
|
||||||
{
|
{
|
||||||
soldiers.Add(soldier);
|
soldiers.Add(soldier);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user