mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 22:23:11 +02:00
Merge branch 'kuchy-formation' into 'Development'
# Conflicts: # theProject/Assets/Scripts/Squad.cs
This commit is contained in:
commit
9df38ff1a6
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:
|
||||
@ -33,7 +33,7 @@ public class Squad : MonoBehaviour
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
[SerializeField] private Formation formation = new Formation();
|
||||
[SerializeField] private List<Entity> soldiers = new List<Entity>(); // soldiers belonging to the squad
|
||||
public List<Entity> GetSoldiers() { return soldiers; }
|
||||
private Queue<Order> orders = new Queue<Order>(); // orders given to the squad
|
||||
|
||||
Loading…
Reference in New Issue
Block a user