Пример #1
0
        private bool HasEdge(int x, int y, Direction dir)
        {
            Room.Tile             tile    = room.GetTile(x, y);
            Room.Tile.TerrainType terrain = tile.Terrain;
            Room.SlopeDirection   slope   = (terrain == Room.Tile.TerrainType.Slope) ? room.IdentifySlope(x, y) : Room.SlopeDirection.Broken;

            if (terrain == Room.Tile.TerrainType.Solid)
            {
                return(true);
            }
            if (terrain == Room.Tile.TerrainType.Air ||
                terrain == Room.Tile.TerrainType.ShortcutEntrance ||
                terrain == Room.Tile.TerrainType.Floor)
            {
                return(false);
            }
            switch (dir)
            {
            case Direction.Up:
                return(slope == Room.SlopeDirection.DownRight || slope == Room.SlopeDirection.DownLeft);

            case Direction.Right:
                return(slope == Room.SlopeDirection.UpLeft || slope == Room.SlopeDirection.DownLeft);

            case Direction.Down:
                return(slope == Room.SlopeDirection.UpRight || slope == Room.SlopeDirection.UpLeft);

            case Direction.Left:
                return(slope == Room.SlopeDirection.DownRight || slope == Room.SlopeDirection.UpRight);
            }
            return(false);
        }
Пример #2
0
        public void UpdateMapper(int iterations)
        {
            Room.Tile[,] tiles = _tiles;
            for (int i = 0; i < iterations; i++)
            {
                switch (state)
                {
                case MappingState.FindingEdges:
                {
                    Room.Tile             tile    = tiles[_x, _y];
                    Room.Tile.TerrainType terrain = tile.Terrain;
                    Room.SlopeDirection   slope   = (terrain == Room.Tile.TerrainType.Slope) ? room.IdentifySlope(_x, _y) : Room.SlopeDirection.Broken;

                    if (HasEdge(_x, _y, Direction.Left) && !HasEdge(_x - 1, _y, Direction.Right))
                    {
                        AddEdge(_x, _y, Direction.Left);
                    }
                    if (HasEdge(_x, _y, Direction.Down) && !HasEdge(_x, _y - 1, Direction.Up))
                    {
                        AddEdge(_x, _y, Direction.Down);
                    }
                    if (HasEdge(_x, _y, Direction.Right) && !HasEdge(_x + 1, _y, Direction.Left))
                    {
                        AddEdge(_x, _y, Direction.Right);
                    }
                    if (HasEdge(_x, _y, Direction.Up) && !HasEdge(_x, _y + 1, Direction.Down))
                    {
                        AddEdge(_x, _y, Direction.Up);
                    }

                    if (slope != Room.SlopeDirection.Broken)
                    {
                        AddSlopeEdge(_x, _y, slope);
                    }

                    _x++;
                    if (_x >= room.TileWidth)
                    {
                        _x = 0;
                        _y++;
                        if (_y >= room.TileHeight)
                        {
                            _y    = corners.Count;
                            state = MappingState.DuplicatingPoints;
                        }
                    }
                }
                break;

                case MappingState.DuplicatingPoints:
                {
                    corners.Add(corners[_x]);
                    _x++;
                    if (_x >= _y)
                    {
                        state = MappingState.Done;
                        _x    = 0;
                        _y    = 0;
                    }
                }
                break;

                case MappingState.Done:
                    return;
                }
            }
        }