Coder Social home page Coder Social logo

cavegeneration's People

Contributors

zerochili avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cavegeneration's Issues

您好

能留个qq或者微信吗,我有些unity学习方面的问题想请教一下

Assets/Scripts/Room.cs 中 UpdateEdgeTiles 函数可能会放入重复的边界点

Assets/Scripts/Room.cs 中 UpdateEdgeTiles 函数可能会放入重复的边界点

    // 更新房间边缘瓦片集
    public void UpdateEdgeTiles(TileType[,] map)
    {
        edgeTiles.Clear();

        // 遍历上下左右四格,判断是否有墙
        foreach (Coord tile in tiles)
            for (int i = 0; i < 4; i++)
            {
                int x = tile.tileX + upDownLeftRight[i, 0];
                int y = tile.tileY + upDownLeftRight[i, 1];
                if (map[x, y] == TileType.Wall)
                {
                    edgeTiles.Add(tile);
                    continue;
                }
            }
    }

测试函数

    // 更新房间边缘瓦片集
    public void UpdateEdgeTiles(TileType[,] map)
    {
        edgeTiles.Clear();

        // 遍历上下左右四格,判断是否有墙
        foreach (Coord tile in tiles)
            for (int i = 0; i < 4; i++)
            {
                int x = tile.tileX + upDownLeftRight[i, 0];
                int y = tile.tileY + upDownLeftRight[i, 1];
                if (map[x, y] == TileType.Wall)
                {
                    foreach (var edgeTile in edgeTiles)
                    {
                        if (edgeTile.tileX == tile.tileX && edgeTile.tileY == tile.tileY)
                        {
                            Debug.Log("重复放入边界点");
                            break;
                        }
                    }
                    edgeTiles.Add(tile);
                    continue;
                }
            }
    }

测试结果

image

可以考虑将 Coord 结构体改成 Vector2Int 然后使用 Contain 判断是否已经放过

    // 更新房间边缘瓦片集
    public void UpdateEdgeTiles(TileType[,] map)
    {
        edgeTiles.Clear();
        
        // 遍历上下左右四格,判断是否有墙
        foreach (Vector2Int tile in tiles)
            for (int i = 0; i < 4; i++)
            {
                int x = tile.x + upDownLeftRight[i, 0];
                int y = tile.y + upDownLeftRight[i, 1];
                if (map[x, y] == TileType.Wall && !edgeTiles.Contains(tile))
                {
                    edgeTiles.Add(tile);
                }
            }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.