private void updateForce(GameTime gameTime) { RopeSegment current = ropeStart; while (current != null) { current.updateForce(gameTime); current = current.getNext(); } }
public void Draw(SpriteBatch batch) { RopeSegment current = ropeStart; while (current.getNext() != null) { drawBetweenSegments(current, current.getNext(), batch); current = current.getNext(); } }
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); }
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)); }
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; }
public void setNext(RopeSegment next) { this.next = next; }
public void setLast(RopeSegment last) { this.last = last; }