Ejemplo n.º 1
0
    void Start()
    {
        ball = ballObject.GetComponent <PlayBall>();

        powerBar      = GameInterface.Instance.PowerBar;
        powerBarImage = GameInterface.Instance.PowerBarImage;
    }
Ejemplo n.º 2
0
    private Vector3 calcNormalVectorBox(PlayBall sphere, Bounds box)
    {
        // Ball is already colliding with the box when this code runs
        // Calculate normals from positions

        // Ball colliding in x direction
        if ((sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) > box.min.z - ball.radius) &&
            (sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) < box.max.z + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) < box.max.y + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) > box.min.y - ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) < box.min.x + ball.radius))
        {
            normalVector = -Vector3.right;
        }

        // Ball colliding in minus x direction
        if ((sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) > box.min.z - ball.radius) &&
            (sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) < box.max.z + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) < box.max.y + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) > box.min.y - ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) > box.max.x - ball.radius))
        {
            normalVector = Vector3.right;
        }

        // Ball colliding in z direction
        if ((sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) < box.min.z + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) < box.max.y + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) > box.min.y - ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) < box.max.x + ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) > box.min.x - ball.radius))
        {
            normalVector = Vector3.forward;
        }

        // Ball colliding in minus z direction
        if ((sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) > box.max.z - ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) < box.max.y + ball.radius) &&
            (sphere.transform.position.y + (ball.movement.y * Time.fixedDeltaTime) > box.min.y - ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) < box.max.x + ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) > box.min.x - ball.radius))
        {
            normalVector = -Vector3.forward;
        }

        // Ball collides in Minus Y direction (Top -> Down)
        if ((sphere.transform.position.y + (ball.movement.z * Time.fixedDeltaTime) > box.max.y - ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) > box.min.x - ball.radius) &&
            (sphere.transform.position.x + (ball.movement.x * Time.fixedDeltaTime) < box.max.x + ball.radius) &&
            (sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) < box.max.z + ball.radius) &&
            (sphere.transform.position.z + (ball.movement.z * Time.fixedDeltaTime) > box.min.z - ball.radius))
        {
            normalVector = Vector3.up;
        }

        return(normalVector);
    }
Ejemplo n.º 3
0
    void Start()
    {
        if (Instance == null)
        {
            Instance = this;
        }

        renderer = GetComponent <Renderer>();
        radius   = renderer.bounds.extents.x;
    }
Ejemplo n.º 4
0
    private Vector3 calcNormalVectorCylinder(PlayBall ball, Cylinder cylinder)
    {
        // Ball is already colliding with the cylinder when this code runs

        // direction vector from the center of the cylinder to the center of the ball
        Vector3 heading = ball.transform.position - cylinder.position;

        heading.y    = 0;
        normalVector = heading.normalized; // Gets pushed away with speed 35

        //If ball is on top
        if (ball.transform.position.y > cylinder.position.y + cylinder.height / 2)
        {
            normalVector = Vector3.up;
        }

        return(normalVector);
    }
Ejemplo n.º 5
0
    // Use this for initialization
    private void Start()
    {
        skittlePositions.Add(new Vector3(0f, 0.41f, 12.6f));
        skittlePositions.Add(new Vector3(-0.4f, 0.41f, 13.3f));
        skittlePositions.Add(new Vector3(0.4f, 0.41f, 13.3f));
        skittlePositions.Add(new Vector3(-0.8f, 0.41f, 14f));
        skittlePositions.Add(new Vector3(0f, 0.41f, 14f));
        skittlePositions.Add(new Vector3(0.8f, 0.41f, 14f));
        skittlePositions.Add(new Vector3(-1.2f, 0.41f, 14.7f));
        skittlePositions.Add(new Vector3(-0.4f, 0.41f, 14.7f));
        skittlePositions.Add(new Vector3(0.4f, 0.41f, 14.7f));
        skittlePositions.Add(new Vector3(1.2f, 0.41f, 14.7f));

        playBall      = ball.GetComponent <PlayBall>();
        startPosition = ball.transform.position;

        foreach (var skittlePosition in skittlePositions)
        {
            var skittle = Instantiate(skittlePrefab, skittlePosition, Quaternion.identity);
            skittle.GetComponent <HandleSkittle>().SkittleFallenEvent += OnSkittleFallenEvent;
        }
    }
Ejemplo n.º 6
0
        private static void Menu()
        {
            text.TextEd("Choose program: Enter Number", "cyan");


            string[] titles = new string[]
            {
                "Triangle Area",
                "Odd or Even",
                "Stars",
                "Fizzle",
                "Array Test",
                "Months of Year",
                "Reverse Array",
                "Rolling Dice",
                "Ball Pop",
                "To Quit"
            };

            for (int i = 0; i < titles.Length; i++)
            {
                text.TextEd("\n" + (i + 1) + ". " + titles[i], "green");
            }


            var choice = text.AskForInt("Enter Input Here:");


            switch (choice)
            {
            case 1:
                Console.Clear();
                Triangle.TriangleArea();
                break;

            case 2:
                Console.Clear();
                OddEven.Check();
                break;

            case 3:
                Console.Clear();
                Stars.Star();
                break;

            case 4:
                Console.Clear();
                Fizzle.Fizz();
                break;

            case 5:
                Console.Clear();
                ArrayTest.ATest();
                break;

            case 6:
                Console.Clear();
                MonthOfYear.NumToMonth();
                break;

            case 7:
                Console.Clear();
                int[] array1 = NumGen.GenerateNumbers();
                ReverseArray.Reverse(array1);
                break;

            case 8:
                Console.Clear();
                Dice.DiceRoll();
                break;

            case 9:
                Console.Clear();
                PlayBall.RedThrow();
                break;

            case 10:
                Console.Clear();
                Environment.Exit(0);
                break;

            default:
                text.TextEd("Please select a choice from the list.", "red");
                break;
            }

            Console.ReadKey();
        }