示例#1
0
        private void Update()
        {
            //ativa efeito do power up
            if (ballCollider != null)
            {
                if (CustomFuncs.MyIntersects(myCollider.bounds, ballCollider.bounds))
                {
                    gameManager.ActivateEffect(type);
                    Destroy(gameObject);

                    //Animações
                    if (type == PowerUpType.FIRE)
                    {
                        fundoFogo.gameObject.SetActive(true);
                        Instantiate(paredeFogoEsquerda, transform.position, Quaternion.identity);
                        Instantiate(paredeFogoDireita, transform.position, Quaternion.identity);

                        //Som
                        AudioSource.PlayClipAtPoint(spreadFireSound, Vector3.zero);
                    }

                    if (type == PowerUpType.ICE)
                    {
                        fundoGelo.gameObject.SetActive(true);
                        Instantiate(pedacosGeloDireita, transform.position, Quaternion.identity);
                        Instantiate(pedacosGeloEsquerda, transform.position, Quaternion.identity);

                        //Som
                        AudioSource.PlayClipAtPoint(iceBreakSound, Vector3.zero);
                        AudioSource.PlayClipAtPoint(spreadIceSound, Vector3.zero);
                    }
                }
            }
        }
示例#2
0
        private IEnumerator Animation()
        {
            yield return(new WaitForSeconds(appearingTime));

            //Cria metades
            float      cameraY     = Camera.main.transform.position.y;
            Vector3    cameraVectX = new Vector3(Camera.main.transform.position.x, 0, 0);
            float      initialY    = Camera.main.orthographicSize * 2 + cameraY;
            GameObject upperHalf   = Instantiate(ballsUpperHalf, cameraVectX + Vector3.up * initialY, Quaternion.identity);
            GameObject lowerHalf   = Instantiate(ballsLowerHalf, cameraVectX + Vector3.down * initialY, Quaternion.Euler(0, 0, 180));

            //Som
            GameObject movementSoundGameObject = CustomFuncs.MyPlayClipAtPoint(movementSound, Vector3.zero);

            //Desce (ou sobe) peças
            float speed = initialY / meetingTime;

            while (upperHalf.transform.position.x > cameraY || lowerHalf.transform.position.y < cameraY)
            {
                upperHalf.transform.position += speed * Vector3.down * Time.fixedDeltaTime;
                lowerHalf.transform.position += speed * Vector3.up * Time.fixedDeltaTime;

                yield return(new WaitForFixedUpdate());
            }
            upperHalf.transform.position = new Vector3(upperHalf.transform.position.x, cameraY, upperHalf.transform.position.z);
            lowerHalf.transform.position = new Vector3(lowerHalf.transform.position.x, cameraY, lowerHalf.transform.position.z);

            //Som
            Destroy(movementSoundGameObject);

            yield return(new WaitForSeconds(unionTime));

            //Junta metades
            Destroy(upperHalf);
            Destroy(lowerHalf);
            GameObject fusionBall = Instantiate(spriteBall, new Vector3(cameraVectX.x, cameraY, 0), Quaternion.identity);

            //Som
            AudioSource.PlayClipAtPoint(unionSound, Vector3.zero);

            yield return(new WaitForSeconds(gameStartTime));

            //Começa partida
            Destroy(fusionBall);

            GetComponent <GameManager>().StartsGameAfterCutScene();

            //Som
            AudioSource.PlayClipAtPoint(startSound, Vector3.zero);
        }
示例#3
0
        /// <summary>
        /// Incrementa 'PowerUpBounces'. Quando atingi um certo número de 'bounces',
        /// escolhe qual será o powerup e ativa a linha de aviso.
        /// </summary>
        public void BounceOcurred()
        {
            PowerUpBounces++;

            if (PowerUpBounces == bouncesTillWarningLine)
            {
                powerUpType = CustomFuncs.RandomBool() ? PowerUpType.FIRE : PowerUpType.ICE;
                //powerUpType = PowerUpType.FIRE;
                //powerUpType = PowerUpType.ICE;

                linhaDeAviso.gameObject.SetActive(true);
                linhaDeAviso.GetComponent <SpriteRenderer>().color = powerUpType == PowerUpType.FIRE ? linhaDeAviso.corFogo : linhaDeAviso.corGelo;
            }

            if (PowerUpBounces == bouncesTillPowerUp)
            {
                lastBounceX = ball.transform.position.x;
            }
        }
示例#4
0
        private void Start()
        {
            gameManager = FindObjectOfType <GameManager>();
            myCollider  = GetComponent <Collider2D>();

            foreach (Collider2D collider in FindObjectsOfType <Collider2D>())
            {
                if (collider.gameObject.GetComponent <BarraController>() != null)
                {
                    padColliders.Add(collider);
                }
            }

            //calcula minY e maxY
            Sprite sprite = GetComponent <SpriteRenderer>().sprite;

            maxY = Camera.main.orthographicSize - sprite.bounds.extents.y * transform.localScale.y;
            minY = -Camera.main.orthographicSize + sprite.bounds.extents.y * transform.localScale.y;

            //Joga bola
            velocity = (CustomFuncs.RandomBool()) ? Vector3.left * terminalSpeed * 0.5f : Vector3.right * terminalSpeed * 0.5f;
        }
示例#5
0
        private void FixedUpdate()
        {
            bool    collisionHappened = false;
            Vector3 newPosition       = transform.position + velocity * Time.fixedDeltaTime;

            //Reflexão nas paredes
            if (newPosition.y > maxY)
            {
                //Torna colisão pixel perfect
                Vector3 diffVect = newPosition - transform.position;
                transform.position += diffVect * Mathf.Abs((maxY - transform.position.y) / diffVect.y);

                velocity = Vector3.Reflect(velocity, Vector3.down);

                collisionHappened = true;
            }
            if (newPosition.y < minY)
            {
                //Torna colisão pixel perfect
                Vector3 diffVect = newPosition - transform.position;
                transform.position += diffVect * Mathf.Abs((minY - transform.position.y) / diffVect.y);

                velocity = Vector3.Reflect(velocity, Vector3.up);

                collisionHappened = true;
            }
            //Reflexão nas raquetes
            foreach (Collider2D collider in padColliders)
            {
                Bounds newBounds = new Bounds(newPosition, myCollider.bounds.size);

                if (CustomFuncs.MyIntersects(newBounds, collider.bounds))
                {
                    BarraController paddle = collider.gameObject.GetComponent <BarraController>();

                    //Calcula a maior (ou menor) posição x que a bola chegar na qual a raquete ainda possa salvar o ponto
                    Vector3 diffVect         = newPosition - transform.position;
                    int     paddleSide       = (diffVect.x > 0) ? 1 : -1; //diz se a bola está indo para a direita ou esquerda
                    float   paddleHalfLenght = collider.bounds.extents.x;
                    float   ballHalfLenght   = myCollider.bounds.extents.x;
                    float   xSafe            = paddle.transform.position.x + (paddleHalfLenght + ballHalfLenght) * paddleSide;

                    //Torna a colisão pixel perfect
                    float xLimit = paddle.transform.position.x - (ballHalfLenght + paddleHalfLenght) * paddleSide;
                    transform.position += (paddleSide * transform.position.x < xLimit * paddleSide) ?
                                          diffVect * Mathf.Abs((xLimit - transform.position.x) / diffVect.x) :
                                          new Vector3(xLimit - transform.position.x, 0, 0);

                    //Efeito da colisão
                    velocity  = Vector3.Reflect(velocity, paddle.normal);
                    velocity += paddle.velocity * padTransmission + paddle.normal * padBumping;

                    //Som da raquetada
                    switch (gameManager.gameState)
                    {
                    case GameState.NORMAL: AudioSource.PlayClipAtPoint(normalBounceSound, Vector3.zero); break;

                    case GameState.FIRE: AudioSource.PlayClipAtPoint(fireBounceSound, Vector3.zero); break;

                    case GameState.ICE: AudioSource.PlayClipAtPoint(iceBounceSound, Vector3.zero); break;

                    default: break;
                    }

                    gameManager.BounceOcurred();
                    collisionHappened = true;
                    break;
                }
            }

            if (!collisionHappened)
            {
                transform.position = newPosition;
            }

            //Limita velocidade
            float speed = Mathf.Min(velocity.magnitude, terminalSpeed);

            velocity = velocity.normalized * speed;
        }