예제 #1
0
        public override void Render(IFrame frame, TankState state)
        {
            var body = bodyVGroup
                       .Move(Origin)
                       .Rotate(Vector.Zero, state.Rotation)
                       .Move(state.Position);

            var head = headVGroup
                       .Move(Origin)
                       .Rotate(Vector.Zero, state.GunRotation - 90f)
                       .Move(state.Position);

            frame.FillPolygon(body, Color.DarkOliveGreen, false);
            frame.FillPolygon(head, Color.YellowGreen, false);
            frame.FillCircle(state.Position, 3, Color.Brown);

            /*foreach (var (points, turnRatio) in wheesMeta)
             * foreach (var p in points)
             * {
             *  var wheel = wheelVGroup.Rotate(Vector.Zero, SteerAngle * turnRatio).Move(Origin).Move(p)
             *      .Rotate(Vector.Zero, Rotation).Move(Position);
             *
             *  if (Abs(overload) > 0.95f)
             *  {
             *      View.MarkSlip(wheel);
             *  }
             *
             *  View.FillPolygon(wheel, Color.Black, true);
             * }
             *
             * VectorGroup Prepare(VectorGroup vg) =>
             *  vg.Move(Origin).Rotate(Vector.Zero, Rotation).Move(Position);
             *
             * var headPoints = Prepare(headVGroup);
             *
             * var bodyPoints = Prepare(bodyVGroup);
             *
             * View.FillPolygon(bodyPoints, Color.White, false);
             * View.DrawPolygon(bodyPoints, Color.Black, false);
             *
             * var fuelRatio = Fuel / MaxFuel;
             *
             * View.FillPolygon(headPoints, Color.FromArgb(
             *      (int) (255 - ((255 - headColor.R) * fuelRatio)),
             *      (int) (255 - ((255 - headColor.G) * fuelRatio)),
             *      (int) (255 - ((255 - headColor.B) * fuelRatio))),
             *  true);
             *
             * View.DrawPolygon(headPoints, Color.Black, true);*/
        }
예제 #2
0
        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);*/
        }