public int CheckUp(GameObject brick, GameObject[,] brickArray) { // Grab the brick's brickComponent BrickComponent brickComponent = brick.GetComponent <BrickComponent>(); // First check if components are null if (brickComponent == null) { return(0); } // figure out the distance to the edge of the PlayArea int endOfPlayArea = (int)gameModel.PlayAreaHeight - (int)brickComponent.Location.y; int toMove = 0; // Calculate free spots to the right of it. The number starts at 1 cause that is where the box is. for (int y = 1; y < endOfPlayArea; y++) { if (brickArray[(int)brickComponent.Location.x, (int)brickComponent.Location.y + y] == null) { toMove += 1; } else { break; } } // If the brick doesn't move, return false if (toMove == 0) { return(0); } return(toMove); }
private bool UpdateActualLocation(GameObject brick) { // TODO: We will be adding in movement here BrickComponent brickComponent = brick.GetComponent <BrickComponent>(); if (brickComponent.Location.x != (int)brick.gameObject.transform.position.x || brickComponent.Location.y != (int)brick.gameObject.transform.position.y) { //StartCoroutine(SlideBlockSmoothly(brickComponent)); //brick.transform.position = new Vector3(brickComponent.Location.x, brickComponent.Location.y); return(true); } return(false); }
private IEnumerator SlideBlockSmoothly(BrickComponent brickComponent) { Vector3 startPos = brickComponent.gameObject.transform.position; Vector3 endPos = new Vector3(brickComponent.Location.x, brickComponent.Location.y); Debug.Log("Is this firing"); for (float f = 0f; f <= 1f; f += 0.25f) { Debug.Log(f); //Debug.Log(f); // Debug.Log("The transform location" + brick.transform.position); // Debug.Log("The new position" + new Vector3(brickComponent.Location.x, brickComponent.Location.y)); brickComponent.gameObject.transform.position = Vector3.Lerp(startPos, endPos, f); yield return(0); } }
public bool MoveDown(GameObject brick, bool updateSide) { if (directionChecker.CheckDown(brick, gameModel.BrickArray) > 0) { BrickComponent brickComponent = brick.GetComponent <BrickComponent>(); brickComponent.Location.y = brickComponent.Location.y - directionChecker.CheckDown(brick, gameModel.BrickArray); //UpdateActualLocation(brickComponent.gameObject); if (updateSide == true) { brickComponent.Side = Sides.Bottom; } // Update the brick array so that everything is aligned. UpdateBrickArray(); return(true); } return(false); }
// Write a general move command that uses only the directions public void Move(GameObject[,] brickArray, MoveDirection moveDir) { // Settings to figure out which way it is going int brickArrayWidth = brickArray.GetUpperBound(0) + 1; int brickArrayHeight = brickArray.GetUpperBound(1) + 1; int newX; int newY; int xModifier = 0; int yModifier = 0; int startX = 0; int startY = 0; bool movingUpAndDown = false; newX = startX; newY = startY; if (moveDir == MoveDirection.Up) { // This should all be done by column newY = brickArrayHeight - 1; newX = 0; // Set up here which sides will be affected for (int x = 0; x < brickArrayWidth; x++) { for (int y = brickArrayHeight - 1; y >= 0; y--) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { } else if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newY -= 1; } } newY = brickArrayHeight - 1; newX += 1; } } else if (moveDir == MoveDirection.Down) { newY = 0; newX = 0; // Set up here which sides will be affected for (int x = 0; x < brickArrayWidth; x++) { for (int y = 0; y < brickArrayHeight; y++) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { } else if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newY += 1; } } newY = 0; newX += 1; } } else if (moveDir == MoveDirection.Left) { newX = 0; newY = brickArrayHeight - 1; // Set up here which sides will be affected for (int y = brickArrayHeight - 1; y >= 0; y--) { for (int x = 0; x < brickArrayWidth; x++) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { } else if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newX += 1; } } newX = 0; newY -= 1; } } else if (moveDir == MoveDirection.Right) { newX = brickArrayWidth - 1; newY = brickArrayHeight - 1; // Set up here which sides will be affected for (int y = brickArrayHeight - 1; y >= 0; y--) { for (int x = brickArrayWidth - 1; x >= 0; x--) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { } else if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newX -= 1; } } newX = brickArrayWidth - 1; newY -= 1; } } moveProcessor.UpdateBrickArray(); }
// Load the bricks private void LoadBricks() { // Compute how much we have to scale our objects Vector2 Scaler = new Vector2(Camera.main.pixelRect.width / 777.5f, Camera.main.pixelRect.height / 622f); // Reset the bricks for (System.UInt16 Index = 0; Index < 91; ++Index) { // Destroy the brick if (Bricks[Index] != null) { DestroyImmediate(Bricks[Index].gameObject); } int Col = (Index % 13); int Row = (Index / 13); // Instantiate a brick under the game parent object BrickComponent NewBrick = Bricks[Index] = Instantiate(BrickPrefab, new Vector3(), new Quaternion(), EntityParent.transform).GetComponent <BrickComponent>(); // Set some property NewBrick.BrickStrength = 1; NewBrick.transform.localPosition = new Vector2((-300f + 50 * Col) * Scaler.x, (220f - 40 * Row) * Scaler.y); NewBrick.name = "Brick_" + CurrentLevel + "_" + Index; // if (CurrentLevel == 1) { if (Col < 3 || Col > 9) { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(1, 0, 0)); NewBrick.BrickStrength = 1; } else { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(1, 1, 1)); NewBrick.BrickStrength = 2; } if (Index == 19 || Index == 32 || (Index > 42 && Index < 48) || (Index > 56 && Index < 60) || Index == 71 || Index == 84) { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(1, 0, 0)); NewBrick.BrickStrength = 3; } } else if (CurrentLevel == 2) { if (Col < 4) { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(0 / 255f, 146 / 255f, 70 / 255f)); NewBrick.BrickStrength = 1; } else if (Col < 9) { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(1, 1, 1)); NewBrick.BrickStrength = 2; } else { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(206 / 255f, 43 / 255f, 55 / 255f)); NewBrick.BrickStrength = 3; } } else if (CurrentLevel == 3) { // Yellow color if ((Index > 17 && Index < 21) || (Index > 28 && Index < 31) || (Index > 33 && Index < 36) || (Index > 39 && Index < 43) || (Index > 47 && Index < 51) || (Index > 54 && Index < 57) || (Index > 59 && Index < 62) || (Index > 69 && Index < 73)) { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(254f / 255f, 254f / 255f, 0)); NewBrick.BrickStrength = 1; } // Blue color else if ((Index > 30 && Index < 34) || (Index > 42 && Index < 48) || (Index > 56 && Index < 60)) { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(0f, 34 / 255f, 119 / 255f)); NewBrick.BrickStrength = 2; } // Green color else { NewBrick.GetComponentInParent <ColorModifier>().SetColor(new Color(0f, 156 / 255f, 55 / 255f)); NewBrick.BrickStrength = 3; } } // Set how many points we get by destroying the brick NewBrick.PowerLevel = (7 - Row) * 50; // Sets whatever this brick will spawn a powerup NewBrick.HasPowerUp = Random.Range(0, 10) < 8 ? false : true; } }
private IEnumerator SlideBlockSmoothly(BrickComponent brickComponent) { Vector3 startPos = brickComponent.gameObject.transform.position; Vector3 endPos = new Vector3(brickComponent.Location.x, brickComponent.Location.y); Debug.Log("Is this firing"); for(float f = 0f; f <= 1f; f += 0.25f ) { Debug.Log(f); //Debug.Log(f); // Debug.Log("The transform location" + brick.transform.position); // Debug.Log("The new position" + new Vector3(brickComponent.Location.x, brickComponent.Location.y)); brickComponent.gameObject.transform.position = Vector3.Lerp(startPos, endPos, f); yield return 0; } }