private void DrawStrand(Graphics graphics, Rectangle clip, Strand strand) { int x; int y; x = strand.Position.X; y = strand.Position.Y; if (this.ShouldRender(clip, x, y)) { if (_drawShapes) { GraphicsState state; state = graphics.Save(); graphics.TranslateTransform(x, y); graphics.RotateTransform(Compass.GetAngle(strand.Heading)); graphics.DrawPolygon(_strandPen, _strandShape); graphics.Restore(state); } else { graphics.DrawLine(_strandPen, new Point(strand.Position.X - 1, strand.Position.Y - 1), new Point(strand.Position.X + 1, strand.Position.Y + 1)); graphics.DrawLine(_strandPen, new Point(strand.Position.X - 1, strand.Position.Y + 1), new Point(strand.Position.X + 1, strand.Position.Y - 1)); } } }
private void DrawChemoeffector(Graphics graphics, Rectangle clip, Chemoeffector chemoeffector, Pen pen, Point[] shape, bool showDetectionZone) { Rectangle bounds; bounds = new Rectangle(chemoeffector.Position.X - (chemoeffector.Strength / 2), chemoeffector.Position.Y - (chemoeffector.Strength / 2), chemoeffector.Strength, chemoeffector.Strength); if (this.ShouldRender(clip, bounds)) { if (showDetectionZone) { if (_outlinesOnly) { graphics.DrawEllipse(pen, bounds); } else { using (GraphicsPath ellipsePath = new GraphicsPath()) { ellipsePath.AddEllipse(bounds); using (PathGradientBrush brush = new PathGradientBrush(ellipsePath)) { brush.CenterPoint = chemoeffector.Position; brush.CenterColor = Color.FromArgb(128, pen.Color); brush.SurroundColors = new[] { Color.Transparent }; graphics.FillEllipse(brush, bounds); } } } } if (_drawShapes) { int x; int y; GraphicsState state; x = chemoeffector.Position.X; y = chemoeffector.Position.Y; state = graphics.Save(); graphics.TranslateTransform(x, y); graphics.RotateTransform(Compass.GetAngle(chemoeffector.Heading)); graphics.DrawPolygon(pen, shape); graphics.Restore(state); } else { graphics.DrawLine(pen, new Point(chemoeffector.Position.X - 1, chemoeffector.Position.Y), new Point(chemoeffector.Position.X + 1, chemoeffector.Position.Y)); graphics.DrawLine(pen, new Point(chemoeffector.Position.X, chemoeffector.Position.Y - 1), new Point(chemoeffector.Position.X, chemoeffector.Position.Y + 1)); } } }
public void GetAngleTestCases(Point current, int expected) { // arrange int actual; // act actual = Compass.GetAngle(current); // assert Assert.AreEqual(expected, actual); }
public void Draw(XnaRenderer renderer) { Tile[] parts = _body.ToArray(); for (int i = 0; i < parts.Length; i++) { Texture texture; float angle = 0; Tile part = parts[i]; if (i == parts.Length - 1) { texture = _headAnimation.CurrentTexture; angle = Compass.GetAngle(MoveDirection); } else if (i == 0) { texture = _tailTexture; CardinalDirection directionOfLast = Compass.GetDirection(parts[i + 1].Position - parts[i].Position); angle = Compass.GetAngle(directionOfLast); } else { CardinalDirection directionOfNext = Compass.GetDirection(parts[i - 1].Position - parts[i].Position); CardinalDirection directionOfLast = Compass.GetDirection(parts[i + 1].Position - parts[i].Position); if (Compass.GetOppositeDirection(directionOfLast) == directionOfNext) { texture = _bodyNsTexture; if (directionOfNext == CardinalDirection.East || directionOfNext == CardinalDirection.West) { angle = MathHelper.PiOver2; } } else { texture = _bodyNeTexture; if (directionOfLast == CardinalDirection.North && directionOfNext == CardinalDirection.West) { angle = MathHelper.PiOver2 * 3; } if (directionOfLast == CardinalDirection.East && directionOfNext == CardinalDirection.South) { angle = MathHelper.PiOver2; } if (directionOfLast == CardinalDirection.South && directionOfNext == CardinalDirection.East) { angle = MathHelper.PiOver2; } if (directionOfLast == CardinalDirection.South && directionOfNext == CardinalDirection.West) { angle = MathHelper.Pi; } if (directionOfLast == CardinalDirection.West && directionOfNext == CardinalDirection.South) { angle = MathHelper.Pi; } if (directionOfLast == CardinalDirection.West && directionOfNext == CardinalDirection.North) { angle = MathHelper.PiOver2 * 3; } } } renderer.DrawSprite(texture, new Vector2(part.Position.X + 0.5f, part.Position.Y + 0.5f), new Vector2(1f, 1f), angle, Color.Green, 1f); } }