Exemplo n.º 1
0
 // 投球 - 設定球的方向與出力
 void Pitching()
 {
     level = ballnum / 3;
     if (!ControlActtive)
     {
         target.transform.localPosition = new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), 0);
         //前五個level,每個levle一種球路;其餘球路隨機,5、6 level 球速逐漸增加;7、8變速;
         if (level < 5)
         {
             initialSpeed = Random.Range(SpeedMin, SpeedMax);
             balltype     = (Ball.Type)level;
         }
         else
         {
             balltype = (Ball.Type)Random.Range(0, 5);
             if (level < 7)
             {
                 initialSpeed = Random.Range(++SpeedMin, ++SpeedMax);
             }
             else if (level < 9)
             {
                 tmp = Random.Range(0, 2);
                 if (tmp == 0)
                 {
                     initialSpeed = Random.Range(10.0f, 20.0f);
                     changeSpeed  = Random.Range(1.5f, 3.0f);
                 }
                 else
                 {
                     initialSpeed = Random.Range(40.0f, 60.0f);
                     changeSpeed  = Random.Range(0.05f, 0.3f);
                 }
             }
             else
             {
                 initialSpeed = Random.Range(++SpeedMin, ++SpeedMax);
                 tmp          = Random.Range(0, 10);
                 if (tmp >= 2)
                 {
                     if (changeSpeed <= 0.8)
                     {
                         changeMin += 0.02f;
                     }
                     changeSpeed = Random.Range(changeMin, 1.0f);
                 }
                 else
                 {
                     changeSpeed = 0.01f;
                 }
             }
         }
     }
     heldBall.GetComponent <Ball>().setShot(initialSpeed, balltype, changeSpeed);
     // heldBall.GetComponent<Ball>().setShot(60, balltype, 3.0f);
     heldBall.GetComponent <Ball>().setState(Ball.State.Flying1);
     ballnum++;
 }
Exemplo n.º 2
0
    private void SpawnBalls(int _id, Ball.Type _type, Ball.State _state)
    {
        if (_id >= lBalls.Count)
        {
            return;
        }

        // active ball
        Ball ball = lBalls[_id];

        // swap component (only for special ball)
        if (_type == Ball.Type.COLORFULL)
        {
            BallColorFull compBall = ball.gameObject.AddComponent <BallColorFull>();
            compBall.Clone(ball);
            Destroy(ball);

            lBalls[_id] = compBall;
            ball        = compBall;
        }
        else
        {
            if (ball.GetType() == Ball.Type.COLORFULL)
            {
                Ball compBall = ball.gameObject.AddComponent <Ball>();
                compBall.Clone(ball);
                Destroy(ball);

                lBalls[_id] = compBall;
                ball        = compBall;
            }
        }

        ball.SetType(_type);
        ball.SetActiveState(_state, true);

        // update list of small balls
        if (_state == Ball.State.GROWSMALL)
        {
            UpdateListSmallBalls(true, _id);
        }

        // update list empty tiles (remove this id)
        UpdateListEmptyTiles(false, _id);

        // DEBUG
        if (DebugUtils.IsDebugEnable())
        {
            Debug.Log("SPAWN BALL = " + _id);
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        if (controller.TouchpadButtonPressed)
        {
            moveTarget();
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
            balltype = Ball.Type.Fastball;
        }
        else if (Input.GetKeyDown(KeyCode.W))
        {
            balltype = Ball.Type.Curve;
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            balltype = Ball.Type.Slider;
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            balltype = Ball.Type.Snake;
        }
        else if (Input.GetKeyDown(KeyCode.T))
        {
            balltype = Ball.Type.Shadow;
        }
        else if (Input.GetKeyDown(KeyCode.A))
        {
            ControlActtive = !ControlActtive;
        }

        //動畫控制
        AnimatorStateInfo asi = anim.GetCurrentAnimatorStateInfo(0);

        if (asi.IsName("Throw_1"))
        {
            anim.SetBool("throw_1", false);
            Manager.instance.IsbackPos = false;
        }
        else if (asi.IsName("Idle 0"))
        {
            Manager.instance.IsbackPos = true;
        }
    }
Exemplo n.º 4
0
    public static Sprite GetSprite(Ball.Type _type)
    {
        // default color for special type
        if (_type == Type.COLORFULL)
        {
            _type = Type.BLUE;
        }

        string spriteKey = GameConfig.ballImgPath.Replace("{0}", _type.ToString().ToLower());

        Sprite sprite = Resources.Load <Sprite>(spriteKey);

        if (sprite)
        {
            return(sprite);
        }
        else
        {
            Debug.LogError("Missing sprite of " + _type.ToString() + " ball");
        }

        return(null);
    }
Exemplo n.º 5
0
    public static void FindPathMathColor(List <Ball> _lBalls, int _boardDimension, List <int> _checkBalls, int _dir, ref List <int> _path)
    {
        if (_path.Count == 0)
        {
            return;
        }

        // check 8 direction
        int nextId = GetNextId(_boardDimension, _path[_path.Count - 1], _dir);

        if (nextId >= 0 && nextId < _lBalls.Count && _checkBalls.Contains(nextId))
        {
            // if match type
            Ball nextBall = _lBalls[nextId];
            Ball fstBall  = _lBalls[_path[0]];
            if (nextBall.GetState() == Ball.State.IDLE && nextBall.GetSize() == Ball.Size.BIG)
            {
                bool isKeepFinding = false;
                if (nextBall.GetType() == fstBall.GetType())
                {
                    isKeepFinding = true;
                }
                else if (nextBall.GetType() == Ball.Type.COLORFULL)
                {
                    isKeepFinding = true;
                }
                else if (fstBall.GetType() == Ball.Type.COLORFULL)
                {
                    int colorFullCounter = 0;
                    for (int i = 0; i < _path.Count; i++)
                    {
                        int       id   = _path[i];
                        Ball.Type type = _lBalls[id].GetType();
                        // get color of path (except ball: color full)
                        if (type != Ball.Type.COLORFULL && type == nextBall.GetType())
                        {
                            isKeepFinding = true;
                            break;
                        }
                        if (type == Ball.Type.COLORFULL)
                        {
                            colorFullCounter++;
                        }
                    }

                    // if all balls are colorfull
                    if (!isKeepFinding && colorFullCounter == _path.Count)
                    {
                        isKeepFinding = true;
                    }
                }

                if (isKeepFinding)
                {
                    _path.Add(nextId);
                    // keep going find
                    FindPathMathColor(_lBalls, _boardDimension, _checkBalls, _dir, ref _path);
                }
            }
        }
    }
Exemplo n.º 6
0
    public void PlayMovingAnim(Ball.Type _type)
    {
        string animKey = "move_" + _type.ToString().ToLower();

        animator.Play(animKey);
    }
Exemplo n.º 7
0
    // ========================================================== PUBLIC FUNC ==========================================================
    public void PlayHighlightAnim(Ball.Type _type)
    {
        string animKey = "hl_" + _type.ToString().ToLower();

        animator.Play(animKey);
    }
Exemplo n.º 8
0
    // === spawn ball ===
    private void SpawnRandomBalls(Ball.State _state)
    {
        // gen balls
        List <int> spawnIds = new List <int>();
        int        turn     = Mathf.Min(GameConfig.ballSpawnPerTurn, lEmptyTiles.Count);

        // Random Position (not match prev pos)
        for (int i = 0; i < turn; i++)
        {
            int rdId = -1;
            do
            {
                rdId = (turn == GameConfig.ballSpawnPerTurn) ? Random.Range(0, lEmptyTiles.Count) : i;
            } while (rdId >= lEmptyTiles.Count || spawnIds.Contains(lEmptyTiles[rdId]));

            spawnIds.Add(lEmptyTiles[rdId]);
        }

        // Random Type
        List <Ball.Type> rdTypes = new List <Ball.Type>();

        for (int i = 0; i < 3; i++)
        {
            Ball.Type type = Ball.Type.BLUE;    // default color
            // get type from random list
            if (i < lnextTypes.Count)
            {
                rdTypes.Add(lnextTypes[i]);
            }
            else
            {
                // random type for this turn
                type = (Ball.Type)Random.Range((int)Ball.Type.BLUE, (int)Ball.Type.COUNT);
                rdTypes.Add(type);
            }

            // random for next turn
            type = (Ball.Type)Random.Range((int)Ball.Type.BLUE, (int)Ball.Type.COUNT);
            if (i < lnextTypes.Count)
            {
                lnextTypes[i] = (type);
            }
            else
            {
                lnextTypes.Add(type);
            }
        }

        for (int i = 0; i < spawnIds.Count; i++)
        {
            SpawnBalls(spawnIds[i], rdTypes[i], _state);
        }

        // Show Panel
        if (lnextTypes.Count >= 3)
        {
            TopPanelMgr.instance.RefreshBallPanel(Ball.GetSprite(lnextTypes[0]), Ball.GetSprite(lnextTypes[1]), Ball.GetSprite(lnextTypes[2]));
        }

        // GAME OVER (out of slot of ball to spawn)
        if (turn < GameConfig.ballSpawnPerTurn || lEmptyTiles.Count <= 0)
        {
            GameMgr.Instance.OnGameOver();

            if (DebugUtils.IsDebugEnable())
            {
                Debug.Log("GAME OVER");
            }
        }
    }