private PointF[] NormalizeCoords(VectorGroup group) => group .Scale(_scalling) .Select(p => new PointF(p.X + _width / 2 - camOffset.X * _scalling, _height - p.Y - _height / 2 + camOffset.Y * _scalling)) .ToArray();
public override void Render() { var pts = Bounds.ToArray(); var canPts = new VectorGroup(pts[0], pts[1], pts[4], pts[3], pts[0], pts[4], pts[1], pts[2], pts[3]); View.FillPolygon(new VectorGroup(pts).Move(Position), color, false); View.DrawPolygon(canPts.Move(Position), Color.Black, false, 2); }
public Wall(Vector from, Vector to) { var center = (from + to) * 0.5f; Bounds = VectorGroup.FromRect( new Size((int)MathF.Abs(from.X - to.X), (int)MathF.Abs(from.Y - to.Y))); Position = center; BoundsRadius = from.DistaceTo(to); }
public void FillPolygon(VectorGroup points, Color color, bool isCurved = false) { var normalizedPoints = NormalizeCoords(points); if (isCurved) { _currentGraphics.FillClosedCurve(new SolidBrush(color), normalizedPoints); } else { _currentGraphics.FillPolygon(new SolidBrush(color), normalizedPoints); } }
public void DrawPolygon(VectorGroup points, Color color, bool isCurved = false, float stroke = 1) { var normalizedPoints = NormalizeCoords(points); if (isCurved) { _currentGraphics.DrawClosedCurve(new Pen(color, stroke), normalizedPoints); } else { _currentGraphics.DrawPolygon(new Pen(color, stroke), normalizedPoints); } }
public static bool HandleCollisions(TankState state, TankAppliance appliance, VectorGroup oppos, float elapsed) { var selfBounds = appliance.Bounds .Rotate(appliance.Origin, state.Rotation) .Move(state.Position); var intersected = false; var interections = selfBounds.FindIntersections(oppos); foreach (var((c, d), (a, b)) in interections) { intersected = true; var dir = state.Position.X * (a.Y - b.Y) * state.Position.Y * (b.X - a.X) + (a.X * b.Y - a.Y * b.X); var v = b - a; if (dir == 0) // sorry, that's magic { continue; } var n = new Vector(v.Y, -v.X) * -(dir / MathF.Abs(dir)); // direction to throw body away state.Speed = 0; state.Position += n * 0.05f * elapsed; } return(intersected); }
private void OnWorldPaint(object sender, PaintEventArgs e) { var g = e.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; _frame = new Frame(g, Width, Height, 0.5f); if (_isConnected) { _frame.LookAt(currentState.Position); var rq = new List <TankState>(); rq.Add(currentState); rq.AddRange(enemiesStates); foreach (var state in rq) { if (state != default) { _t1Appliance.Render(_frame, state); var bounds = _t1Appliance.Bounds .Rotate(_t1Appliance.Origin, state.Rotation) .Move(state.Position); _frame.DrawPolygon(bounds, Color.Lime); var ray = new VectorGroup(state.Position, state.Position + Vector.FromAngle(state.GunRotation - 90f) * 2000f); if (state.Loading > 1) { _frame.DrawPolygon(ray, Color.Chocolate); } } } foreach (var wall in _map.Walls) { _frame.FillPolygon(wall.Bounds.Move(wall.Position).Scale(_map.ScallingFactor), Color.FromName(wall.ColorCode)); var bounds = wall.Bounds .Move(wall.Position) .Scale(_map.ScallingFactor); _frame.DrawPolygon(bounds, Color.MediumPurple); } g.DrawString($"Score {currentState.Score}", new Font(FontFamily.GenericMonospace, 20), Brushes.Black, 0, 0); } else { g.DrawString("Connecting", new Font(FontFamily.GenericMonospace, 20), Brushes.Black, 0, 0); } if (currentState?.IsInters ?? false) { g.DrawString("Oh no", new Font(FontFamily.GenericMonospace, 20), Brushes.PaleVioletRed, 0, 0); } /*if (currentState != null) * View.PlaceCamOn(currentState);*/ }