当前位置: 首页>>代码示例>>C#>>正文


C# Square.getY方法代码示例

本文整理汇总了C#中Square.getY方法的典型用法代码示例。如果您正苦于以下问题:C# Square.getY方法的具体用法?C# Square.getY怎么用?C# Square.getY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Square的用法示例。


在下文中一共展示了Square.getY方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: enlargeMoveable

    static void enlargeMoveable(int moveRange)
    {
        int forceBreak=0;
        bool inMoveable=false;
        for (int c=0; c<moveable.Count; c++) {
            if (forceBreak >= 250){
                Debug.Log ("Force break at c. moveable.count:" + moveable.Count);
                break;
            }
            else {
                forceBreak++;
            }

            // Take current moveable cell and check around it
            current = moveable[c];
            int loopCount=0;

            //Debug.Log("Current is x:" + current.getX () + " y:" + current.getY() + ". G is " + current.getG());
            for (int i=0; i<3; i++) {
                for (int j=0; j<3; j++) {
                    loopCount += 1;
                    if (loopCount % 2 == 1)
                        continue; //skipping diagonal movement

                    if (walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)] == 0) // Check if cell is walkable
                        continue;

                    if ((current.getG () + (moveWeight * walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)])) > (moveRange*moveWeight+10)){ // Check if cell is way too far
                        doneCheck = true;
                        return;
                    }

                    //						if (moveRange*moveWeight+10 < current.getG () + moveWeight * walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)]) // Check if cell is reachable
                    //							continue;

                    //Debug.Log("G of x:" + (current.getX () - 1 + j) + ", y: " + (current.getY () - 1 + i) + "is " + (current.getG()+moveWeight));

                    inMoveable = false;
                    for (int k=0; k<moveable.Count; k++){ // Check if cell is already in list
                        if (moveable[k].getX () == (current.getX () - 1 + j) && moveable[k].getY() == (current.getY () - 1 + i)){
                            inMoveable = true;
                            break;
                        }
                    }

                    if (inMoveable)
                        continue;

                    // Add squares into moveable
                    moveable.Add (new Square (
                        (int)current.getX() - 1 + j,
                        (int)current.getY() - 1 + i,
                        (current.getG () + (moveWeight * walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)])),
                        0));
                }
            }
        }
    }
开发者ID:kaizeth,项目名称:2d_game_works,代码行数:58,代码来源:Pathfinder.cs

示例2: findPath

    public static void findPath(int[][] map, Vector3 start, Vector3 end)
    {
        //Step 0: Clear existing static lists
        openLists.Clear ();
        closedLists.Clear ();

        //Step 1: set start as current, prepare openLists and closedLists
        current = new Square ((int)start.x, (int)start.y);
        target = new Square ((int)end.x, (int)end.y);
        walkable = map;
        closedLists.Add (current); // Add current into closed list.
        int loopCount = 0;

        //Step 1.1: Loop around current, add into openLists.
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                loopCount += 1;
                if (loopCount % 2 == 1) /*Skip diagonal movement*/
                    continue;

                //Debug.Log ("Floor " + ((current.getX () - 1 + i) + "," + (current.getY () - 1 + j) + " is " + walkable [(current.getY () - 1 + j)] [(current.getX () - 1 + i)]));

                if (walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)] == 0) // Check if cell is walkable
                    continue;

                //Debug.Log ("G of " + (current.getX () - 1 + i) + "," + (current.getY () - 1 + j) + " is " + (current.getG () + moveWeight*walkable [(current.getY () - 1 + j)] [(current.getX () - 1 + i)]));

                //Step 1.2: Calculate heuristics before add into openLists
                int heuristics = 10 * (int)(Mathf.Abs (current.getX () - 1 + j - target.getX ()) + Mathf.Abs (current.getY () - 1 + i - target.getY ()));

                //Step 1.3: Add squares into openLists
                openLists.Add (new Square (
                    (int)start.x - 1 + j,
                    (int)start.y - 1 + i,
                    (current.getG () + (moveWeight * walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)])),
                    heuristics,
                    current));
            }
        }

        // Loop until end is reached.
        int counting = 0;
        while (current.getX () != target.getX () || current.getY ()!=target.getY ()) {
            if (counting == 250)
                break;
            // Step 2: Loop through open list to get next current
            //Debug.Log ("____________________               CalculateLists called!!!!!");
            calculateLists ();
            //Step 3: Using next current, add neighbours to open lists
            growOpenLists ();
            counting++;
        }
        Debug.Log ("openLists size is " + openLists.Count);
        return;
    }
开发者ID:kaizeth,项目名称:2d_game_works,代码行数:55,代码来源:Pathfinder.cs

示例3: highlightMoveable

    public static void highlightMoveable(int[][] map, Vector3 start, int moveRange)
    {
        //Step 0: Clear existing static lists
        moveable.Clear();

        //Step 1: set start as current, prepare some variables
        int loopCount=0;
        current = new Square ((int)start.x, (int)start.y);
        walkable = map;

        //Step 1.1: Loop around current, add into openLists.
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                loopCount += 1;
                if (loopCount % 2 == 1) /*Skip diagonal movement*/
                    continue;

                if (walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)] == 0) // Check if cell is walkable
                    continue;

                if (moveRange*moveWeight < (current.getG () + (moveWeight * walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)]))) // Check if cell is reachable
                    continue;

                //Step 1.3: Add squares into moveable
                moveable.Add (new Square (
                    (int)start.x - 1 + j,
                    (int)start.y - 1 + i,
                    (current.getG () + (moveWeight * walkable [(current.getY () - 1 + i)] [(current.getX () - 1 + j)])),
                    0));
            }
        }

        //Loop until all squares within move range is selected
        int counting = 0;
        doneCheck = false;
        while (doneCheck == false) {
            if (counting == 250)

            // Step 2: Loop through open list to get next current
            enlargeMoveable (moveRange);
            counting++;
        }
        colourMoveable(true, moveRange);
    }
开发者ID:kaizeth,项目名称:2d_game_works,代码行数:44,代码来源:Pathfinder.cs


注:本文中的Square.getY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。