Пример #1
0
 public void moveDownBlocks()
 {
     foreach (GameObject block in gameLogicController._currentBlocks)
     {
         BlockTasksController blockTypeComponent = block.GetComponent <BlockTasksController>();
         if (blockTypeComponent.placed == false)
         {
             tryToMoveDownBlock(block);
         }
     }
 }
Пример #2
0
 public void startMoveUpBlocks()
 {
     foreach (GameObject block in _currentBlocks)
     {
         BlockTasksController blockTypeComponent = block.GetComponent <BlockTasksController>();
         if (blockTypeComponent.placed == true)
         {
             blockTypeComponent.placed = false;
         }
     }
 }
Пример #3
0
 void checkGameResult()
 {
     foreach (GameObject block in _currentBlocks)
     {
         BlockTasksController blockTypeComponent = block.GetComponent <BlockTasksController>();
         if (blockTypeComponent.placed == true && block.transform.localPosition.y > (_loseHeight * _blockHeight))
         {
             _lose    = true;
             stopGame = true;
             endGameController.endMainGame();
             break;
         }
     }
 }
Пример #4
0
    public void showErrorSwipeAnimation()
    {
        GameObject firstBlock = _currentBlocks.Peek();

        BlockTasksController blockTasksController = firstBlock.GetComponent <BlockTasksController>();
        GameObject           firstTask            = blockTasksController.blockTasks[0];

        Vector3  startScale    = firstTask.transform.localScale;
        Vector3  newScale      = new Vector3(startScale.x * 1.5f, startScale.y * 1.5f, 0);
        Sequence scaleSequence = DOTween.Sequence();

        scaleSequence.Append(firstTask.transform.DOScale(newScale, gameSettings.scaleAnimationDuration));
        scaleSequence.Append(firstTask.transform.DOScale(startScale, gameSettings.scaleAnimationDuration));
    }
Пример #5
0
    void Start()
    {
        BlockTasksController blockTasksController = blockExample.GetComponent <BlockTasksController>();
        Renderer             renderer             = blockTasksController.blockRect.GetComponent <Renderer>();

        _blockHeight           = renderer.bounds.size.y;
        _loseHeight            = (_blockHeight * gameSettings.boardHeight);
        _currentSpawnTime      = 0;
        _currentBlocks         = new Queue <GameObject>();
        _score                 = 0;
        _playerInputController = new PlayerInputController();
        _playerInputController.gameLogicController = this;
        _swipeDirectionController = new SwipeDirectionController();
        _moveBlocksController     = new MoveBlocksController();
        _moveBlocksController.gameLogicController = this;
        gameBalanceController.setNewBalance();
    }
Пример #6
0
    void tryToMoveDownBlock(GameObject aBlock)
    {
        aBlock.transform.localPosition = new Vector3(aBlock.transform.localPosition.x, aBlock.transform.localPosition.y - gameLogicController.blocksSpeed, 0);

        BlockTasksController blockTypeComponent = aBlock.GetComponent <BlockTasksController>();

        BlockTasksController blockTasksController = aBlock.GetComponent <BlockTasksController>();
        Renderer             renderer             = blockTasksController.blockRect.GetComponent <Renderer>();

        float loseHeight = (gameLogicController._blockHeight / 2);

        if (aBlock.transform.localPosition.y < loseHeight)
        {
            blockTypeComponent.placed      = true;
            aBlock.transform.localPosition = new Vector3(aBlock.transform.localPosition.x, aBlock.transform.localPosition.y + gameLogicController.blocksSpeed, 0);
        }
        else
        {
            foreach (GameObject blockForCollision in gameLogicController._currentBlocks)
            {
                if (aBlock != blockForCollision)
                {
                    BlockTasksController blockTasksControllerForCollision = blockForCollision.GetComponent <BlockTasksController>();
                    Renderer             blockForCollisionRenderer        = blockTasksControllerForCollision.blockRect.GetComponent <Renderer>();

                    if (renderer.bounds.Intersects(blockForCollisionRenderer.bounds) == true || aBlock.transform.localPosition.y < loseHeight)
                    {
                        int index = Array.IndexOf(gameLogicController._currentBlocks.ToArray(), aBlock);
                        blockTypeComponent.placed = true;
                        float   blockHeight   = renderer.bounds.size.y;
                        Vector3 finalPosition = new Vector3(blockForCollision.transform.localPosition.x, blockForCollision.transform.localPosition.y + gameLogicController.blocksSpeed + blockHeight + 0.01f, 0);
                        aBlock.transform.localPosition = finalPosition;
                        break;
                    }
                }
            }
        }
    }
Пример #7
0
    public void getUserInput()
    {
        if (gameLogicController._currentBlocks.Count > 0)
        {
            GameObject           firstBlock           = gameLogicController._currentBlocks.Peek();
            BlockTasksController blockTasksController = firstBlock.GetComponent <BlockTasksController>();
            List <GameObject>    blockTasks           = blockTasksController.blockTasks;
            GameObject           firstBlockTask       = blockTasks[0];

            BlockTypeController blockTypeComponent = firstBlockTask.GetComponent <BlockTypeController>();
            int blockType = blockTypeComponent.blockType;

            bool rigthSwipe = false;

            if (blockType == 1 && gameLogicController._swipeDirectionController.mMessageIndex == 3)
            {
                blockTasks.Remove(firstBlockTask);
                GameObject.Destroy(firstBlockTask);
                gameLogicController._score += 1;
                rigthSwipe = true;
            }

            if (blockType == 2 && gameLogicController._swipeDirectionController.mMessageIndex == 4)
            {
                blockTasks.Remove(firstBlockTask);
                GameObject.Destroy(firstBlockTask);
                gameLogicController._score += 1;
                rigthSwipe = true;
            }

            if (blockType == 4 && gameLogicController._swipeDirectionController.mMessageIndex == 2)
            {
                blockTasks.Remove(firstBlockTask);
                GameObject.Destroy(firstBlockTask);
                gameLogicController._score += 1;
                rigthSwipe = true;
            }

            if (blockType == 3 && gameLogicController._swipeDirectionController.mMessageIndex == 1)
            {
                blockTasks.Remove(firstBlockTask);
                GameObject.Destroy(firstBlockTask);
                gameLogicController._score += 1;
                rigthSwipe = true;
            }

            if (blockType == 5 && Input.GetMouseButtonDown(0) == true)
            {
                blockTasks.Remove(firstBlockTask);
                GameObject.Destroy(firstBlockTask);
                gameLogicController._score += 1;
            }

            if (blockTasks.Count <= 0)
            {
                gameLogicController.removeFirstBlock();
            }

            if (blockType > 0 && blockType < 5 && rigthSwipe == false && gameLogicController._swipeDirectionController.mMessageIndex > 0)
            {
                gameLogicController.showErrorSwipeAnimation();
            }
        }

        gameLogicController._swipeDirectionController.mMessageIndex = 0;
    }
Пример #8
0
    void spawnNewBlock()
    {
        _currentSpawnTime++;

        if (_currentSpawnTime >= spawnTime)
        {
            _currentSpawnTime = 0;

            GameObject block = Instantiate(blockPadTemplate, transform.position, Quaternion.identity) as GameObject;
            block.transform.SetParent(transform.parent, false);
            block.transform.position = transform.position;

            int        borderIndex         = Random.Range(0, blockBordersTemplates.Length);
            Vector3    startBorderPosition = new Vector3(0, blockBordersTemplates[borderIndex].transform.localPosition.y, 0);
            GameObject blockBorder         = Instantiate(blockBordersTemplates[borderIndex], startBorderPosition, Quaternion.identity) as GameObject;
            blockBorder.transform.SetParent(block.transform, false);

            BlockTasksController tasksController = block.GetComponent <BlockTasksController>();
            Destroy(tasksController.blockRect);
            tasksController.blockRect = blockBorder;

            BlockTasksController blockTasksController = block.GetComponent <BlockTasksController>();

            int taskCount = blockTasksCount;
            if (randomTasksCount)
            {
                taskCount = Random.Range(1, blockTasksCount + 1);
            }

            float tasksLength = 0.0f;
            for (int blockTaskIndex = 0; blockTaskIndex < taskCount; blockTaskIndex++)
            {
                int blockIndex = blockType;
                if (blockType == 0)
                {
                    blockIndex = Random.Range(0, blockTemplates.Length);
                }

                Vector3    newBlockTaskPosition = new Vector3(0, blockTemplates[blockIndex].transform.localPosition.y, 0);
                GameObject blockTaskTemplate    = blockTemplates[blockIndex];
                GameObject blockTask            = Instantiate(blockTemplates[blockIndex], newBlockTaskPosition, blockTaskTemplate.transform.rotation) as GameObject;
                blockTask.transform.SetParent(block.transform, false);
                blockTasksController.blockTasks.Add(blockTask);

                Renderer renderer = blockTask.GetComponent <Renderer>();
                tasksLength += (renderer.bounds.size.x + gameSettings.distanceBetweeneTasks);
            }

            tasksLength -= gameSettings.distanceBetweeneTasks;
            float startX = -tasksLength / 2.0f;

            foreach (GameObject task in blockTasksController.blockTasks)
            {
                Renderer renderer = task.GetComponent <Renderer>();
                float    width    = renderer.bounds.size.x;
                task.transform.localPosition = new Vector3(startX + (width / 2), task.transform.localPosition.y, 0);
                startX += (width + gameSettings.distanceBetweeneTasks);
            }

            _currentBlocks.Enqueue(block);
        }
    }