Esempio n. 1
0
        private void updateForce(GameTime gameTime)
        {
            RopeSegment current = ropeStart;

            while (current != null)
            {
                current.updateForce(gameTime);
                current = current.getNext();
            }
        }
Esempio n. 2
0
        public void Draw(SpriteBatch batch)
        {
            RopeSegment current = ropeStart;

            while (current.getNext() != null)
            {
                drawBetweenSegments(current, current.getNext(), batch);
                current = current.getNext();
            }
        }
Esempio n. 3
0
        private Vector2 getForceTo(RopeSegment seg)
        {
            Vector2 force = Vector2.Zero;

            if (seg != null)
            {
                Vector2 dist       = seg.getPos() - getPos();
                float   len        = dist.Length();
                float   overlength = len - targetLength;
                dist.Normalize();
                force = dist * overlength * strength;
            }

            return(force);
        }
Esempio n. 4
0
        private void drawBetweenSegments(RopeSegment one, RopeSegment two, SpriteBatch batch)
        {
            Vector2 dist     = two.getPos() - one.getPos();
            float   rotation = (float)Math.Atan2(dist.Y, dist.X);
            Vector2 scale    = new Vector2(dist.Length() / BASE_LENGTH, 1);
            float   sc       = (one.targetLength / dist.Length());

            if (sc < 0)
            {
                sc = 0;
            }
            Color color = new Color(1 - sc, sc, 0);

            batch.Draw(baseTexture, position: one.getPos(), scale: scale, rotation: rotation, color: color, origin: new Vector2(0, 2.5f));
            //batch.Draw(baseTexture, position: one.getPos(), scale: new Vector2(5/100f, 1));
        }
Esempio n. 5
0
        private void createSegments(Vector2 pos, int targetLength, int segments, float strength, float weight)
        {
            RopeSegment tmp = null;
            float       weightPerSegment = targetLength / 100f * weight / segments;

            for (int i = 0; i < segments; i++)
            {
                RopeSegment seg = new RopeSegment(this, new Vector2(pos.X + (targetLength / segments - 1) * i, pos.Y), (targetLength / segments - 1), strength, weightPerSegment);
                if (ropeStart == null)
                {
                    ropeStart = seg;
                }
                if (tmp != null)
                {
                    tmp.setNext(seg);
                }
                seg.setLast(tmp);
                tmp = seg;
            }
            ropeEnd = tmp;
        }
Esempio n. 6
0
 public void setNext(RopeSegment next)
 {
     this.next = next;
 }
Esempio n. 7
0
 public void setLast(RopeSegment last)
 {
     this.last = last;
 }