private static List<StaticUnit> ScatterStaticUnits(Game game, int numStatUnits, float minDistance, int distance, Player player) { List<StaticUnit> statUnitList = new List<StaticUnit>(); for (int i = 0; i < numStatUnits; i++) { StaticUnit statUnit = new StaticUnit(game, UnitTypes.StaticUnitType.Tree); statUnit.Initialize(); // Generate a random position Vector3 offset = RandomHelper.GeneratePositionXZ(distance); while (Math.Abs(offset.X) < minDistance && Math.Abs(offset.Z) < minDistance) offset = RandomHelper.GeneratePositionXZ(distance); statUnit.Transformation = new Transformation(player.Transformation.Translate + offset, Vector3.Zero, Vector3.One); statUnitList.Add(statUnit); } return statUnitList; }
private static List<StaticUnit> PlaceStaticUnits(Game game, String LevelName) { List<StaticUnit> statUnitList = new List<StaticUnit>(); FileStream levelStaticUnitsFS = new FileStream("Content/" + GameAssetsPath.LEVELS_PATH + LevelName + "/StaticUnits.list", FileMode.Open, FileAccess.Read); StreamReader levelStaticUnitsSR = new StreamReader(levelStaticUnitsFS); String str; while ((str = levelStaticUnitsSR.ReadLine()) != null) { if (str[0] == '#') { //MessageBox.Show("Comment"); continue; } String [] strElems = str.Split(";".ToCharArray()); Int32 type = Int32.Parse(strElems[0]); Int32 posX = Int32.Parse(strElems[1]); Int32 posZ = Int32.Parse(strElems[2]); Int32 width = Int32.Parse(strElems[3]); Int32 height = Int32.Parse(strElems[4]); //MessageBox.Show(type + " " + posX + " " + posY + " " + width + " " + height); StaticUnit statUnit = new StaticUnit(game, UnitTypes.StaticUnitType.Tree); statUnit.Initialize(); statUnit.Transformation = new Transformation(new Vector3(posX, 0, posZ), Vector3.Zero, Vector3.One); statUnitList.Add(statUnit); } /*for (int i = 0; i < numStatUnits; i++) { StaticUnit statUnit = new StaticUnit(game, UnitTypes.StaticUnitType.Tree); statUnit.Initialize(); // Generate a random position Vector3 offset = RandomHelper.GeneratePositionXZ(distance); while (Math.Abs(offset.X) < minDistance && Math.Abs(offset.Z) < minDistance) offset = RandomHelper.GeneratePositionXZ(distance); statUnit.Transformation = new Transformation(player.Transformation.Translate + offset, Vector3.Zero, Vector3.One); statUnitList.Add(statUnit); }*/ return statUnitList; }