public IEnumerator GenerateLevel(Level level) { CurrentLevel = level; camAnim.StartCoroutine("Animate"); if (GameObject.Find("Lights holder")) { GameObject.Destroy(GameObject.Find("Lights holder")); } GameObject father = new GameObject("Lights holder"); lightPoints = new PointOfLight[level.x, level.y]; fromColor = Utility.GetRandomColor(); to = Utility.GetRandomColor(fromColor); bottomPoint = new Vector3(-level.x / 2F, -level.y / 2F, 0F); Vector2 maxMatrix = new Vector2(level.x, level.y); for (int i = 0; i < CurrentLevel.x; i++) { for (int j = 0; j < CurrentLevel.y; j++) { Vector3 point = new Vector3(i + bottomPoint.x, j + bottomPoint.y, 0F); string lightName = "X: " + i + " Y:" + j; float colorPercent = ((i / maxMatrix.x) + (j / maxMatrix.y)) * .5F; Color c = Color.Lerp(fromColor, to, colorPercent); BlockType bT = GetBlockType(i, j); print(bT); PointOfLight pointOfLight = Instantiate(lightPrefab, point, lightPrefab.transform.rotation) as PointOfLight; pointOfLight.Initialize(bT, i, j, point, lightName, father.transform, c); lightPoints [i, j] = pointOfLight; yield return(new WaitForSeconds(CurrentLevel.timeBetweenEachTileToSpawn)); } } for (int x = 0; x < CurrentLevel.x; x++) { for (int y = 0; y < CurrentLevel.y; y++) { for (int k = 0; k < CurrentLevel.activeLights.Count; k++) { if (lightPoints[x, y].x == CurrentLevel.activeLights[k].x && lightPoints[x, y].y == CurrentLevel.activeLights[k].y) { lightPoints[x, y].Turn(); } } } } }
public static List <PointOfLight> Parse(IList <string> input) { var pointsExpression = new Regex(@"position=<\s*(\-?\d+),\s*(\-?\d+)> velocity=<\s*(\-?\d),\s*(\-?\d)>"); var points = new List <PointOfLight>(); foreach (var line in input) { var match = pointsExpression.Match(line); var pX = int.Parse(match.Groups[1].Value); var pY = int.Parse(match.Groups[2].Value); var vX = int.Parse(match.Groups[3].Value); var vY = int.Parse(match.Groups[4].Value); var point = new PointOfLight { Position = new Point(pX, pY), Velocity = new Point(vX, vY) }; points.Add(point); } return(points); }