예제 #1
0
 public void Walk()
 {
     if (Children == null)
     {
         Children = new List<Viswalker>();
         List<int> nonBlocked = Directions.FindAll(x => true);
         foreach (int _direction in Directions)
         {
             if (!Tile.Walkable(_direction))
                 nonBlocked.Remove(_direction);
         }
         foreach (int _direction in nonBlocked)
         {
             Viswalker _child = new Viswalker(nonBlocked);
             _child.Tile = Tile[_direction];
             foreach (int _d in _child.Directions.FindAll(x => true))
             {
                 if (!Utility.KeypadNeighbour(
                     _d, _direction)
                     && _d != _direction)
                     _child.Directions.Remove(_d);
             }
             Children.Add(_child);
         }
     }
     foreach (Viswalker _c in Children)
     {
         _c.Walk();
     }
 }
예제 #2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            //test fov stuff

            bool[,] _vismap =
                new bool[GameVars.ScreenWidth, GameVars.ScreenHeight];

            //Viswalker _vw = new Viswalker(new List<int>() { 7, 8, 9 } );
            Viswalker _vw = new Viswalker(Player.Facing);
            _vw.Tile = Player.Tile;
            _vw.Walk();
            var a = _vw.Visible();

            spriteBatch.Begin();
            for (int _x = 0; _x < World.Width; _x++)
            {
                for (int _y = 0; _y < World.Height; _y++)
                {
                    spriteBatch.Draw(
                        Res.Textures[World[_x, _y].Texture ?? "blank"],
                        new Rectangle(
                            _x * GameVars.TileSize,
                            _y * GameVars.TileSize,
                            GameVars.TileSize,
                            GameVars.TileSize
                        ),
                        a.Contains(World[_x, _y]) ? Color.White : Color.Blue
                    );

                    #region walls
                    bool _w = World[_x, _y].West;
                    bool _n = World[_x, _y].North;

                    Vector2 _wallSource = new Vector2(
                        _n ? GameVars.TileSize : (_w ? 1 : 0),
                        _w ? GameVars.TileSize : (_n ? 1 : 0)
                    );

                    //looks hackish, but is to avoid the missing pixel
                    //on the 8w/4n corner if x,y does not have walls
                    if (!(_w || _n) && _x > 0 && _y > 0)
                    {
                        if (World[_x, _y][8].West &&
                            World[_x, _y][4].North)
                        {
                            _wallSource.X = 1;
                            _wallSource.Y = 1;
                        }
                    }

                    spriteBatch.Draw(
                        Res.Textures["grid"],
                        new Rectangle(
                            _x * GameVars.TileSize,
                            _y * GameVars.TileSize,
                            //_n ? GameVars.TileSize : (_w ? 1 : 0),
                            //_w ? GameVars.TileSize : (_n ? 1 : 0)
                            (int)_wallSource.X,
                            (int)_wallSource.Y
                        ),
                        new Rectangle(
                            0,
                            0,
                            //_n ? GameVars.TileSize : (_w ? 1 : 0),
                            //_w ? GameVars.TileSize : (_n ? 1 : 0)
                            (int)_wallSource.X,
                            (int)_wallSource.Y
                        ),
                        Color.Black
                    );
                    #endregion

                    if (World[_x, _y].Creature != null)
                    {
                        spriteBatch.Draw(
                            Res.Textures[World[_x, _y].Creature.Texture],
                            new Rectangle(
                                _x * GameVars.TileSize,
                                _y * GameVars.TileSize,
                                GameVars.TileSize,
                                GameVars.TileSize
                            ),
                            Color.White
                        );
                    }
                }
            }

            spriteBatch.End();
        }