Beispiel #1
0
 public Vector2 GridToPosition(int col, int row)
 {
     CellManager.CellID cellId = new CellManager.CellID();
     cellId.x = col;
     cellId.y = row;
     return(CellManager.GetCellPosition(cellId));
 }
Beispiel #2
0
        public override void Update(float fDeltaTime)
        {
            base.Update(fDeltaTime);

            if (m_isOver)
            {
                return;
            }

            Vector2 lpos = m_ball.transform.localPosition;

            lpos += m_dir * m_cmd.Speed * fDeltaTime;

            if (CheckPoint(m_ball.transform.localPosition, lpos))
            {
                if (m_cmd.Result == 0 || m_cmd.Result == 2)
                {
                    GameObject.Destroy(m_ball);
                }
                else
                {
                    m_ball.transform.localPosition = CellManager.GetCellPosition(m_cmd.DestGrid);
                    m_balls.AddBall(m_cmd.BallId, m_ball, (ELevelBallType)m_cmd.Type);
                    m_ball.GetComponent <Collider2D>().enabled = true;
                    AudioMgr.PlayAudio(205);
                }
                m_ball   = null;
                m_isOver = true;
            }
            else
            {
                m_ball.transform.localPosition = lpos;
                Vector2 pos = m_ball.transform.position;
                if ((pos.x + GlobalData.m_ballRadius >= GlobalData.m_windowWidth / 2 ||
                     pos.x - GlobalData.m_ballRadius <= -GlobalData.m_windowWidth / 2))
                {
                    if (m_hasBouncedBack && (m_cmd.Result == 0 || m_cmd.Result == 2))
                    {
                        GameObject.Destroy(m_ball);
                        m_ball   = null;
                        m_isOver = true;
                        return;
                    }
                    m_dir.x          = -m_dir.x;
                    m_hasBouncedBack = true;
                    AudioMgr.PlayAudio(202);
                }
            }
        }
        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);
            }
        }
Beispiel #4
0
 public GridPosition PositionToGrid(Vector3 position)
 {
     return(CellManager.GetCellID(new Vector2(position.x, -position.y)));
 }