Exemplo n.º 1
0
        private void GenerateWalls()
        {
            _walls = new Grid<bool>( _gridSize );
              var building = new Rectangle( new Size( 5, 6 ) );

              var wallPoints = new List<IPoint>();
              foreach( var line in building.Lines ) {
            wallPoints.AddRange( line.Bresenham() );
              }

              foreach( var line in building.Lines.Translate( new Point( 10, 7 ) ) ) {
            wallPoints.AddRange( line.Bresenham() );
              }

              var rotated1 = new Point( 50, 7 );
              foreach( var line in building.Lines.Translate( rotated1 ).Rotate( 45, rotated1 ) ) {
            wallPoints.AddRange( line.Bresenham() );
              }

              var rotated3 = new Point( 35, 7 );
              foreach( var line in building.Lines.Translate( rotated3 ).Rotate( 90, rotated3 ) ) {
            wallPoints.AddRange( line.Bresenham() );
              }

              foreach( var point in wallPoints ) {
            _walls[ point ] = true;
              }
        }
Exemplo n.º 2
0
        private void GeneratePaths()
        {
            GenerateSilentPaths();
              //var line1 = new Line( new Point( 1, 1 ), new Point( _map.Size.Width - 1, _map.Size.Height - 1 ) );
              //var line2 = new Line( new Point( 1, _map.Size.Height - 1 ), new Point( _map.Size.Width - 1, 1 ) );
              var line3 = new Line( new Point( 1, 1 ), _map.PlayerLocation );

              //var lines = new[] { line1, line2, line3 };
              var lines = new[] { line3 };
              var bounds = new Rectangle( 1, _map.Size.Width - 2, _map.Size.Height - 2, 1 );
              var points = lines.SelectMany( line => line.DrunkenWalk( 0.75, bounds ) ).Distinct();

              foreach( var point in points ) {
            _map.Paths[ point ] = true;
              }
        }
Exemplo n.º 3
0
        public List<object> Tick( string command )
        {
            var oldLocation = new Point(_location.X, _location.Y);
              var direction = ExecuteAction( command );
              if (!_noise.Bounds.InBounds(PlayerLocation) || _blocks[PlayerLocation])
              {
            _location = new Point( oldLocation.X, oldLocation.Y );
            direction = Direction.None;
              }
              _fov = _blocks.Fov(10, PlayerLocation);

              _seen.SetEach( (seen, point ) =>
            seen || _fov[ point ]
              );

              var source = new Rectangle( _viewportSize );
              var target = new Point( 0, 0 );
              var oldCenter = new Point( Center.X, Center.Y );
              if( UseBuffer ) {
            switch( direction ) {
              case Direction.Left:
            source.Right--;
            target.X++;
            oldCenter.X++;
            break;
              case Direction.Right:
            source.Left++;
            oldCenter.X--;
            break;
              case Direction.Up:
            source.Bottom--;
            target.Y++;
            oldCenter.Y++;
            break;
              case Direction.Down:
            source.Top++;
            oldCenter.Y--;
            break;
            }
              }

              Console.SetCursorPosition( 0, 0 );

              var viewportGrid = _noise.Copy( Viewport );

              var tiles = new List<ConsoleCell>();

              viewportGrid.ForEach( p => {
            var point = new Point( p.X + _location.X, p.Y + _location.Y );

            var draw =
              !UseBuffer
              || direction == Direction.None
              || p.Equals( Center )
              || p.Equals( oldCenter )
              || ( direction == Direction.Left && p.X == 0 )
              || ( direction == Direction.Right && p.X == viewportGrid.Width - 1 )
              || ( direction == Direction.Up && p.Y == 0 )
              || ( direction == Direction.Down && p.Y == viewportGrid.Height - 1 );

            tiles.Add(
              draw? new ConsoleCell {
            ForegroundColor = GetForegroundColor( p, point ),
            BackgroundColor = GetBackgroundColor( point ),
            Char = p.Equals( Center ) ? '@' : GetTile( point )
              }
              : default( ConsoleCell )
            );
              } );

              if( UseBuffer ) Console.MoveBufferArea( source.Left, source.Top, source.Width, source.Height, target.X, target.Y );
              Console.Blit( tiles );

              return Console.Flush();
        }