Exemple #1
0
        private int CalcSquareDistanceWeight(GpsMapCell gmc1, GpsMapCell gmc2)
        {
            int x = gmc1.Row - gmc2.Row;
            int y = gmc1.Col - gmc2.Col;

            return(x * x + y * y);
        }
Exemple #2
0
    public void CreatBox()
    {
        actor = GameObject.Find("actor").transform;
        //playerPosition = PlayerControl.transform.position; //人物Position
        playerPosition = actor.position;
        GpsMapCell player = Document.Instance.Map.GetCell(playerPosition);

        go = null;

        for (int i = 0; i < 50; i++)
        {
            if (player.Row > 3 && player.Col > 6)
            {
                int x = Random.Range(player.Row - 1, player.Row + 1);           //行
                // int y = Random.Range(player.Col- 5, player.Col - 1) | Random.Range(player.Col + 1, player.Col + 5); ;//列
                int        y   = Random.Range(player.Col - 5, player.Col + 5);; //列
                GpsMapCell gmc = Document.Instance.Map.GetCell(x, y);           //获取对应格子
                if (x != player.Row && y != player.Col)
                {
                    if (gmc.Type == GpsMapCell.EType.EN_CROSS || gmc.Type == GpsMapCell.EType.EN_ROAD)
                    {
                        Vector3 targetPosition = Document.Instance.Map.GetCellPosition(gmc); //将格子转换为世界坐标
                        go = (GameObject)Instantiate(box);
                        go.transform.position = targetPosition;                              //当前的格子转换为世界坐标
                        XxdwDebugger.Log("生成宝箱");
                        break;
                    }
                }
            }
            if (go != null)
            {
                break;
            }
        }
    }
Exemple #3
0
    private void OnNotiKeyDown(Notification noti)
    {
        GameKey.EKey key = (GameKey.EKey)noti.Data;
        // GameKey.EKey modifier = (GameKey.EKey)noti.ExtraData;
        if (key == GameKey.EKey.K_A)//在老虎机的周围,按键A,生成道具(没有扣除金币数),没有调用接口
        {
            actor = GameObject.Find("actor").transform;
            //playerPosition = PlayerControl.transform.position; //人物Position
            playerPosition = actor.position;
            GpsMapCell player = Document.Instance.Map.GetCell(playerPosition);
            int        x1     = player.Row - tiger1.Row; //行
            int        y1     = player.Col - tiger1.Col; //列
            int        x2     = player.Row - tiger2.Row;
            int        y2     = player.Col - tiger2.Col;
            if (y1 < 3 && y1 > -3 && x1 < 1 && x1 > -1)
            {
                AudioSource.PlayClipAtPoint(get, TIGER_MACHINE1.transform.position);         //声音
                item = Document.Instance.OpenTigerMachine(Document.Instance.Getcode("T01")); //T01老虎机编号,调用接口
            }

            if (y2 < 3 && y2 > -3 && x2 < 1 && x2 > -1)
            {
                AudioSource.PlayClipAtPoint(get, TIGER_MACHINE2.transform.position);  //声音
                Document.Instance.OpenTigerMachine(Document.Instance.Getcode("T04")); //T01老虎机编号,调用接口
            }
        }
    }
Exemple #4
0
    public void Creatcoins()
    {
        int        x   = Random.Range(this.cell.Row - 3, this.cell.Row + 3);
        int        y   = Random.Range(this.cell.Col - 1, this.cell.Col + 1);
        GpsMapCell gmc = Document.Instance.Map.GetCell(x, y);//获取对应格子

        if (gmc.Type == GpsMapCell.EType.EN_CROSS || gmc.Type == GpsMapCell.EType.EN_ROAD)
        {
            Vector3    targetPosition = Document.Instance.Map.GetCellPosition(gmc); //将格子转换为世界坐标
            GameObject go1            = (GameObject)Instantiate(coin);
            go1.transform.position = targetPosition;                                //当前的格子转换为世界坐标
        }
    }
Exemple #5
0
        public GpsMapMonitorSpot FindMonitorSpotNearestTo(GpsMapCell gmc)
        {
            GpsMapMonitorSpot rs = null;

            int min = (int)Parameters.POSITIVE_INFINITE;

            foreach (GpsMapMonitorSpot gmms in this.listMonitorSpots)
            {
                int w = this.CalcSquareDistanceWeight(gmms.Cell, gmc.Index);
                if (w < min)
                {
                    min = w;
                    rs  = gmms;
                }
            }

            return(rs);
        }
Exemple #6
0
 public void CreatTIGER_MACHINE2()
 {
     TigerNum = "T02";
     while (TIGERMACHINE2 == null)
     {
         int        x   = Random.Range(0, Document.Instance.Map.RowNum - 1);
         int        y   = Random.Range(0, Document.Instance.Map.ColNum - 1);
         GpsMapCell gmc = Document.Instance.Map.GetCell(x, y);//获取对应格子
         if (gmc.Type == GpsMapCell.EType.EN_CROSS || gmc.Type == GpsMapCell.EType.EN_ROAD)
         {
             Vector3 targetPosition = Document.Instance.Map.GetCellPosition(gmc); //将格子转换为世界坐标
             TIGERMACHINE2 = (GameObject)Instantiate(TIGER_MACHINE2);
             TIGERMACHINE2.transform.position = targetPosition;                   //当前的格子转换为世界坐标
             tiger2 = gmc;
             break;
         }
     }
 }
Exemple #7
0
        // 找与建筑相连的路口
        public GpsMapCell FindCrossCellOfBuilding(GpsMapCell gmcBuilding)
        {
            List <GpsMapCell> listGmc       = new List <GpsMapCell>();
            List <GpsMapCell> listGmcClosed = new List <GpsMapCell>();

            listGmc.Add(gmcBuilding);

            while (listGmc.Count > 0)
            {
                GpsMapCell gmc = listGmc[0];
                listGmc.RemoveAt(0);
                int index = listGmcClosed.BinarySearch(gmc);
                if (index < 0)
                {
                    listGmcClosed.Insert(~index, gmc);
                }

                for (int n = 0; n < (int)Parameters.EDirection.DIR_NUM; n++)
                {
                    GpsMapCell neighbor = Neighbor(gmc, (Parameters.EDirection)n);
                    if (neighbor != null)
                    {
                        if (neighbor.IsCross())
                        {
                            return(neighbor);
                        }
                        else if (neighbor.IsBuilding() &&
                                 listGmcClosed.BinarySearch(neighbor) < 0 && !listGmc.Contains(neighbor))
                        {
                            listGmc.Add(neighbor);
                        }

                        if (Math.Abs(neighbor.Row - gmcBuilding.Row) > Parameters.MAX_SEARCH_CELL_RADIUS ||
                            Math.Abs(neighbor.Col - gmcBuilding.Col) > Parameters.MAX_SEARCH_CELL_RADIUS)
                        {
                            break;
                        }
                    }
                }
            }

            return(null);
        }
Exemple #8
0
 private GpsMapCell FindNearestCellOf(GpsMapCell gmc, GpsMapCell.EType type)
 {
     if (gmc.IsTypeOf(type))
     {
         return(gmc);
     }
     for (int k = 1; k <= Parameters.MAX_SEARCH_CELL_RADIUS; k++)
     {
         for (int n = 0; n < (int)Parameters.EDirection.DIR_NUM; n++)
         {
             GpsMapCell neighbor = Neighbor(gmc, (Parameters.EDirection)n, k);
             if (neighbor != null && neighbor.IsTypeOf(type))
             {
                 return(neighbor);
             }
         }
     }
     return(null);
 }
Exemple #9
0
        public bool IsNeighbor(GpsMapCell gmc, int cellIndex, int distance = 1)
        {
            bool rs = false;

            for (int d = 0; d < distance; d++)
            {
                for (int n = 0; n < (int)Parameters.EDirection.DIR_NUM; n++)
                {
                    GpsMapCell neighbor = Neighbor(gmc, (Parameters.EDirection)n, d);
                    if (neighbor != null && neighbor.Index == cellIndex)
                    {
                        rs = true;
                        goto LBL_END;
                    }
                }
            }

LBL_END:
            return(rs);
        }
Exemple #10
0
        // 输出的顶点数和边数相同
        public bool FindCross2CrossPaths(GpsMapCell fromCross, GpsMapCell toCross,
                                         out List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode, out List <MapPathGraph.Edge> listEdge, AStarHelper ash = null)
        {
            if (ash == null)
            {
                ash = new AStarHelper(this.CalcDistanceWeight);
            }
            ash.Clear();

            listNavigateVertexNode = new List <MapPathGraph.NavigateVertexNode>();
            listEdge = new List <MapPathGraph.Edge>();
            float weight = this.pathGraph.FindShortestPaths(ash,
                                                            this.pathGraph.GetVertex(fromCross.Index),
                                                            this.pathGraph.GetVertex(toCross.Index),
                                                            listNavigateVertexNode);

            this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);

            listNavigateVertexNode.RemoveAt(0); // 去掉首结点,因其不指导导航路径,与FindCell2CrossPath一致
            return(weight >= 0);
        }
Exemple #11
0
    //测试,调用道具类里的编号
    public void Creatitem()
    {
        actor = GameObject.Find("actor").transform;
        //playerPosition = PlayerControl.transform.position; //人物Position
        playerPosition = actor.position;
        GpsMapCell player = Document.Instance.Map.GetCell(playerPosition);
        GameObject go1;
        int        x   = Random.Range(player.Row - 3, player.Row + 3);
        int        y   = Random.Range(player.Col - 1, player.Col + 1);
        GpsMapCell gmc = Document.Instance.Map.GetCell(x, y);//获取对应格子

        if (gmc.Type == GpsMapCell.EType.EN_CROSS || gmc.Type == GpsMapCell.EType.EN_ROAD)
        {
            Vector3 targetPosition = Document.Instance.Map.GetCellPosition(gmc);//将格子转换为世界坐标


            if (item == "I01")//雷电
            {
                go1 = (GameObject)Instantiate(thuner);
                go1.transform.position = targetPosition;
            }
            else if (item == "I02")//冰冻
            {
                go1 = (GameObject)Instantiate(liquid);
                go1.transform.position = targetPosition;
            }
            else if (item == "B01")//肾宝
            {
                go1 = (GameObject)Instantiate(shenbao);
                go1.transform.position = targetPosition;
            }
            else if (item == "B03")//金克拉
            {
                go1 = (GameObject)Instantiate(jinkela);
                go1.transform.position = targetPosition;
            }
        }
    }
Exemple #12
0
        // 输出的顶点数和边数相同
        public bool FindCell2CrossPath(GpsMapCell from, GpsMapCell cross,
                                       out List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode, out List <MapPathGraph.Edge> listEdge)
        {
            listNavigateVertexNode = null;
            listEdge = null;

            from = FindNearestCellOf(from, GpsMapCell.EType.EN_ROAD);
            if (from == null)
            {
                XxdwDebugger.Log("Road nearby not found. Strange!");
                return(false);
            }

            int crossVertexIndex = this.pathGraph.FindVertex(cross.Index);

            if (crossVertexIndex < 0)
            {
                XxdwDebugger.Log("Target cross not found. Strange!");
                return(false);
            }
            MapPathGraph.VertexNode vnTo = this.pathGraph.VertexList[crossVertexIndex];

            MapPathGraph.VertexNode vn1, vn2;
            MapPathGraph.Edge       e;
            int spotIndex = FindEdgeOfRoadCell(from.Index, out vn1, out vn2, out e);

            if (spotIndex < 0)
            {
                XxdwDebugger.Log("Cross of road not found. Strange!");
                return(false);
            }
            float w1 = CalcDetailWeight(e.Spots, 0, spotIndex + 1);
            float w2 = CalcDetailWeight(e.Spots, spotIndex, e.Spots.Length);

            int[] spots1 = new int[spotIndex + 1];
            Array.Copy(e.Spots, 0, spots1, 0, spotIndex + 1);
            int[] spots2 = new int[e.Spots.Length - spotIndex];
            Array.Copy(e.Spots, spotIndex, spots2, 0, e.Spots.Length - spotIndex);

            MapPathGraph.Edge e1, e2;
            if (e.Spots[0] == vn1.Cell)
            {
                e1 = new MapPathGraph.Edge(vn1.Cell, e.Spots[spotIndex], w1, spots1, "");
                e1.ReverseSpots();
                e2 = new MapPathGraph.Edge(vn2.Cell, e.Spots[spotIndex], w2, spots2, "");
            }
            else
            {
                e1 = new MapPathGraph.Edge(vn1.Cell, e.Spots[spotIndex], w2, spots2, "");
                e2 = new MapPathGraph.Edge(vn2.Cell, e.Spots[spotIndex], w1, spots1, "");
                e2.ReverseSpots();
            }


            List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode1 = new List <MapPathGraph.NavigateVertexNode>();
            List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode2 = new List <MapPathGraph.NavigateVertexNode>();
            AStarHelper ash = new AStarHelper(this.CalcDistanceWeight);

            ash.Clear();
            float weight1 = this.pathGraph.FindShortestPaths(ash, vn1, vnTo, listNavigateVertexNode1);

            weight1 += weight1 >= 0 ? w1 : Parameters.MAX_EDGE_WEIGHT;
            ash.Clear();
            float weight2 = this.pathGraph.FindShortestPaths(ash, vn2, vnTo, listNavigateVertexNode2);

            weight2 += weight2 >= 0 ? w2 : Parameters.MAX_EDGE_WEIGHT;
            if (listNavigateVertexNode1.Count == 0 && listNavigateVertexNode2.Count == 0)
            {
                return(false);
            }

            listEdge = new List <MapPathGraph.Edge>();
            if (weight1 < weight2)
            {
                listNavigateVertexNode1[0].SelectedEdgeIndex = this.pathGraph.GetEdgeNumber(vn1, e);
                listNavigateVertexNode = listNavigateVertexNode1;
                this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);
                listEdge.Insert(0, e1);
            }
            else
            {
                listNavigateVertexNode2[0].SelectedEdgeIndex = this.pathGraph.GetEdgeNumber(vn2, e);
                listNavigateVertexNode = listNavigateVertexNode2;
                this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);
                listEdge.Insert(0, e2);
            }

            return(true);
        }
Exemple #13
0
        private GpsMapCell Neighbor(GpsMapCell gmc, Parameters.EDirection dir, int distance = 1)
        {
            int r = gmc.Row, c = gmc.Col;

            switch (dir)
            {
            case Parameters.EDirection.DIR_R:
                if (c < this.colNum - distance)
                {
                    c += distance;
                }
                break;

            case Parameters.EDirection.DIR_RD:
                if (r < this.rowNum - distance && c < this.colNum - distance)
                {
                    r += distance;
                    c += distance;
                }
                break;

            case Parameters.EDirection.DIR_D:
                if (r < this.rowNum - distance)
                {
                    r += distance;
                }
                break;

            case Parameters.EDirection.DIR_LD:
                if (r < this.rowNum - distance && c > distance - 1)
                {
                    r += distance;
                    c -= distance;
                }
                break;

            case Parameters.EDirection.DIR_L:
                if (c > distance - 1)
                {
                    c -= distance;
                }
                break;

            case Parameters.EDirection.DIR_LU:
                if (r > distance - 1 && c > distance - 1)
                {
                    r -= distance;
                    c -= distance;
                }
                break;

            case Parameters.EDirection.DIR_U:
                if (r > distance - 1)
                {
                    r -= distance;
                }
                break;

            case Parameters.EDirection.DIR_RU:
                if (r > distance - 1 && c < this.colNum - distance)
                {
                    r -= distance;
                    c += distance;
                }
                break;

            default:
                break;
            }

            if (r != gmc.Row || c != gmc.Col)
            {
                //return this.grid[r, c];
                return(this.GetCell(r, c));
            }

            return(null);
        }
Exemple #14
0
 public Vector3 GetCellPosition(GpsMapCell gmc)
 {
     return(GetCellPosition(gmc.Index));
 }
Exemple #15
0
    void Update()
    {
        actor = GameObject.Find("actor").transform;
        Vector3 point = new Vector3(actor.position.x + 1f, actor.position.y - 0.2f, actor.position.z);

        if (Input.GetKeyDown(KeyCode.Z))
        {
            temp_bullet = Instantiate(bullet, actor.position, actor.rotation) as Rigidbody2D;
            temp_bullet.GetComponent <bullet1>().leftorright = this.leftorright;
        }


        if (Input.GetKeyDown(KeyCode.C))
        {
            CoolEffect.CoolInstace.gameObject.SetActive(true);
            if (newTime >= coolTime)
            {
                Instantiate(Resources.Load("effects/wave billboard 12"), point, Quaternion.identity);
                newTime = 0.0f;
            }
        }
        newTime += Time.deltaTime;
        leftTime = coolTime - newTime;

        role.SetBool("walking", false);
        float h = Input.GetAxis("Horizontal");

        if (h > 0 && facingLeft)
        {
            Flip();
        }
        else if (h < 0 && !facingLeft)
        {
            Flip();
        }

        d = Document.Instance.Map.GetCell(temp_actor.Row, temp_actor.Col);
        t = Document.Instance.Map.GetCell(temp_actor.Row - 1, temp_actor.Col);
        b = Document.Instance.Map.GetCell(temp_actor.Row + 1, temp_actor.Col);
        l = Document.Instance.Map.GetCell(temp_actor.Row, temp_actor.Col - 1);
        r = Document.Instance.Map.GetCell(temp_actor.Row, temp_actor.Col + 1);

        if (t == null)
        {
            temp_actor.Row += 1;
        }
        if (b == null)
        {
            temp_actor.Row -= 1;
        }
        if (l == null)
        {
            temp_actor.Col -= 1;
        }
        if (r == null)
        {
            temp_actor.Col += 1;
        }

        if (this.jump)
        {
            if (!this.falling && t != null && t.Type != GpsMapCell.EType.EN_BUILDING)
            {
                temp_actor.Row--;
                MoveTo(temp_actor);
                StartCoroutine(DelayToInvokeDo(() =>
                {
                    this.falling = true;
                    role.SetBool("jumping", false);
                }, 0.5f));
            }
        }
        if (t != null && t.Type == GpsMapCell.EType.EN_BUILDING)
        {
            this.falling = true;
        }

        if (this.falling)
        {
            if (d != null && d.Type == GpsMapCell.EType.EN_SELECTION)
            {
                temp_actor.Row++;
                MoveTo(temp_actor);
            }
        }

        if (d != null && d.Type == GpsMapCell.EType.EN_DANGER)
        {
            Application.LoadLevel(2);
        }
    }
Exemple #16
0
    private void OnNotiKeyDown(Notification noti)
    {
        GameKey.EKey key      = (GameKey.EKey)noti.Data;
        GameKey.EKey modifier = (GameKey.EKey)noti.ExtraData;
        Cell         newCell  = new Cell(this.cell);
        int          multiple = GameKey.IsControlKey(modifier) ? 3 : 1;

        switch (key)
        {
        case GameKey.EKey.K_UpArrow:
            newCell.Row -= multiple;
            break;

        case GameKey.EKey.K_DownArrow:
            newCell.Row += multiple;
            break;

        case GameKey.EKey.K_LeftArrow:
        {
            leftorright = false;
            newCell.Col--;
        }
        break;

        case GameKey.EKey.K_RightArrow:
        {
            leftorright = true;
            newCell.Col++;
        }
        break;

        case GameKey.EKey.K_Space:
        {
            newCell.Row--;
        }
        break;

        default:
            return;
        }

        GpsMapCell gnc = Document.Instance.Map.GetCell(this.cell.Row, this.cell.Col);
        GpsMapCell gpc = Document.Instance.Map.GetCell(newCell.Row, newCell.Col);

        if (gpc != null)
        {
            if (gpc.Type == GpsMapCell.EType.EN_ROPE)
            {
                MoveTo(newCell);
            }

            if (key != GameKey.EKey.K_Space)
            {
                if (gpc.Type == GpsMapCell.EType.EN_ROAD || gpc.Type == GpsMapCell.EType.EN_CROSS)
                {
                    MoveTo(newCell);
                    //行走动画
                    role.SetBool("walking", true);

                    /*if (key == GameKey.EKey.K_UpArrow || key == GameKey.EKey.K_DownArrow)
                     * {
                     *  role.SetBool("walking", false);
                     *  role.SetBool("climbing", true);
                     * }*/
                }
                //攀爬
                if (gpc.Type == GpsMapCell.EType.EN_LADDER)
                {
                    MoveTo(newCell);
                    role.SetBool("climbing", true);

                    /*if(key == GameKey.EKey.K_Space && gpc.Type == GpsMapCell.EType.EN_SELECTION)
                     * {
                     *  MoveTo(newCell);
                     *  temp_actor.Row = newCell.Row;
                     *  temp_actor.Col = newCell.Col;
                     *  this.falling = true;
                     * }*/
                }

                if (gpc.Type == GpsMapCell.EType.EN_SELECTION && key != GameKey.EKey.K_UpArrow && key != GameKey.EKey.K_DownArrow)
                {
                    if (gnc.Type != GpsMapCell.EType.EN_ROPE && gnc.Type != GpsMapCell.EType.EN_LADDER)
                    {
                        MoveTo(newCell);
                        temp_actor.Row = newCell.Row;
                        temp_actor.Col = newCell.Col;
                        //  this.falling = true;
                    }
                }
            }
            // 处理跳跃

            if (gpc.Type == GpsMapCell.EType.EN_SELECTION)
            {
                if (gnc.Type == GpsMapCell.EType.EN_ROAD || gnc.Type == GpsMapCell.EType.EN_CROSS /*&& !this.falling*/)
                {
                    if (key == GameKey.EKey.K_Space) //|| key == GameKey.EKey.K_RightArrow || key == GameKey.EKey.K_LeftArrow)
                    {
                        MoveTo(newCell);
                        temp_actor.Row = newCell.Row;
                        temp_actor.Col = newCell.Col;
                        this.falling   = false;
                        this.jump      = true;
                        //跳跃动画判断
                        role.SetBool("jumping", true);
                    }
                }
            }
        }
    }