Beispiel #1
0
        public static void UpdateVisibilityMap(GameMap map, VisibilityMap visibility, Vector2Int pos, int distance)
        {
            var p0 = new Vector2Int(pos.x - distance, pos.y - distance);
            var p1 = new Vector2Int(pos.x + distance, pos.y + distance);

            for (int x = p0.x; x <= p1.x; x++)
            {
                for (int y = p0.y; y <= p1.y; y++)
                {
                    //for every tile on the perimeter
                    if ((x == p0.x || x == p1.x) || (y == p0.y || y == p1.y))
                    {
                        Line(pos.x, pos.y, x, y, (pX, pY) =>
                        {
                            if (pX < 0 || pX >= map.Width || pY < 0 || pY > map.Height)
                            {
                                return(false);
                            }

                            visibility.Set(pX, pY, VisibilityMap.VisibilityState.Visible);

                            var tile = map.GetTile(pX, pY);
                            return(!tile.BlockSight);
                        });
                    }
                }
            }
        }
Beispiel #2
0
        public void CreateMap(GameMapData data)
        {
            size = new Vector2Int(data.Width, data.Height);

            tilemap.Resize(size.x, size.y);

            tiles         = new Tile[size.x, size.y];
            visibilityMap = new VisibilityMap(size.x, size.y);

            DestroyEntites();
            entityMap = new EntityMap(size.x, size.y);

            fovMaterial.SetVector("_FogSize", new Vector4(Width * TileSize, Height * TileSize, 0, 0));
            fovMaterial.SetTexture("_FogMapA", visibilityMap.texturePrev);
            fovMaterial.SetTexture("_FogMapB", visibilityMap.textureCur);

            //create tiles
            for (int x = 0; x < size.x; x++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    var brush = data.Get(x, y) == 0 ? floorBrush : wallBrush;

                    tilemap.SetTile(x, y, brush);
                }
            }

            for (int x = 0; x < size.x; x++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    tiles[x, y] = tilemap.GetTileInstance(x, y).GetComponent <Tile>();
                }
            }

            pathfindingNodes = new TileGridNodes(this);

            RecalulatePathfinding();
        }