Ejemplo n.º 1
0
 public void reset()
 {
     routeFound  = false;
     currentNode = start;
     route       = new Queue <navNode>();
     candy       = 0;
 }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     actions      = GetComponent <basicActions>();
     routeFound   = false;
     currentNode  = start;
     route        = new Queue <navNode>();
     candy        = 0;
     goingToScore = false;
 }
Ejemplo n.º 3
0
    private void moveToNode(navNode node, navNode previous)
    {
        string action = "";

        if (previous.next == node)
        {
            action = previous.transitionToNext;
        }
        else if (previous.previous == node)
        {
            action = previous.transitionPrevious;
        }

        //print(node.name + previous.name + action);

        if (action == "jump")
        {
            takeJumps = true;
        }
        else if (action == "run")
        {
            takeJumps = false;
        }

        if (node.transform.position.x - 1 < myPos.x && myPos.x < node.transform.position.x + 1 && node.transform.position.y - 1 < myPos.y && myPos.y < node.transform.position.y + 1)
        {
            print("bop");
            actions.move = 0;
            currentNode  = route.Dequeue();
        }
        else if (myPos.x < node.transform.position.x)
        {
            actions.move = 1;
        }
        else if (myPos.x > node.transform.position.x)
        {
            actions.move = -1;
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Decision making

        playerpos = player.transform.position;
        myPos     = transform.position;
        candy     = GetComponent <candyCollection>().candy;

        if (actions.gameMode == 0)
        {
            if (Mathf.Abs(playerpos.x - transform.position.x) < 2 && Mathf.Abs(playerpos.y - transform.position.y) < 0.5)
            {
                print("Raaaa!");
                //ATTACK
                if (actions.curRot == player.GetComponent <basicActions>().curRot)
                {
                    if (actions.facingRight)
                    {
                        actions.facingRight = false;
                    }
                    else
                    {
                        actions.facingRight = true;
                    }
                }
                actions.HAttack = true;
                actions.jump    = false;
                actions.move    = 0;
            }
            //Not enough candy, look for ccp
            else if (candy < CDP.GetComponent <cdpScript>().acceptedAmount)
            {
                if (goingToScore)
                {
                    reset();
                    goingToScore = false;
                    currentNode  = GameObject.FindGameObjectWithTag("node").GetComponent <navNode>();
                }
                actions.HAttack = false;
                if (currentNode.tag == "ccpNode")
                {
                    if (currentNode.transform.position.x - 1 < myPos.x && myPos.x < currentNode.transform.position.x + 1)
                    {
                        actions.isCollecting = true;
                        actions.move         = 0;
                    }
                    else if (myPos.x < currentNode.transform.position.x)
                    {
                        actions.move = 1;
                    }
                    else if (myPos.x > currentNode.transform.position.x)
                    {
                        actions.move = -1;
                    }
                    routeFound = false;
                }
                else
                {
                    temp = currentNode;
                    while (!routeFound)
                    {
                        if (temp.next.gameObject.tag == "ccpNode")
                        {
                            routeFound = true;
                            route.Enqueue(temp.next);
                        }
                        else if (temp.previous.gameObject.tag == "ccpNode")
                        {
                            routeFound = true;
                            route.Enqueue(temp.previous);
                        }
                        else
                        {
                            route.Enqueue(temp);
                            temp = temp.next;
                        }
                    }
                }
            }
            //Have enough candy to score
            else
            {
                goingToScore         = true;
                actions.HAttack      = false;
                temp                 = currentNode;
                actions.isCollecting = false;
                if (!routeFound)
                {
                    while (!routeFound)
                    {
                        if (temp.next.gameObject.tag == "cdpNode")
                        {
                            routeFound = true;
                            route.Enqueue(temp.next);
                        }
                        else if (temp.previous.gameObject.tag == "cdpNode")
                        {
                            routeFound = true;
                            route.Enqueue(temp.previous);
                        }
                        else
                        {
                            route.Enqueue(temp.next);
                            temp = temp.next;
                        }
                    }
                }
            }
        }

        //Execute route
        if (route.Count != 0)
        {
            moveToNode(route.Peek(), currentNode);
        }


        /*
         * if (Mathf.Abs(playerpos.x - transform.position.x) < 2 && Mathf.Abs(playerpos.y - transform.position.y) < 0.5)
         * {
         *  //ATTACK
         *  if (curRot == player.GetComponent<basicActions>().curRot)
         *  {
         *      if (facingRight)
         *          facingRight = false;
         *      else
         *          facingRight = true;
         *  }
         *  attack = true;
         *  jump = false;
         *  moveLeft = false;
         *  moveRight = false;
         *
         * }
         *
         *
         * //Doesnt have enough candy to score
         * if (GetComponent<candyCollection>().candy < CDP.GetComponent<cdpScript>().acceptedAmount)
         * {
         *  attack = false;
         *
         *  if (Mathf.Abs(CCPpos.x - transform.position.x) > 0.1 && Mathf.Abs(CCPpos.y - transform.position.y) > 0.5)
         *  {
         *      jump = false;
         *      isCollecting = false;
         *      if (CCPpos.x > transform.position.x)
         *      {
         *          moveRight = true;
         *          moveLeft = false;
         *      }
         *      else
         *      {
         *          moveRight = false;
         *          moveLeft = true;
         *      }
         *  }
         *  else
         *  {
         *      moveRight = false;
         *      moveLeft = false;
         *      isCollecting = true;
         *  }
         * }
         * //Has enough
         * else
         * {
         *  attack = false;
         *  if (Mathf.Abs(CDPpos.y - transform.position.y) > 2)
         *  {
         *      moveRight = true;
         *      moveLeft = false;
         *      jump = true;
         *  }
         *  else if (Mathf.Abs(CDPpos.x - transform.position.x) > 0.2 && Mathf.Abs(CDPpos.y - transform.position.y) > 0.5)
         *  {
         *      isCollecting = false;
         *      if (CCPpos.x > transform.position.x)
         *      {
         *          moveRight = true;
         *          moveLeft = false;
         *      }
         *      else
         *      {
         *          moveRight = false;
         *          moveLeft = true;
         *      }
         *
         *  }
         * }
         */
    }
Ejemplo n.º 5
0
        public static navMeshInfo LoadMeshInfoFromFiles(string bytesFileName)
        {
            navMeshInfo    info    = new navMeshInfo();
            List <Point3D> listVec = new List <Point3D>();

            string s1, s2;
            var    lines = System.IO.File.ReadAllLines(bytesFileName, Encoding.UTF8).Where(a => !string.IsNullOrWhiteSpace(a) && !a.StartsWith("--")).ToArray();

            s1 = lines[0];
            s2 = lines[1];

            string[] arr1 = s1.Split(new char[] { ',', ';' });
            string[] arr2 = s2.Split(new char[] { ',', ';' });

            string[] arrvertices;
            string[] arrindices;
            int      ttttttt;

            if (arr1.All(a => int.TryParse(a, out ttttttt)))
            {
                //如果全都是整数,说明是索引
                arrvertices = arr2;
                arrindices  = arr1;
            }
            else
            {
                arrvertices = arr1;
                arrindices  = arr2;
            }

            //张建是用逗号分开的
            var svecs  = arrvertices.Select(a => double.Parse(a)).ToArray();
            var snodes = arrindices.Select(a => int.Parse(a)).ToArray();

            for (int i = 0; i < svecs.Length; i += 3)
            {
                Point3D v3 = new Point3D();
                v3.X = svecs[i];
                v3.Y = svecs[i + 1];
                v3.Z = svecs[i + 2];
                listVec.Add(v3);
            }
            info.vecs = listVec.ToArray();

            List <navNode> polys = new List <navNode>();
            int            index = 0;

            //因为一定是三角形
            for (int i = 0; i < snodes.Length; i += 3)
            {
                int        k      = 0;
                navNode    node   = new navNode();
                List <int> points = new List <int>();
                points.Add(snodes[i]);
                points.Add(snodes[i + 1]);
                points.Add(snodes[i + 2]);
                node.nodeID = index;
                index++;
                List <int> poly = new List <int>();
                poly.Add(points[0]);
                poly.Add(points[1]);
                poly.Add(points[2]);

                node.poly = poly.ToArray();
                //node.genBorder();//这里生成的border 是顶点border
                //node.genCenter(info);
                polys.Add(node);
            }
            info.nodes = polys.ToArray();
            //info.calcBound();
            //info.genBorder();
            System.Diagnostics.Debug.WriteLine("顶点数" + info.vecs.Length + "\t多边形数:" + info.nodes.Length);
            return(info);
        }