Exemplo n.º 1
0
Arquivo: MGC.cs Projeto: p2426/Towerl
    public void MoveTheBall()
    {
        // MOVE THE BALL
        CurrentBallVelocity     += Vector3.up * Gravity * Time.deltaTime;
        Ball.transform.position += CurrentBallVelocity * Time.deltaTime;
        // At this stage we are able to detect tier transitions
        // Can compare where the Ball WAS (stored in BallHeight) against the New Height
        float NewBallHeight = Ball.transform.position.y;

        if (CurrentBallVelocity.y < 0) // Only need ANY checking if ball is moving downwards
        {
            if ((int)Mathf.Floor(NewBallHeight) == (int)Mathf.Floor(BallHeight))
            {
                // DO NOTHING .. Are on same Tier between frames
            }
            else // here's the Ball Mechanics, folks.  Hang onto your hats
            {
                if (NewBallHeight <= 0) // Have Reached the bottom
                {
                    // Add Game Over (Win) complete code here ... or call a function ;p
                    // but for our purposes now
                    double Start = Time.realtimeSinceStartup;
                    DestroyLevel();
                    levelBuilder.BuildRandomLevel();
                    ResetBall();
                    Debug.Log("Time to Destroy, Rebuild and Reset = " + (Time.realtimeSinceStartup - Start).ToString());
                }
                else
                {
                    int TierToCheck = (int)Mathf.Floor(NewBallHeight + 1);
                    int SurfaceHit  = GetTierSegmentType(TierToCheck, TowerAngle);
                    switch (SurfaceHit)
                    {
                    case 0:     // 0 = gap -- FALL THROUGH
                        BallFalling = true;
                        break;

                    case 1:     // 1 = normal platform --- BOUNCE
                        BallFalling = false;
                        camera.GetComponent <CameraController2>().SetToHeight(TierToCheck + 1);
                        CurrentBallVelocity = new Vector3(0, BallMaxVelocity, 0);
                        break;

                    case 2:     // 2 = Hazard ---- GAME OVER (will just reset)
                        GameRunning = false;
                        ResetBall();
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        BallHeight = Ball.transform.position.y; // IMPORTANT - this gives us frame to frame comparison
        if (BallHeight < 0)
        {
            ResetBall();
        }
    }