void SpawnObject()
    {
        // Declare construction parameters
        Direction direction;
        Vector2   spawnPosition = new Vector2();
        Color     color         = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f, 1f, 1f);
        int       speed         = (int)(Random.value * (MAX_SPEED - MIN_SPEED) + MIN_SPEED);

        // used variables
        float directionRandomizer = Random.value;
        float spawnRandomizer     = Random.Range(-RANGE, RANGE);

        // initialize parameters
        if (directionRandomizer < .25f)
        {
            direction = Direction.north;
            spawnPosition.Set(spawnRandomizer, -SPAWN_DISTANCE);
        }
        else if (directionRandomizer < .5f)
        {
            direction = Direction.south;
            spawnPosition.Set(spawnRandomizer, SPAWN_DISTANCE);
        }
        else if (directionRandomizer < .75f)
        {
            direction = Direction.east;
            spawnPosition.Set(-SPAWN_DISTANCE, spawnRandomizer);
        }
        else
        {
            direction = Direction.west;
            spawnPosition.Set(SPAWN_DISTANCE, spawnRandomizer);
        }

        // Instantiate
        LightBall lightball = Instantiate(objectToSpawn, spawnPosition, Quaternion.identity) as LightBall;

        // Set params
        lightball.SetUp(direction, speed, color);
    }
Exemple #2
0
    //重さを移すのに失敗して、移し元から共有ブロックへ光の弾が戻っていく状態
    //
    void UpdateReturnToShare()
    {
        if (mInitState == true)
        {
            mInitState = false;


            //共有ボックスの処理
            //

            ShareWeightBox lDestShare = mDest.GetComponent <ShareWeightBox>();
            mLightBallShare.Clear();

            //共有ボックスの数だけ光の弾を生成
            foreach (var s in lDestShare.GetShareAllListExceptOwn())
            {
                GameObject l = Instantiate(mLightBallPrefab, transform);
                l.GetComponent <LightBall>().InitPoint(GetMassPosition(mDest), GetMassPosition(s.gameObject));
                l.GetComponent <LightBall>().PlayEffect();
                mLightBallShare.Add(l);
            }


            //全ての光る球の到達する時間は一定だ
            //移す先の共有ボックスと、他の共有ボックスの一番近い距離を求め、その時間で到達するように速度を変更する
            //
            float lMinDistance = float.MaxValue;
            foreach (var l in mLightBallShare)
            {
                LightBall lc = l.GetComponent <LightBall>();
                lMinDistance = Mathf.Min((lc.From - lc.To).magnitude, lMinDistance);
            }

            foreach (var l in mLightBallShare)
            {
                LightBall lc = l.GetComponent <LightBall>();
                lc.mMoveSpeed = (lc.From - lc.To).magnitude / lMinDistance * mLightBallTemplate.GetComponent <LightBall>().mMoveSpeed;
            }

            SoundManager.SPlay(mShiftDestSE);
        }


        //全ての光の弾が他の共有ボックスへ到達するまで、光の弾の更新を続ける
        //

        var lShareList = mSource.GetComponent <ShareWeightBox>().GetShareAllListExceptOwn();

        bool lAllReach = true;

        for (int i = 0; i < mLightBallShare.Count; i++)
        {
            LightBall      l = mLightBallShare[i].GetComponent <LightBall>();
            ShareWeightBox s = lShareList[i].GetComponent <ShareWeightBox>();
            l.SetPoint(GetMassPosition(mDest), GetMassPosition(s.gameObject));
            l.UpdatePoint();
            if (l.IsReached == false)
            {
                lAllReach = false;
            }
        }

        //全て到達したら
        if (lAllReach == true)
        {
            //光の弾の削除
            foreach (var s in mLightBallShare)
            {
                DestroyLightBall(s);
            }

            //見かけの重さを戻す
            foreach (var s in mDest.GetComponent <ShareWeightBox>().GetShareAllListExceptOwn())
            {
                s.GetComponent <WeightManager>().WeightLvSeem += GetShiftWeight();
            }
            ChangeState(CSelectState.cFail);                //失敗状態へ
            SoundManager.SPlay(mShiftDestSE);
        }
    }
Exemple #3
0
    //共有ボックスが移し元になり、他の共有ブロックの重さが移ってくる状態
    void UpdateMoveFromShare()
    {
        if (mInitState == true)
        {
            mInitState = false;

            //カーソルを移せない表示に
            ChangeCursorState(CCursorState.cCanNotShift);

            //移す線を非表示に
            mMassShiftLine.SetActive(false);

            //選択先のハイライトを消し、移し先のハイライトを表示
            ShowModelHilight(mSelect, false, Color.white);
            ShowModelHilight(mDest, true, mDestColor * mDestColorPower);


            //共有ボックスの処理
            //

            ShareWeightBox lSourceShare = mSource.GetComponent <ShareWeightBox>();
            mLightBallShare.Clear();

            //共有ボックスの数だけ光の弾を生成
            foreach (var s in lSourceShare.GetShareAllListExceptOwn())
            {
                GameObject l = Instantiate(mLightBallPrefab, transform);
                l.GetComponent <LightBall>().InitPoint(GetMassPosition(s.gameObject), GetMassPosition(mSource));
                l.GetComponent <LightBall>().PlayEffect();
                mLightBallShare.Add(l);

                s.GetComponent <WeightManager>().WeightLvSeem -= GetShiftWeight();                      //見かけの重さを減らす
            }


            //全ての光る球の到達する時間は一定だ
            //移す元の共有ボックスと、他の共有ボックスの一番近い距離を求め、その時間で到達するように速度を変更する
            //
            float lMinDistance = float.MaxValue;
            foreach (var l in mLightBallShare)
            {
                LightBall lc = l.GetComponent <LightBall>();
                lMinDistance = Mathf.Min((lc.From - lc.To).magnitude, lMinDistance);
            }

            foreach (var l in mLightBallShare)
            {
                LightBall lc = l.GetComponent <LightBall>();
                lc.mMoveSpeed = (lc.From - lc.To).magnitude / lMinDistance * mLightBallTemplate.GetComponent <LightBall>().mMoveSpeed;
            }

            SoundManager.SPlay(mShiftSourceSE);
        }


        //全ての光の弾が移し元へ到達するまで、光の弾の更新を続ける
        //

        var lShareList = mSource.GetComponent <ShareWeightBox>().GetShareAllListExceptOwn();

        bool lAllReach = true;

        for (int i = 0; i < mLightBallShare.Count; i++)
        {
            LightBall      l = mLightBallShare[i].GetComponent <LightBall>();
            ShareWeightBox s = lShareList[i].GetComponent <ShareWeightBox>();
            l.SetPoint(GetMassPosition(s.gameObject), GetMassPosition(mSource));
            l.UpdatePoint();
            if (l.IsReached == false)
            {
                lAllReach = false;
            }
        }

        //全て届いたら
        if (lAllReach == true)
        {
            //光の弾を消去する
            foreach (var s in mLightBallShare)
            {
                DestroyLightBall(s);
            }
            ChangeState(CSelectState.cMoveSourceToDest);                //移し元から移し先へ移す状態へ
        }
    }