Ejemplo n.º 1
0
 public ContactPoint(int x, int y)
 {
     Position  = new Vector2(x, y);
     Triangles = new TriangleData[8];
     for (int i = 0; i < 8; i++)
     {
         Triangles[i] = new TriangleData(this, new Vector2[] { Position, Position + clockwisePoints[i], Position + clockwisePoints[(i + 1) % 8] });
     }
 }
 public void AddTriangle(TriangleData triangleData)
 {
     triangleData.Owner = this;
     TriangleDatas.Add(triangleData);
     if (!ContactPoints.Contains(triangleData.ContactPoint))
     {
         ContactPoints.Add(triangleData.ContactPoint);
     }
     CalculateCenter();
 }
Ejemplo n.º 3
0
        public TriangleData GetRandomAvailableNeighbour()
        {
            TriangleData randomNeighbour     = null;
            var          availableNeighbours = GetAvailableNeighbours();

            if (availableNeighbours.Count > 0)
            {
                randomNeighbour = availableNeighbours[Random.Range(0, availableNeighbours.Count)];
            }
            return(randomNeighbour);
        }
        GameObject CreateTriangle(TriangleData triangleData, Material material)
        {
            var triangle = new GameObject("puzzlePieceTriangle");
            var renderer = triangle.AddComponent <LineRenderer>();

            renderer.useWorldSpace = false;
            renderer.material      = material;
            renderer.startWidth    = .1f;
            renderer.endWidth      = .1f;
            renderer.positionCount = 4;
            for (int i = 0; i < 4; i++)
            {
                renderer.SetPosition(i, triangleData.Points[i % 3]);
            }
            return(triangle);
        }
Ejemplo n.º 5
0
        bool IsMyNeighbour(TriangleData neighbourCandidate)
        {
            int commonPointCount = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (Points[i] == neighbourCandidate.Points[j])
                    {
                        commonPointCount++;
                        break;
                    }
                }
            }
            return(commonPointCount == 2);
        }
 void AddTriangleToPuzzlePiece(TriangleData triangleData, PuzzlePiece puzzlePiece)
 {
     puzzlePiece.AddTriangle(triangleData);
     availableTriangles.Remove(triangleData);
 }