示例#1
0
    /// <summary>
    /// 丸太を割る
    /// </summary>
    private void CrackWood()
    {
        Vector2 pPoint = playerManager.GetPlayerMapPoint();
        Vector2 fPoint = mapManager.GetFindPoint((int)pPoint.y, (int)pPoint.x, playerManager.GetPlayerDirection(), 1);

        if (mapManager.IsOnWood(pPoint) && mapManager.IsOnWood(fPoint))
        {
            Wood w1 = woodManager.GetIncludedPointWood(pPoint);
            Wood w2 = woodManager.GetIncludedPointWood(fPoint);
            if (w1 == w2)
            {
                Direction.DirectionState pDir = playerManager.GetPlayerDirection();
                Direction.DirectionState wDir = w1.GetDirection();
                int     l1;
                int     l2;
                Vector2 rPoint = w1.GetRootPoint();
                if (pDir == wDir)
                {
                    if (pDir == Direction.DirectionState.Up || pDir == Direction.DirectionState.Down)
                    {
                        l1 = (int)Mathf.Abs(pPoint.y - rPoint.y) + 1;
                        l2 = w1.GetLength() - l1;
                    }
                    else
                    {
                        l1 = (int)Mathf.Abs(pPoint.x - rPoint.x) + 1;
                        l2 = w1.GetLength() - l1;
                    }
                }
                else
                {
                    if (pDir == Direction.DirectionState.Up || pDir == Direction.DirectionState.Down)
                    {
                        l2 = (int)Mathf.Abs(pPoint.y - rPoint.y);
                        l1 = w1.GetLength() - l2;
                    }
                    else
                    {
                        l2 = (int)Mathf.Abs(pPoint.x - rPoint.x);
                        l1 = w1.GetLength() - l2;
                    }
                }
                woodManager.WoodCreate(pPoint * mapManager.GetMapChipSize() * new Vector2(1, -1), Direction.GetReverseDirection(pDir), l1); //自マス
                woodManager.SetWoodRootPoint(woodManager.GetWoodsLastNumber(), pPoint);
                woodManager.WoodCreate(fPoint * mapManager.GetMapChipSize() * new Vector2(1, -1), pDir, l2);                                //前マス
                woodManager.SetWoodRootPoint(woodManager.GetWoodsLastNumber(), fPoint);
                woodManager.ChangeWoodsLayer();
                w1.Crack();
            }
        }
    }
示例#2
0
    private void PlayerMoveUpdate()
    {
        if (playerManager.GetPlayerMode() == 1)//プレイヤーが移動待機状態なら
        {
            Vector2 playerDestination = mapManager.GetFindPoint((int)playerManager.GetPlayerMapPoint().y,
                                                                (int)playerManager.GetPlayerMapPoint().x,
                                                                playerManager.GetPlayerDirection(), 1); //プレイヤーの移動先のポイントを取得
            Wood nowPointWood         = null;                                                           //現在地の木
            Wood destinationPointWood = null;                                                           //移動先の木
            if (mapManager.IsOnWood(playerManager.GetPlayerMapPoint()))                                 //プレイヤーが木に乗っていたら
            {
                nowPointWood = woodManager.GetIncludedPointWood(playerManager.GetPlayerMapPoint());     //乗っている木を取得
            }
            if (mapManager.IsOnWood(playerDestination))                                                 //移動先に木があるなら
            {
                destinationPointWood = woodManager.GetIncludedPointWood(playerDestination);             //移動先の木を取得
            }



            //ここからそもそも移動が出来る状態か判断


            if (!mapManager.IsOnWood(playerManager.GetPlayerMapPoint()))                             //プレイヤーが丸太に乗っていない時
            {
                if (mapManager.IsOnWood(playerDestination) && mapManager.IsRiver(playerDestination)) //移動先が丸太かつ川なら
                {
                    if (destinationPointWood.GetState() == 3)                                        //丸太が流れているなら
                    {
                        playerManager.PlayerStop();                                                  //プレイヤーを止めて
                        return;                                                                      //移動しない
                    }

                    if (!Direction.IsSameAxis(playerManager.GetPlayerDirection(), destinationPointWood.GetDirection())) //方向軸が違うなら
                    {
                        foreach (Vector2 dwp in destinationPointWood.GetMapPoints())                                    //その丸太が一か所でも
                        {
                            if (!mapManager.IsRiver(dwp))                                                               //川でないマスがあれば(全て川に入って無ければ)
                            {
                                playerManager.PlayerStop();                                                             //プレイヤーを止めて
                                return;                                                                                 //移動しない
                            }
                        }
                    }
                }
            }
            if (mapManager.IsOnWood(playerManager.GetPlayerMapPoint()))                                             //プレイヤーが丸太に乗っていたら
            {
                foreach (Vector2 nwp in nowPointWood.GetMapPoints())                                                //プレイヤーの乗る丸太が一か所でも
                {
                    if (!mapManager.IsRiver(nwp))                                                                   //川でないマスがあれば(全て川に入って無ければ)
                    {
                        if (!Direction.IsSameAxis(playerManager.GetPlayerDirection(), nowPointWood.GetDirection())) //軸が違えば
                        {
                            playerManager.PlayerStop();                                                             //プレイヤーを止めて
                            return;                                                                                 //移動しない
                        }
                    }
                }

                if (mapManager.IsRiver(playerDestination))                                                                              //移動先が川で
                {
                    if (mapManager.IsOnWood(playerDestination))                                                                         //丸太があるなら
                    {
                        if (destinationPointWood != nowPointWood)                                                                       //その丸太が今乗っている丸太と違うなら
                        {
                            if (destinationPointWood.GetState() == 3)                                                                   //丸太が流れているなら
                            {
                                playerManager.PlayerStop();                                                                             //プレイヤーを止めて
                                return;                                                                                                 //移動しない
                            }
                            foreach (Vector2 dwp in destinationPointWood.GetMapPoints())                                                //その丸太が一か所でも
                            {
                                if (!mapManager.IsRiver(dwp))                                                                           //川でないマスがあれば(全て川に入って無ければ)
                                {
                                    if (!Direction.IsSameAxis(playerManager.GetPlayerDirection(), destinationPointWood.GetDirection())) //軸が違うなら
                                    {
                                        playerManager.PlayerStop();                                                                     //プレイヤーを止めて
                                        return;                                                                                         //移動しない
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //ここから移動したいマスに侵入できるかの判断

            if (mapManager.IsPlayerEnterMapchip(playerManager.GetPlayerDirection(), playerManager.GetPlayerMapPoint()))//移動したいマスにプレイヤーが侵入できるなら
            {
                if (nowPointWood != destinationPointWood || (mapManager.IsOnWood(playerManager.GetPlayerMapPoint()) && mapManager.IsRiver(playerManager.GetPlayerMapPoint())))
                {
                    if (mapManager.IsOnWood(playerDestination) && !mapManager.IsRiver(playerDestination))//移動先に丸太があって川でないなら
                    {
                        //Debug.Log("PlayerDestinationOnWood");
                        destinationPointWood = woodManager.GetIncludedPointWood(playerDestination);                                                                                                                //その丸太を取得
                                                                                                                                                                                                                   //Debug.Log(dw);
                        if (!Direction.IsSameAxis(playerManager.GetPlayerDirection(), destinationPointWood.GetDirection()))                                                                                        //プレイヤーの移動方向軸と丸太の方向軸が違うなら
                        {
                            for (int i = 0; i < destinationPointWood.GetLength(); i++)                                                                                                                             //丸太の長さ分
                            {
                                Vector2 woodPoint       = mapManager.GetFindPoint((int)destinationPointWood.GetRootPoint().y, (int)destinationPointWood.GetRootPoint().x, destinationPointWood.GetDirection(), i); //丸太のマス一つ分の現在地マス
                                Vector2 woodDistination = mapManager.GetFindPoint((int)woodPoint.y, (int)woodPoint.x, playerManager.GetPlayerDirection(), 1);                                                      //丸太のマスの移動先1マス
                                if (!mapManager.IsCanEnterWood(woodDistination))                                                                                                                                   //1マスでも丸太が侵入できないますがあれば
                                {
                                    playerManager.PlayerStop();                                                                                                                                                    //プレイヤーを止めて
                                                                                                                                                                                                                   //Debug.Log("Return");
                                    return;                                                                                                                                                                        //移動しない
                                }
                            }
                            //ここまでくると丸太移動が出来ることが確定
                            destinationPointWood.MoveSet(playerManager.GetPlayerDirection()); //丸太をプレイヤーの移動方向へ移動させる
                            Vector2 dwRootPoint = destinationPointWood.GetRootPoint();        //丸太の根本のマス目を取得
                            for (int i = 0; i < destinationPointWood.GetLength(); i++)        //その丸太全てに対し
                            {
                                Vector2 woodPoint       = mapManager.GetFindPoint((int)dwRootPoint.y, (int)dwRootPoint.x, destinationPointWood.GetDirection(), i);
                                Vector2 woodDistination = mapManager.GetFindPoint((int)woodPoint.y, (int)woodPoint.x, playerManager.GetPlayerDirection(), 1);
                                destinationPointWood.ChangeMapPoints(i, woodDistination);                //丸太に自身の場所データを変更させる
                                mapManager.RemoveWood(woodPoint);                                        //もともと乗っていたマス目を乗っていないことに
                                                                                                         //Debug.Log("woodPoint:" + woodPoint);
                                                                                                         //Debug.Log("woodDistination:" + woodDistination);
                                mapManager.OnWood(woodDistination, destinationPointWood.GetDirection()); //移動先のマス目に乗っているように
                            }
                            if (playerManager.GetPlayerDirection() != Direction.DirectionState.Up)       //上に行かないなら
                            {
                                destinationPointWood.ChangeLayer();                                      //丸太のレイヤーを変更
                            }
                        }
                    }
                }
                if (mapManager.IsOnWood(playerManager.GetPlayerMapPoint()) && !mapManager.IsOnWood(playerDestination))
                {
                    playerManager.PlayerOffsetRemove();
                }
                if (mapManager.IsOnWood(playerDestination) && !mapManager.IsOnWood(playerManager.GetPlayerMapPoint()))
                {
                    playerManager.PlayerOffsetAdd();
                }
                playerManager.PlayerMoveStart();//プレイヤー移動開始
                if (playerManager.GetPlayerDirection() != Direction.DirectionState.Up)
                {
                    playerManager.ChangePlayerLayer();
                    if (destinationPointWood != null)
                    {
                        playerManager.SetPlayerLayer(destinationPointWood.GetMaxPointHeight());
                    }
                }
            }
            else//移動したいマスにプレイヤーが移動出来ないなら
            {
                playerManager.PlayerStop();//プレイヤーを止める
            }
        }
    }