public void CreateNewBlocker() { int blockerLayerID = (int)CalculateBlockerStartY(); if (_gamePrefabs.BlockersGO.Count > 0 && _gameConfig.BrickLayers[blockerLayerID] == _gameConfig.BricksOnRow) { int randomBlockerID = Mathf.FloorToInt(UnityEngine.Random.Range(0F, _gamePrefabs.BlockersGO.Count)); float randomRotAngle = Mathf.Floor(UnityEngine.Random.Range(0F, 360F)); GameObject currentBlocker = Instantiate( _gamePrefabs.BlockersGO[randomBlockerID], _gameConfig.connComp.BricksParentTR ); BrickModel currentBrickM = currentBlocker.GetComponent <BrickModel>(); if (currentBrickM != null) { currentBrickM.EndTriggerTR = _gameConfig.connComp.EndTriggerTR; } Vector3 blockerOffset = CalculateBlockerOffset(currentBlocker, blockerLayerID); currentBlocker.transform.position = _gameConfig.BrickPos - blockerOffset; currentBlocker.transform.RotateAround(Vector3.zero, Vector3.up, randomRotAngle); _gameConfig.LockedBlocker++; } }
public void CreateNewBrick() { CameraFollowController camFC = Camera.main.GetComponent <CameraFollowController>(); if (camFC != null) { if (_gamePrefabs.BricksGO.Count > 0 && _gameConfig.BrickPool.Count > 0) { int newBrickID = _gameConfig.BrickPool[0]; _currentBrick = Instantiate(_gamePrefabs.BricksGO[newBrickID], _gameConfig.connComp.BricksParentTR); _currentBrickRB = _currentBrick.GetComponent <Rigidbody>(); _currentBrickM = _currentBrick.GetComponent <BrickModel>(); _currentBrick.transform.position = _gameConfig.BrickPos; _currentBrickRB.useGravity = false; _currentBrickRB.detectCollisions = false; _currentBrickM.State = BrickState.IDLE; _currentBrickM.EndTriggerTR = _gameConfig.connComp.EndTriggerTR; _currentBrickM.OnEndTheGame += _endTheGame; _currentBrickM.OnAddLockedBrick += _addLockedBrick; camFC.SetCameraTagetTR(_currentBrick.transform, _gameConfig.CameraOffset); _currentBrick.transform.RotateAround(Vector3.zero, Vector3.up, _gameConfig.BrickRot.y); _rotateBrick = true; _gameConfig.BrickPool.RemoveAt(0); } } }
public void updateBrickPreviewer() { if (Player.Instance == null) { return; } // update brick previewer if (selectedItem == null && BrickCollisionDetector.Instance != null) { Destroy(BrickCollisionDetector.Instance.gameObject); } else if (selectedItem != null && selectedItem.item.type == Item.Type.Brick) { BrickModel selectedBrickModel = selectedItem.item.brickModel; if (BrickCollisionDetector.Instance != null) { if (BrickCollisionDetector.Instance.currentBrickType == selectedBrickModel.type) { return; } Destroy(BrickCollisionDetector.Instance.gameObject); } GameObject brickPreviewer = Instantiate(Server.brickPrefabs[selectedBrickModel.type.ToString()]); brickPreviewer.AddComponent <BrickCollisionDetector>().setCurrentBrickType(selectedBrickModel.type); } }
// Refactor these two methods to remove duplicate code private void RandomLevel() { for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { var randomNum = Random.Range(0, prefabs.Count + 1); var model = new BrickModel(); var brickSpace = new Vector2( x * (prefabs[0].transform.localScale.x + spacing), -y * (prefabs[0].transform.localScale.y + spacing)); var spawnPos = startPosition + brickSpace; if (randomNum < prefabs.Count) { var prefab = prefabs[Random.Range(0, prefabs.Count)]; var prefabBrick = prefab.GetComponent <Brick>(); var brick = Instantiate(prefab, spawnPos, Quaternion.identity); model = new BrickModel { Brick = brick, Position = spawnPos, BrickType = prefabBrick.brickType }; if (prefabBrick.brickType != BrickType.None && prefabBrick.brickType != BrickType.Unbreakable) { remainingBricks++; } } else { // Add an empty space model = new BrickModel { Brick = null, Position = spawnPos, BrickType = BrickType.None }; } bricks.Add(model); } } }
public void brickHit(GameObject brick) { BrickModel brickModel = brick.GetComponent <BrickModel>(); brickModel.brickHitPoints--; if (brickModel.brickHitPoints == 0) { this.bricksLeft.Remove(brick); Destroy(brick); this.addScore(); if (this.playerWon()) { this.tooglePauseGame(); this.showLevelCompletedDialog(); } } else { brickModel.updateColor(); } }
private void GenerateLevel(int levelToLoad) { var level = Levels.LevelOne; if (levelToLoad == 2) { level = Levels.LevelTwo; } for (int x = 0; x < level.Length; x++) { for (int y = 0; y < level[x].Length; y++) { var prefab = prefabs.First(p => p.GetComponent <Brick>().brickType == level[x][y]); var prefabBrick = prefab.GetComponent <Brick>(); var spawnPos = startPosition + new Vector2( x * (prefab.transform.localScale.x + spacing), -y * (prefab.transform.localScale.y + spacing)); var brick = Instantiate(prefab, spawnPos, Quaternion.identity); var model = new BrickModel { Brick = brick, Position = spawnPos, BrickType = prefabBrick.brickType }; bricks.Add(model); if (prefabBrick.brickType != BrickType.None && prefabBrick.brickType != BrickType.Unbreakable) { remainingBricks++; } } } }
private void Start() { _brickModel = GetComponent <BrickModel>(); }
// Constructor public BrickViewModel(double left, double top) { Brick = new BrickModel(left, top); }