示例#1
0
        /// <summary>
        /// Creates a new world.
        /// </summary>
        /// <param name="seed">The world seed.</param>
        private World( int seed )
        {
            // setup the terrain
            //_terrain = Terrain.CreateInstance( (int)DateTime.Now.Ticks );
            _terrain = Terrain.CreateInstance( seed );

            // create the player
            Vector3 playerPosition = new Vector3( 0.0f, Terrain.MaximumHeight + 2.0f, 0.0f );
            _player = Player.CreateInstance( playerPosition );

            // create the world manager (it will begin running all by itself)
            _manager = new WorldManager( this, playerPosition );
        }
示例#2
0
        /// <summary>
        /// Gets the light value from the block at the local coordinates.
        /// </summary>
        /// <param name="terrain">The terrain to use.</param>
        /// <param name="x">The relative local X coordinate.</param>
        /// <param name="y">The relative local Y coordinate.</param>
        /// <param name="z">The relative local Z coordinate.</param>
        private float GetLightFromBlock( Terrain terrain, int x, int y, int z )
        {
            // if we're within actual bounds, then we can just return the already calculated light
            if ( x >= 0 && x < ChunkData.SizeXZ &&
                 z >= 0 && z < ChunkData.SizeXZ &&
                 y >= 0 && y < ChunkData.SizeY )
            {
                return _data[ x, y, z ].Lighting;
            }

            // TODO : We need to query the world later when the terrain is modifiable

            // if we're not within bounds, then we need to estimate the light level
            float lighting = Block.MaximumLighting;
            for ( int toCheckY = ChunkData.SizeY - 1; toCheckY > y; --toCheckY )
            {
                if ( terrain.Query( x, toCheckY, z ) != BlockType.Air )
                {
                    lighting = Block.MinimumLighting;
                    break;
                }
            }
            return lighting;
        }
示例#3
0
 /// <summary>
 /// Creates the terrain instance if it does not already exist.
 /// </summary>
 /// <param name="seed">The terrain seed.</param>
 /// <returns></returns>
 public static Terrain CreateInstance( int seed )
 {
     if ( _instance == null )
     {
         _instance = new Terrain( seed );
     }
     return _instance;
 }