Esempio n. 1
0
        public Array3D <byte> Generate()
        {
            var result = new Array3D <byte>(width, depth, Math.Max(height, 2));

            var random = new Random();

            for (var i = 0; i < iteratirons; i++)
            {
                if (i == 0)
                {
                    for (var c1 = 0; c1 < width; c1++)
                    {
                        for (var c2 = 0; c2 < depth; c2++)
                        {
                            result[c1, c2, 0] = (byte)BlockType.Dirt;
                        }
                    }
                }
                else
                {
                    var hillParams = new IntPoint3D(random.Next(width), random.Next(depth), random.Next(height));

                    CreateHill(result, hillParams);
                }
            }

            return(result);
        }
Esempio n. 2
0
        private void CreateHill(Array3D <byte> data, IntPoint3D hillParams)
        {
            var c1Min = hillParams.X - hillParams.Z < 0 ? 0 : hillParams.X - hillParams.Z;
            var c1Max = Math.Min(hillParams.X + hillParams.Z, width - 1);

            var c2Min = hillParams.Y - hillParams.Z < 0 ? 0 : hillParams.Y - hillParams.Z;
            var c2Max = Math.Min(hillParams.Y + hillParams.Y, depth - 1);

            for (var c1 = c1Min; c1 <= c1Max; c1++)
            {
                for (var c2 = c2Min; c2 <= c2Max; c2++)
                {
                    var c3Max = (int)Math.Sqrt(hillParams.Z * hillParams.Z - (c1 - hillParams.X) * (c1 - hillParams.X) - (c2 - hillParams.Y) * (c2 - hillParams.Y));

                    if (c3Max <= 0)
                    {
                        continue;
                    }

                    for (var i = 0; i < c3Max; i++)
                    {
                        data[c1, c2, i] = (byte)BlockType.Dirt;
                    }
                }
            }
        }
Esempio n. 3
0
        public Block(GraphicsDevice graphicsDevice, IntPoint3D position)
        {
            this.graphicsDevice = graphicsDevice;

            Position = position.ToVector() * BlockSize;

            vertices = CubeFactory.GetCube(BlockSize, IntPoint3D.GetNeighbourPositions());

            effect = new BasicEffect(graphicsDevice);
        }
        public void Convert(float x, float y, float z, IntPoint3D expected)
        {
            const int blockSize = 1;

            var result = WorldToLogicalSpaceConverter.Convert(x, y, z, blockSize);

            result.X.ShouldBe(expected.X);
            result.Y.ShouldBe(expected.Y);
            result.Z.ShouldBe(expected.Z);
        }
Esempio n. 5
0
        private static IEnumerable <VertexPositionColor> GetFaceVertices(IntPoint3D faceVector, int scale)
        {
            var halfScale = scale / 2f;

            foreach (var vector in Faces[faceVector])
            {
                var result = new VertexPositionColor
                {
                    Position = vector * halfScale,
                    Color    = Colors[faceVector]/*.Values.ToArray()[new Random().Next(6)]*/
                };

                yield return(result);
            }
        }
Esempio n. 6
0
 public void AddBlockAt(IntPoint3D location, GraphicsDevice graphicsDevice)
 {
     items[location.X, location.Y, location.Z] = new Block(graphicsDevice, location.X * BlockSize * 2,
                                                           location.Y * BlockSize * 2,
                                                           location.Z * BlockSize * 2);
 }
 protected static IntPoint3D Add(IntPoint3D a, IntPoint3D b)
 {
     return(new IntPoint3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z));
 }
Esempio n. 8
0
 public LogicalBlock(IntPoint3D location, short type, bool isUserPlaced)
 {
     Location     = location;
     Type         = type;
     IsUserPlaced = isUserPlaced;
 }
Esempio n. 9
0
 public void AddBlockAt(IntPoint3D location, BlockType type)
 {
     terrainData[location] = (byte)type;
 }
Esempio n. 10
0
 public static VertexPositionColor[] GetCubeWithDefaultFaces(int size)
 {
     return(GetCube(size, IntPoint3D.GetNeighbourPositions()));
 }