예제 #1
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
        /// <summary>
        /// 縦方向に移動できるかチェック
        /// </summary>
        /// <param name="data"></param>
        /// <param name="moveY"></param>
        /// <returns></returns>
        private bool CheckMovingVertical(TamaData data, int moveY)
        {
            if (data == null)
            {
                return(false);
            }

            int newY = data.Y + moveY;

            // 半分浮いているなら縦に移動可能
            if (data.Half)
            {
                return(true);
            }
            // 枠のチェック
            if ((newY < 0) || (newY >= setting.rowsCount))
            {
                return(false);
            }
            // フィールドのチェック
            if (GetTamaFromField(data.X, newY) != null)
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// たまをキャッシュ
        /// </summary>
        public void InitTamaCache(PlayFieldSetting setting, Transform transform)
        {
            if (tamaCache != null)
            {
                return;
            }
            var count = setting.columnsCount * setting.rowsCount + 4;

            tamaCache = new Stack <TamaData>(count);
            for (int i = 0; i < count; ++i)
            {
                var s = GameObject.Instantiate <SpriteRenderer>(tamaPrefab);
                //s.sprite = atlas.GetSprite("l01");
                s.transform.parent        = transform;
                s.transform.localPosition = Vector3.zero;
                s.transform.localScale    = Vector3.one;
                s.enabled = false;
                var e    = s.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>();
                var tama = new TamaData()
                {
                    Sprite = s, Spark = e
                };
                tamaCache.Push(tama);
            }
        }
예제 #3
0
        /// <summary>
        /// たまのペアを回転
        /// </summary>
        /// <param name="main"></param>
        /// <param name="sub"></param>
        /// <param name="cw">true:時計回り</param>
        private void RotateTamaPair(TamaData main, TamaData sub, bool cw)
        {
            (int rotX, int rotY) = CalculateRotateOffset(main, sub, cw);
            int subX = main.X + rotX;
            int subY = main.Y + rotY;

            // フィールドが空ではない場合
            if (!CheckFieldBlank(subX, subY))
            {
                // メインが動かせるかチェック
                if (CheckMove(main, -rotX, -rotY))
                {
                    subX = main.X + rotX;
                    subY = main.Y + rotY;
                }
                // 動かせなくて縦なら上下入れ替え
                else if (main.X == sub.X)
                {
                    int x     = main.X;
                    int mainY = sub.Y;
                    subY = main.Y;
                    SetTamaPosition(main, x, mainY);
                    SetTamaPosition(sub, x, subY);
                    return;
                }
            }
            // サブの位置を確定
            SetTamaPosition(sub, subX, subY);
        }
예제 #4
0
        /// <summary>
        /// たまをキャッシュに戻す
        /// </summary>
        /// <param name="data"></param>
        public void ReleaseTama(TamaData data)
        {
            data.Sprite.enabled = false;
            data.Spark.enabled  = false;

            tamaCache.Push(data);
        }
예제 #5
0
        /// <summary>
        /// たまを1つ生成
        /// </summary>
        /// <returns></returns>
        private TamaData GenerateTama()
        {
            TamaData data = tamaCache.Pop();

            data.Color = (ColorType)tamaRand.Next(4);
            data.Half  = false;
            return(data);
        }
예제 #6
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
 /// <summary>
 /// たまを右に動かす
 /// </summary>
 /// <param name="data"></param>
 /// <param name="x"></param>
 private void MoveTamaRight(TamaData data, int x = 1)
 {
     if (data == null)
     {
         return;
     }
     SetTamaPosition(data, data.X + x, data.Y);
 }
예제 #7
0
        private (int, int) CalculateRotateOffset(TamaData main, TamaData sub, bool cw)
        {
            // サブのオフセット
            int x = sub.X - main.X;
            int y = sub.Y - main.Y;

            // 回転後のオフセット
            return(cw ? (y, -x) : (-y, x));
        }
예제 #8
0
        /// <summary>
        /// こうげきだまを1つ生成
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public TamaData GenerateAttackTama(ColorType color)
        {
            TamaData data = tamaCache.Pop();

            data.Color = color;
            data.Half  = false;
            data.State = TamaStateType.Small;
            SetupTamaSprite(data);
            return(data);
        }
예제 #9
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
        /// <summary>
        /// たまのペアを上に動かす
        /// </summary>
        /// <param name="main"></param>
        /// <param name="sub"></param>
        /// <param name="y"></param>
        /// <returns>動かしたらtrue</returns>
        private bool MoveTamaPairUp(TamaData main, TamaData sub)
        {
            if (!CheckMovingVertical(main, 1) || !CheckMovingVertical(sub, 1))
            {
                return(false);
            }

            MoveTamaUp(main);
            MoveTamaUp(sub);
            return(true);
        }
예제 #10
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
        /// <summary>
        /// たまのペアを右に動かす
        /// </summary>
        /// <param name="main"></param>
        /// <param name="sub"></param>
        /// <param name="x"></param>
        /// <returns>動かしたらtrue</returns>
        private bool MoveTamaPairRight(TamaData main, TamaData sub, int x = 1)
        {
            if (!CheckMovingHorizontal(main, 1) || !CheckMovingHorizontal(sub, 1))
            {
                return(false);
            }

            MoveTamaRight(main, x);
            MoveTamaRight(sub, x);
            return(true);
        }
예제 #11
0
        /// <summary>
        /// 指定方向に動かせるなら動かす
        /// </summary>
        /// <param name="main"></param>
        /// <param name="moveX"></param>
        /// <param name="moveY"></param>
        /// <returns></returns>
        private bool CheckMove(TamaData main, int moveX, int moveY)
        {
            int x = main.X + moveX;
            int y = main.Y + moveY;

            if (GetTamaFromField(x, y) != null)
            {
                return(false);
            }
            // 動かせるなら動かす
            SetTamaPosition(main, x, y);
            return(true);
        }
예제 #12
0
        /// <summary>
        /// たまの見た目を設定
        /// </summary>
        /// <param name="data"></param>
        /// <param name="col"></param>
        /// <param name="row"></param>
        private void SetupTamaSprite(TamaData data)
        {
            int index = (int)data.Color;

            if (data.State == TamaStateType.Small)
            {
                index += 4;
            }
            data.Sprite.sprite  = tamaSprites[index];
            data.Sprite.enabled = true;
            //data.Sprite.transform.localPosition = new Vector3(setting.cellSize * col, setting.cellSize * row, 0);
            data.Sprite.transform.localScale = Vector3.one;

            data.Spark.enabled = false;
        }
예제 #13
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
        /// <summary>
        /// たまの位置を設定
        /// </summary>
        private void SetTamaPosition(TamaData data, int col, int row)
        {
            if (data == null)
            {
                return;
            }
            data.X = col;
            data.Y = row;
            float y = (float)row;

            if (data.Half)
            {
                y += 0.5f;            // 半分浮いている
            }
            data.Sprite.transform.localPosition = new Vector3(setting.cellSize * col, setting.cellSize * y, 0);
        }
예제 #14
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
        /// <summary>
        /// 横方向に移動できるかどうかチェックする
        /// </summary>
        /// <param name="data"></param>
        /// <param name="moveX"></param>
        /// <returns></returns>
        private bool CheckMovingHorizontal(TamaData data, int moveX)
        {
            int newX = data.X + moveX;

            // 枠のチェック
            if ((newX < 0) || (newX >= setting.columnsCount))
            {
                return(false);
            }
            // フィールドのチェック
            if (GetTamaFromField(newX, data.Y) != null)
            {
                return(false);
            }

            return(true);
        }
예제 #15
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
 /// <summary>
 /// たまを下に動かす
 /// </summary>
 /// <param name="data"></param>
 /// <param name="useHalf">半分ずつ動かすかどうか</param>
 private void MoveTamaDown(TamaData data, bool useHalf = true)
 {
     if (data == null)
     {
         return;
     }
     // 半分浮いてる場合
     if (data.Half)
     {
         data.Half = false;
         SetTamaPosition(data, data.X, data.Y);
     }
     else
     {
         data.Half = useHalf;
         SetTamaPosition(data, data.X, data.Y - 1);
     }
 }
예제 #16
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
 /// <summary>
 /// たまを上に動かす
 /// </summary>
 /// <param name="data"></param>
 /// <param name="useHalf">半分ずつ動かすかどうか</param>
 private void MoveTamaUp(TamaData data, bool useHalf = true)
 {
     if (data == null)
     {
         return;
     }
     if (data.Half || !useHalf)
     {
         // 半分浮いてるか、半分ずつ動かさないなら一つ上にあげる
         data.Half = false;
         SetTamaPosition(data, data.X, data.Y + 1);
     }
     else
     {
         // 半分浮かせる
         data.Half = true;
         SetTamaPosition(data, data.X, data.Y);
     }
 }
예제 #17
0
        /// <summary>
        /// フィールドのたまを落下させる
        /// </summary>
        private bool DropTamaInFIeld()
        {
            bool falling = false;

            for (int x = 0; x < setting.columnsCount; ++x)
            {
                for (int y = 0; y < setting.rowsCount; ++y)
                {
                    //TamaData data = tamaField[y, x];
                    TamaData data = GetTamaFromField(x, y);
                    if ((data != null) && (CheckMovingVertical(data, -1)))
                    {
                        RemoveTamaFromField(x, y);
                        MoveTamaDown(data);
                        PutTamaToField(data);
                        falling = true;
                    }
                }
            }
            return(falling);
        }
예제 #18
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
 /// <summary>
 /// たまを現在の座標に設置
 /// </summary>
 /// <param name="data"></param>
 private void PutTamaToField(TamaData data)
 {
     PutTamaToField(data.X, data.Y, data);
 }
예제 #19
0
 /// <summary>
 /// 接続をチェック
 /// </summary>
 /// <param name="data"></param>
 /// <param name="group"></param>
 /// <param name="found"></param>
 /// <returns>連結されたものある場合true</returns>
 private bool CheckTamaFieldLink(TamaData data, int group, bool found = false)
 {
     // 隣
     (int x, int y, bool b)[] nexts =
예제 #20
0
파일: PlayField.cs 프로젝트: uyamae/Pzldm
 /// <summary>
 /// フィールドのたまを設置
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="data"></param>
 private void PutTamaToField(int x, int y, TamaData data)
 {
     tamaField[y, x] = data;
 }