Created different unit lists by map position and team
This commit is contained in:
parent
e15dbc9182
commit
6d8fc52d3b
4 changed files with 58 additions and 33 deletions
|
@ -18,15 +18,15 @@ public class Generator : MonoBehaviour {
|
|||
GameObject turnMan = Instantiate (tmanager);
|
||||
GameObject mapCreator = Instantiate (mcreator);
|
||||
GameObject unitCreator = Instantiate (ucreator);
|
||||
tScript = turnMan.GetComponent<TurnManagerScript>();
|
||||
mScript = mapCreator.GetComponent<MapCreation>();
|
||||
uScript = unitCreator.GetComponent<UnitCreator>();
|
||||
tScript = turnMan.GetComponent<TurnManagerScript> ();
|
||||
mScript = mapCreator.GetComponent<MapCreation> ();
|
||||
uScript = unitCreator.GetComponent<UnitCreator> ();
|
||||
uScript.mapSize = new Vector2 (20, 40);
|
||||
|
||||
int[,] map = new int [x,y];
|
||||
for(int i = 0; i < x; ++i) {
|
||||
for(int j = 0; j < y; ++j) {
|
||||
if (i == 0 || i == x-1 || j == 0 || j == y-1)
|
||||
int[,] map = new int [x, y];
|
||||
for (int i = 0; i < x; ++i) {
|
||||
for (int j = 0; j < y; ++j) {
|
||||
if (i == 0 || i == x - 1 || j == 0 || j == y - 1)
|
||||
map [i, j] = -1;
|
||||
else
|
||||
map [i, j] = 0;
|
||||
|
@ -35,9 +35,11 @@ public class Generator : MonoBehaviour {
|
|||
//just to test
|
||||
map [10, 10] = -1;
|
||||
map [10, 20] = -1;
|
||||
mScript.setMatrix (map,x,y);
|
||||
mScript.setMatrix (map, x, y);
|
||||
|
||||
turnMan.GetComponent<TurnManagerScript> ().charMap = uScript.tutorialUnits (x, y);
|
||||
uScript.tutorialUnits ();
|
||||
turnMan.GetComponent<TurnManagerScript> ().charMap = uScript.getUnitMap ();
|
||||
turnMan.GetComponent<TurnManagerScript> ().charList = uScript.getUnitLists ();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
|
@ -9,7 +9,7 @@ public class TurnManagerScript : MonoBehaviour {
|
|||
public int playerNum = 2;
|
||||
public int iaNum = 0;
|
||||
public bool inTurn = true;
|
||||
//public List<List<GameObject> > charList;
|
||||
public List<List<GameObject> > charList;
|
||||
|
||||
public List<int> terrain;
|
||||
public List<GameObject> charMap;
|
||||
|
|
|
@ -38,9 +38,10 @@ public class UnitBehaviour : MonoBehaviour {
|
|||
public int attackActions = 2;
|
||||
public Elemental attackElem = Elemental.None;
|
||||
|
||||
public void SetupStats (int pX, int pZ, int actions = 2, int steps = 5, int p = 50, int crit = 10, int pRange = 20, int critRange = 10) {
|
||||
public void SetupStats (int pX, int pZ, Team id, int actions = 2, int steps = 5, int p = 50, int crit = 10, int pRange = 20, int critRange = 10) {
|
||||
posX = pX;
|
||||
posZ = pZ;
|
||||
teamID = id;
|
||||
actionsPerTurn = actions;
|
||||
stepLength = steps;
|
||||
if (pRange > 0) {
|
||||
|
|
|
@ -6,10 +6,14 @@ public class UnitCreator : MonoBehaviour {
|
|||
|
||||
public GameObject lichObject;
|
||||
public GameObject skeletonObject;
|
||||
public List<GameObject> units;
|
||||
public List<GameObject> unitsByMap;
|
||||
public Vector2 mapSize;
|
||||
public List<List<GameObject>> unitsByTeam;
|
||||
|
||||
private UnitBehaviour playerLichScript;
|
||||
private List<GameObject> teamNone;
|
||||
private List<GameObject> teamPlayer;
|
||||
private List<GameObject> teamEnemy1;
|
||||
|
||||
public enum UnitType {
|
||||
Lich = 0,
|
||||
|
@ -30,14 +34,14 @@ public class UnitCreator : MonoBehaviour {
|
|||
}
|
||||
|
||||
void createUnit(int posX, int posZ, UnitBehaviour.Team team, UnitType type = UnitType.Skeleton) {
|
||||
GameObject unit;
|
||||
GameObject unit = null;
|
||||
|
||||
if (type == UnitType.Lich) {
|
||||
unit = Instantiate (lichObject, new Vector3(posX, lichObject.transform.lossyScale.y/2f, posZ), Quaternion.identity) as GameObject;
|
||||
unit.transform.localScale = new Vector3 (unit.transform.lossyScale.y/unit.transform.lossyScale.y, 1, unit.transform.lossyScale.z/unit.transform.lossyScale.y);
|
||||
unit.GetComponent<UnitBehaviour> ().SetupStats (posX, posZ, 3, 3, 100, 0, 0, 0);
|
||||
unit.GetComponent<UnitBehaviour> ().SetupStats (posX, posZ, team, 3, 3, 100, 0, 0, 0);
|
||||
unit.GetComponent<UnitBehaviour> ().SetupBaseAttack (4, 2, 3);
|
||||
units.Insert(posX*(int)mapSize.x+posZ, unit);
|
||||
unitsByMap.Insert(posX*(int)mapSize.x+posZ, unit);
|
||||
|
||||
if (team == UnitBehaviour.Team.Player && playerLichScript == null )
|
||||
playerLichScript = unit.GetComponent<UnitBehaviour> ();
|
||||
|
@ -45,27 +49,36 @@ public class UnitCreator : MonoBehaviour {
|
|||
} else if (type == UnitType.Skeleton) {
|
||||
unit = Instantiate (skeletonObject, new Vector3(posX, 0f, posZ), Quaternion.identity) as GameObject;
|
||||
unit.transform.localScale = new Vector3 (unit.transform.localScale.x*0.3f, unit.transform.localScale.y*0.3f, unit.transform.localScale.z*0.3f);
|
||||
unit.GetComponent<UnitBehaviour> ().SetupStats (posX, posZ);
|
||||
units.Insert(posX*(int)mapSize.x+posZ, unit);
|
||||
|
||||
|
||||
if (team == UnitBehaviour.Team.Enemy1) {
|
||||
unit.transform.Rotate (new Vector3 (0, 180, 0));
|
||||
}
|
||||
|
||||
//units.Add (unit);
|
||||
unit.GetComponent<UnitBehaviour> ().SetupStats (posX, posZ, team);
|
||||
unitsByMap.Insert(posX*(int)mapSize.x+posZ, unit);
|
||||
}
|
||||
|
||||
|
||||
if (team == UnitBehaviour.Team.Player) {
|
||||
teamPlayer.Add (unit);
|
||||
} else if (team == UnitBehaviour.Team.Enemy1) {
|
||||
unit.transform.Rotate (new Vector3 (0, 180, 0));
|
||||
teamEnemy1.Add (unit);
|
||||
}
|
||||
}
|
||||
|
||||
void setMap(int x, int y) {
|
||||
unitsByMap = new List<GameObject>(x * y);
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
unitsByMap.Insert(i * x + j, null);
|
||||
}
|
||||
}
|
||||
|
||||
unitsByTeam = new List<List<GameObject>> ();
|
||||
|
||||
teamNone = new List<GameObject> ();
|
||||
teamPlayer = new List<GameObject> ();
|
||||
teamEnemy1 = new List<GameObject> ();
|
||||
}
|
||||
|
||||
|
||||
public List<GameObject> tutorialUnits(int x, int y) {
|
||||
units = new List<GameObject>(x * y);
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
units.Insert(i * x + j, null);
|
||||
}
|
||||
}
|
||||
public void tutorialUnits() {
|
||||
setMap (20, 40);
|
||||
|
||||
createUnit (9, 5, UnitBehaviour.Team.Player, UnitType.Lich);
|
||||
|
||||
|
@ -84,6 +97,15 @@ public class UnitCreator : MonoBehaviour {
|
|||
createUnit (16, 24, UnitBehaviour.Team.Enemy1);
|
||||
createUnit (17, 26, UnitBehaviour.Team.Enemy1);
|
||||
|
||||
return units;
|
||||
unitsByTeam.Add (teamPlayer);
|
||||
unitsByTeam.Add (teamEnemy1);
|
||||
}
|
||||
|
||||
public List<List<GameObject>> getUnitLists() {
|
||||
return unitsByTeam;
|
||||
}
|
||||
|
||||
public List<GameObject> getUnitMap() {
|
||||
return unitsByMap;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue