Example #1
0
        public void GenerateMapVoxels()
        {
            if (parts != null)
            {
                parts.Dispose();
            }

            List <MapPosition> data = new List <MapPosition>();

            for (int z = 0; z < Length; z++)
            {
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        MapPart part = map[x, y, z];

                        if (!part.IsEmpty)
                        {
                            data.Add(new MapPosition(new Vector3(part.X * 2, part.Y * 2, part.Z * 2)));
                        }
                    }
                }
            }

            partCount = data.Count;
            parts     = new DynamicVertexBuffer(GraphicsDevice, typeof(MapPosition), Width * Height * Length, BufferUsage.WriteOnly);
            parts.SetData(data.ToArray());
        }
Example #2
0
        public Map(int width, int height, int length)
            : base(Game3DPlatformer.Instance)
        {
            this.Width  = width;
            this.Height = height;
            this.Length = length;
            this.map    = new MapPart[width, height, length];

            test = new Texture2D(GraphicsDevice, 12, 2);
            test.SetData <Color>(new Color[] { Color.Red, Color.Red, Color.Blue, Color.Blue, Color.Cyan, Color.Cyan, Color.Green, Color.Green, Color.Yellow, Color.Yellow, Color.Magenta, Color.Magenta,
                                               Color.Red, Color.Red, Color.Blue, Color.Blue, Color.Cyan, Color.Cyan, Color.Green, Color.Green, Color.Yellow, Color.Yellow, Color.Magenta, Color.Magenta });

            for (int z = 0; z < Length; z++)
            {
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        if (y > 1 && y <= 2 && r.Next(0, 20) == 0)
                        {
                            map[x, y, z] = new MapPart(this)
                            {
                                X           = x - Width / 2,
                                Y           = y - Height / 2,
                                Z           = z - Length / 2,
                                BoundingBox = new BoundingBox(new Vector3(x - Width / 2 - 0.5f, y - Height / 2 - 0.5f, z - Length / 2 - 0.5f),
                                                              new Vector3(x - Width / 2 + 0.5f, y - Height / 2 + 0.6f, z - Length / 2 + 0.5f)),
                                IsEmpty = y > 2
                            };
                        }
                        else
                        {
                            map[x, y, z] = new MapPart(this)
                            {
                                X           = x - Width / 2,
                                Y           = y - Height / 2,
                                Z           = z - Length / 2,
                                BoundingBox = new BoundingBox(new Vector3(x - Width / 2 - 0.5f, y - Height / 2 - 0.5f, z - Length / 2 - 0.5f),
                                                              new Vector3(x - Width / 2 + 0.5f, y - Height / 2 + 0.6f, z - Length / 2 + 0.5f)),
                                IsEmpty = y > 1
                            };
                        }
                    }
                }
            }

            GenerateMapVoxels();

            bindings    = new VertexBufferBinding[2];
            bindings[0] = new VertexBufferBinding(Game.BaseCube.Meshes[0].MeshParts[0].VertexBuffer);
            bindings[1] = new VertexBufferBinding(parts, 0, 1);
        }