private void GenerateRow( BreakoutGameController breakoutGameController, RowConfig rowConfig, int rowIndex) { var unitSize = breakoutGameController.UnitSize; var numColumns = rowConfig.numColumns; var baseWidth = (breakoutGameController.PaddedGameBoardWidth / rowConfig.numColumns); var brickTopCenterPosition = new Vector3(0.0f, -breakoutGameController.PaddedGameBoardHeight * 0.5f * unitSize, 0.0f); var y = (rowIndex * unitSize + brickTopCenterPosition.y); var startX = -(breakoutGameController.PaddedGameBoardWidth * 0.5f + brickTopCenterPosition.x) * unitSize; for (var i = 0; i < numColumns; i++) { var x = startX + (i * baseWidth * unitSize) + (baseWidth * 0.5f * unitSize); var brickConfig = GetBrickConfigForCoords(rowConfig, i); brickConfig.width = baseWidth; brickConfig.unitSize = unitSize; var brick = _brickFactory.CreateBrick(brickConfig); brick.transform.localPosition = new Vector3(x, 0.0f, -y); breakoutGameController.AddBrick(brick); } }
private BrickConfig GetBrickConfigForCoords( RowConfig rowConfig, int column) { var columnPercent = column / rowConfig.numColumns; var validSpawnRuleConfigs = GetValidSpawnRuleConfigs( columnPercent, rowConfig.brickSpawnRuleConfigs.ToList()); var numColors = validSpawnRuleConfigs[0].brickColors.Length; var randomIndex = Random.Range(0, numColors); var randomColor = validSpawnRuleConfigs[0].brickColors[randomIndex]; var brickConfig = new BrickConfig { color = randomColor }; return(brickConfig); }