Esempio n. 1
0
    public Chain(World world,int linkCount, Beast beastA, Beast beastB)
    {
        this.world = world;
        this.linkCount = linkCount;

        this.beastA = beastA;
        this.beastB = beastB;

        Vector2 startPos = beastA.GetPos();
        Vector2 endPos = beastB.GetPos();

        //Vector2 delta = (endPos - startPos) / (float)LINK_COUNT;

        ChainLink previousLink = null;

        for (int c = 0; c<linkCount; c++)
        {
            ChainLink link;

            bool isLastLink = (c == linkCount-1);

            if(isLastLink)
            {
                link = ChainLink.Create(world, beastB);
            }
            else
            {
                link = ChainLink.Create(world, null);
            }

            Vector2 linkPos = new Vector2(startPos.x + ChainLink.LENGTH * (c), startPos.y);

            link.Init(this, previousLink, linkPos, isLastLink);
            links.Add(link);
            previousLink = link;
        }

        beastA.transform.position = new Vector3(startPos.x * FPhysics.POINTS_TO_METERS, startPos.y * FPhysics.POINTS_TO_METERS);
        beastB.transform.position = new Vector3(endPos.x * FPhysics.POINTS_TO_METERS, endPos.y * FPhysics.POINTS_TO_METERS);
    }