Esempio n. 1
0
        protected override bool BindData(ref float[] vertices, ref int[] indices)
        {
            vertices = new float[0];
            indices  = new int[0];
            if (V9 == null || V8 == null)
            {
                return(false);
            }

            var stackedVertices = new List <float>();
            var stackedIndices  = new List <int>();

            var terrainVertices = new List <float>();
            var terrainIndices  = new List <int>();

            var xOffset = (X - 32) * GRID_SIZE;
            var yOffset = (Y - 32) * GRID_SIZE;

            for (var index = 0; index < V9_SIZE_SQ; ++index)
            {
                var x = (xOffset + (index % V9_SIZE) * GRID_PART_SIZE) * -1.0f;
                var y = (yOffset + (index / V9_SIZE) * GRID_PART_SIZE) * -1.0f;
                terrainVertices.AddRange(new[] { y, x, V9[index] });
            }

            for (var index = 0; index < V8_SIZE_SQ; ++index)
            {
                var x = (xOffset + (index % V8_SIZE) * GRID_PART_SIZE + GRID_PART_SIZE / 2.0f) * -1.0f;
                var y = (yOffset + (index / V8_SIZE) * GRID_PART_SIZE + GRID_PART_SIZE / 2.0f) * -1.0f;
                terrainVertices.AddRange(new[] { y, x, V8[index] });
            }

            for (var square = 0; square < V8_SIZE_SQ; ++square)
            {
                for (var corner = 1; corner <= 4; ++corner)
                {
                    GetHeightTriangle(square, corner, out int[] terrainIndice);
                    terrainIndices.AddRange(terrainIndice);
                }
            }

            if (terrainIndices.Count == 0)
            {
                return(false);
            }

            if (Holes.Length > 0 && Holes.Any(h => h != 0))
            {
                var terrainIndiceOffset = 0;

                ushort[] holetab_h = { 0x1111, 0x2222, 0x4444, 0x8888 };
                ushort[] holetab_v = { 0x000F, 0x00F0, 0x0F00, 0xF000 };

                for (int square = 0; square < V8_SIZE_SQ; ++square)
                {
                    for (int j = 0; j < 2; ++j)
                    {
                        var useTerrain = true /* stackedIndices.Count != 0 */;
                        if (useTerrain)
                        {
                            var row     = square / 128;
                            var col     = square % 128;
                            var cellRow = row / 8;     // 8 squares per cell
                            var cellCol = col / 8;
                            var holeRow = (row % 8) / 2;
                            var holeCol = (square - (row * 128 + cellCol * 8)) / 2;

                            var hole = Holes[cellRow * 16 + cellCol];

                            useTerrain = (hole & holetab_h[holeCol] & holetab_v[holeRow]) == 0;
                        }

                        if (useTerrain)
                        {
                            for (var k = 0; k < 3 * 4 / 2; ++k)
                            {
                                stackedIndices.Add(terrainIndices[k + terrainIndiceOffset]);
                            }
                        }

                        terrainIndiceOffset += 3 * 4 / 2;
                    }
                }
                stackedVertices.AddRange(terrainVertices);
            }
            else
            {
                stackedIndices.AddRange(terrainIndices);
                stackedVertices.AddRange(terrainVertices);
            }

            CleanVertices(stackedIndices, stackedVertices);

            for (var i = 0; i < stackedIndices.Count; i += 3)
            {
                var tmp = stackedIndices[i + 1];
                stackedIndices[i + 1] = stackedIndices[i + 2];
                stackedIndices[i + 2] = tmp;
            }

            vertices = stackedVertices.ToArray();
            indices  = stackedIndices.ToArray();

            return(true);
        }
Esempio n. 2
0
 //marble moved to another hole
 private bool FellInAnotherHole(Marble marble)
 {
     return(Holes.Any(h => !h.IsFilled && h.Number != marble.Number &&
                      h.Position.Row == marble.Position.Row && h.Position.Column == marble.Position.Column));
 }