Пример #1
0
 public void AddBall(int id, GameObject ball, ELevelBallType type)
 {
     base.Add(id, ball);
     if (!m_ballsTypeDic.ContainsKey(id))
     {
         m_ballsTypeDic.Add(id, type);
     }
 }
Пример #2
0
        public GameObject GetBallResource(ELevelBallType type)
        {
            if (m_ballResources.ContainsKey(type))
            {
                return(m_ballResources[type]);
            }

            return(null);
        }
Пример #3
0
 public void RandomMap()
 {
     for (int col = -20; col <= 0; col++)
     {
         for (int row = -3; row <= 3; row++)
         {
             ELevelBallType type = (ELevelBallType)UnityEngine.Random.Range(0, 6);
             AddBall(col, row, type);
         }
     }
 }
Пример #4
0
        public void ExChangeBall(int side)
        {
            GameObject     ballTmp     = m_waitBalls[side];
            ELevelBallType ballTypeTmp = m_waitBallsType[side];

            m_waitBalls[side]         = m_waitBalls[side + 2];
            m_waitBallsType[side]     = m_waitBallsType[side + 2];
            m_waitBalls[side + 2]     = ballTmp;
            m_waitBallsType[side + 2] = ballTypeTmp;
            m_isExBall[side]          = true;
            m_exBallTimer[side]       = 0f;
        }
Пример #5
0
 public void TryEraseBubble(ServerBubble bubble, ELevelBallType type, List <ServerBubble> eraseBubbles)
 {
     for (int i = 0; i < bubble.NeighborGrids.Count; i++)
     {
         ServerBubble neighbor = GetBubbleByGrid(bubble.NeighborGrids[i]);
         if (neighbor != null && neighbor.isVisited == false)
         {
             neighbor.isVisited = true;
             if (neighbor.CanErase(type))
             {
                 eraseBubbles.Add(neighbor);
                 TryEraseBubble(neighbor, type, eraseBubbles);
             }
         }
     }
 }
Пример #6
0
        private void SendMessage(int side, ELevelBallType type, Vector2 startPos, Vector2 dir, Vector2 hitPoint, bool isFlyout, float flyDistance)
        {
            Vector2 point     = m_battleFieldObj.transform.InverseTransformPoint(hitPoint);
            Vector2 cellPoint = point;
            float   speed     = flyDistance / ConfigHelper.GetBubbleFlyDuration();

            cellPoint.y = -cellPoint.y;
            if (GameCore.Instance.IsOfflineMode)
            {
                CmdFireBallResponse cmd = new CmdFireBallResponse(0, (int)type, startPos, dir, point, CellManager.GetCellID(cellPoint), m_lastBallId, speed, 0);
                ++m_lastBallId;
                m_battle.HandleBattleCommand(cmd);
            }
            else
            {
                ProtoCSBattleCommand proto = new ProtoCSBattleCommand(new CmdFireBall(side, (int)type, startPos, dir, point, CellManager.GetCellID(cellPoint), isFlyout, speed));
                NetworkMgr.Instance.Send(proto);
            }
        }
Пример #7
0
        public void SetBall(int col, int row, ELevelBallType type)
        {
            GridPosition gridId  = new GridPosition(col, row);
            bool         needSet = true;

            if (Balls.ContainsKey(gridId))
            {
                if (Balls[gridId].Type != type)
                {
                    RemoveBall(col, row);
                }
                else
                {
                    needSet = false;
                }
            }

            if (needSet)
            {
                AddBall(col, row, type);
            }
        }
Пример #8
0
        public void AddBall(int col, int row, ELevelBallType type)
        {
            GameObject prefab = BallPrefabs[type];
            GameObject ball   = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

            ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString());
            ball.transform.SetParent(this.transform);
            ball.transform.localPosition = GridToPosition(col, row);
            //ball.hideFlags = HideFlags.HideInHierarchy;
            LevelBall newball = ball.GetComponent <LevelBall>();

            newball.Id = NewBallId;
            List <LevelBall> connectedBalls = new List <LevelBall>();

            GetConnectedBalls(col, row, connectedBalls);
            foreach (var b in connectedBalls)
            {
                newball.Connections.Add(b);
                b.Connections.Add(newball);
            }

            Balls.Add(new GridPosition(col, row), newball);
        }
Пример #9
0
        public void LoadLevelMap()
        {
            byte[]       databytes = File.ReadAllBytes(GetLevelDataPath(LevelId));
            LevelMapData data      = new LevelMapData();

            data.LoadFromBytes(databytes);
            MapType = (ELevelMapType)data.mapType;

            nextBallId = data.maxBallId + 1;

            foreach (var ballData in data.balls)
            {
                ELevelBallType type   = (ELevelBallType)ballData.type;
                int            col    = ballData.grids[0].col;
                int            row    = ballData.grids[0].row;
                int            ballId = ballData.id;

                GameObject prefab = BallPrefabs[type];
                GameObject ball   = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString());
                ball.transform.SetParent(this.transform);
                ball.transform.localPosition = GridToPosition(col, row);
                ball.hideFlags = HideFlags.HideInHierarchy;
                LevelBall newball = ball.GetComponent <LevelBall>();
                newball.Id = ballId;

                List <LevelBall> connectedBalls = new List <LevelBall>();
                GetConnectedBalls(col, row, connectedBalls);
                foreach (var b in connectedBalls)
                {
                    newball.Connections.Add(b);
                    b.Connections.Add(newball);
                }

                Balls.Add(new GridPosition(col, row), newball);
            }
        }
Пример #10
0
 public bool CanErase(ELevelBallType type)
 {
     return(m_type == type);
 }
Пример #11
0
 public ServerBubble(int id, ELevelBallType type, List <GridPosition> grids)
 {
     m_id         = id;
     m_type       = type;
     m_takenGrids = grids;
 }
Пример #12
0
        public void CalFireBall(int side, ELevelBallType type, Vector2 startPos, Vector2 fingerPos, float lineLength = 0f, bool isPresent = false)
        {
            ClearLineRender();
            float drawLineLength = lineLength;

            Vector2 dir        = (fingerPos - startPos).normalized;
            Vector2 startPoint = startPos;

            Vector2 normal = dir;

            if (normal.y == 0)
            {
                Debug.Log("CallFireBall Y shoud != 0!");
                return;
            }

            float flyDistance    = 0;
            bool  isCalOver      = false;
            bool  hasBouncedBack = false;

            do
            {
                Vector2 endPos = RayCast(startPoint, normal);
                if (m_hit.collider == null)
                {
                    flyDistance += Vector2.Distance(startPoint, endPos);
                    if (isPresent)
                    {
                        drawLineLength -= DrawLine(startPoint, endPos, normal, drawLineLength);
                    }

                    if (endPos.y >= GlobalData.m_windowHight / 2 || endPos.y <= (-GlobalData.m_windowHight / 2) || hasBouncedBack)
                    {
                        //打空了
                        if (!isPresent)
                        {
                            SendMessage(side, type, startPos, dir, endPos, true, flyDistance);
                        }
                        return;
                    }

                    startPoint     = endPos;
                    normal.x       = -normal.x;
                    hasBouncedBack = true;
                }
                else
                {
                    //打中了
                    flyDistance += Vector2.Distance(startPoint, m_hit.point);
                    if (isPresent)
                    {
                        drawLineLength -= DrawLine(startPoint, m_hit.point, normal, drawLineLength);
                    }
                    else
                    {
                        SendMessage(side, type, startPos, dir, m_hit.point, false, flyDistance);
                    }

                    isCalOver = true;
                }
            } while (!isCalOver);
        }