Exemplo n.º 1
0
    private void Update()
    {
        abstractBall = playerAvatar.currentBall.GetComponent <AbstractBall>();

        //Gere les inputs de déplacements horizontaux
        HorizontalMovements();

        //Gere le lancement de la balle depis la raquette
        BallLauncher();
    }
Exemplo n.º 2
0
    protected void RaycastCollisions()
    {
        //Gere toutes les collisions sur les briques
        AbstractBall currentBallAvatar = playerAvatar.currentBall.GetComponent <SimpleBall>();


        //Colisions face haute
        for (int i = 0; i < numberOfRaycastByWidth; i++)
        {
            Vector2 raycastPosition = new Vector2(this.transform.position.x - (width / 2) + (i + 1) * (width / numberOfRaycastByWidth), this.transform.position.y);
            //Debug.DrawRay(raycastPosition, Vector2.up * Mathf.Infinity, Color.red, Mathf.Infinity);

            if (Physics2D.Raycast(raycastPosition, Vector2.up, raycastsDistanceWidth, ballLayerMask))
            {
                if (currentBallAvatar.Speed.x < 0)
                {
                    currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }
                else if (currentBallAvatar.Speed.x >= 0)
                {
                    currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }



                currentHealth -= currentBallAvatar.damages;
            }
        }

        //Colisions face basse
        for (int i = 0; i < numberOfRaycastByWidth; i++)
        {
            Vector2 raycastPosition = new Vector2(this.transform.position.x - (width / 2) + (i + 1) * (width / numberOfRaycastByWidth), this.transform.position.y);


            if (Physics2D.Raycast(raycastPosition, Vector2.down, raycastsDistanceWidth, ballLayerMask))
            {
                if (currentBallAvatar.Speed.x < 0)
                {
                    currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }
                else if (currentBallAvatar.Speed.x >= 0)
                {
                    currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }

                currentHealth -= currentBallAvatar.damages;
            }
        }

        //Colisions face gauche
        for (int i = 0; i < numberOfRaycastByHeight; i++)
        {
            Vector2 raycastPosition = new Vector2(this.transform.position.x, this.transform.position.y - (height / 2) + (i + 1) * (height / numberOfRaycastByHeight));


            if (Physics2D.Raycast(raycastPosition, Vector2.left, raycastsDistanceheight, ballLayerMask))
            {
                if (currentBallAvatar.Speed.y < 0)
                {
                    currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }
                else if (currentBallAvatar.Speed.y >= 0)
                {
                    currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }

                currentHealth -= currentBallAvatar.damages;
            }
        }

        //Colisions face droite
        for (int i = 0; i < numberOfRaycastByHeight; i++)
        {
            Vector2 raycastPosition = new Vector2(this.transform.position.x, this.transform.position.y - (height / 2) + (i + 1) * (height / numberOfRaycastByHeight));


            if (Physics2D.Raycast(raycastPosition, Vector2.right, raycastsDistanceheight, ballLayerMask))
            {
                if (currentBallAvatar.Speed.y < 0)
                {
                    currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }
                else if (currentBallAvatar.Speed.y >= 0)
                {
                    currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                }

                currentHealth -= currentBallAvatar.damages;
            }
        }
    }
Exemplo n.º 3
0
    private void RaycastCollisions()
    {
        //Gere toutes les collisions sur les murs

        AbstractBall currentBallAvatar = playerAvatar.currentBall.GetComponent <AbstractBall>();

        if (raycastsDirection == "down")
        {
            //Colisions face basse (Roof)
            for (int i = 0; i < numberOfRaycasts; i++)
            {
                Vector2 raycastPosition = new Vector2(this.transform.position.x - (width / 2) + (i + 1) * (width / numberOfRaycasts), this.transform.position.y);
                //Debug.DrawRay(raycastPosition, Vector2.up * Mathf.Infinity, Color.red, Mathf.Infinity);

                if (Physics2D.Raycast(raycastPosition, Vector2.down, raycastsDistanceWidth, ballLayerMask))
                {
                    if (currentBallAvatar.Speed.x < 0)
                    {
                        currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                    }
                    else if (currentBallAvatar.Speed.x >= 0)
                    {
                        currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                    }
                }
            }
        }


        //Colisions face gauche (RightWall)
        if (raycastsDirection == "left")
        {
            for (int i = 0; i < numberOfRaycasts; i++)
            {
                Vector2 raycastPosition = new Vector2(this.transform.position.x, this.transform.position.y - (height / 2) + (i + 1) * (height / numberOfRaycasts));


                if (Physics2D.Raycast(raycastPosition, Vector2.left, raycastsDistanceheight, ballLayerMask))
                {
                    if (currentBallAvatar.Speed.y < 0)
                    {
                        currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                    }
                    else if (currentBallAvatar.Speed.y >= 0)
                    {
                        currentBallAvatar.Speed = new Vector2(-currentBallAvatar.initialBallSpeed, currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                    }
                }
            }
        }

        //Colisions face droite (LeftWall)
        if (raycastsDirection == "right")
        {
            for (int i = 0; i < numberOfRaycasts; i++)
            {
                Vector2 raycastPosition = new Vector2(this.transform.position.x, this.transform.position.y - (height / 2) + (i + 1) * (height / numberOfRaycasts));


                if (Physics2D.Raycast(raycastPosition, Vector2.right, raycastsDistanceheight, ballLayerMask))
                {
                    if (currentBallAvatar.Speed.y < 0)
                    {
                        currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, -currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                    }
                    else if (currentBallAvatar.Speed.y >= 0)
                    {
                        currentBallAvatar.Speed = new Vector2(currentBallAvatar.initialBallSpeed, currentBallAvatar.initialBallSpeed) * Time.deltaTime;
                    }
                }
            }
        }
    }