Example #1
0
        private void DrawRobot(Robot r, Graphics g)
        {
            var frame = (Math.Abs(r.Steps / (int)(0.02 * BPS)) + int.MaxValue / 2) % 8;
            g.TranslateTransform((float)r.X, (float)r.Y);
            g.RotateTransform((float)r.Angle);
            g.DrawImage(RobotImage, new Rectangle(-16, -16, 32, 32), new Rectangle(0 + 32 * frame, 0, 32, 32), GraphicsUnit.Pixel);
            g.RotateTransform((float)r.CannonAngle);
            g.DrawImage(CannonImage, new Rectangle(-7, -7, 24, 14));
            g.RotateTransform(-(float)r.CannonAngle);
            g.RotateTransform(-(float)r.Angle);

            //g.FillPolygon(Brushes.LightGray, new[] {
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-12f)),
            //    new PointF((float)Math.Round(15f), (float)Math.Round(-12f)),
            //    new PointF((float)Math.Round(15f), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            //});
            g.FillPolygon(Brushes.Red, new[] {
                new PointF((float)Math.Round(-15f), (float)Math.Round(-12f)),
                new PointF((float)Math.Round(-15f + 30 * Math.Max(0, r.HP)), (float)Math.Round(-12f)),
                new PointF((float)Math.Round(-15f + 30 * Math.Max(0, r.HP)), (float)Math.Round(-9f)),
                new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            });
            //g.FillPolygon(Brushes.Blue, new[] {
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f + 30 * Math.Max(0, 1 - (double)r.FireCooldown / GameState.FIRE_COOLDOWN)), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f + 30 * Math.Max(0, 1 - (double)r.FireCooldown / GameState.FIRE_COOLDOWN)), (float)Math.Round(-7f)),
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-7f)),
            //});

            g.TranslateTransform(-(float)r.X, -(float)r.Y);
        }
Example #2
0
 private void TickRobot(Robot r)
 {
     if (r.FireCooldown > 0) { --r.FireCooldown; }
 }
Example #3
0
 private bool RobotsOverlap(Robot r1, Robot r2)
 {
     var xd = Math.Abs(r1.X - r2.X);
     var yd = Math.Abs(r1.Y - r2.Y);
     return Math.Sqrt(xd * xd + yd * yd) <= 2 * ROBOT_RADIUS;
 }
Example #4
0
 private Robot MakeRobot()
 {
     var r1 = new Robot
     {
         X = RNG.Next(ARENAWIDTH - ROBOT_RADIUS),
         Y = RNG.Next(ARENAHEIGHT - ROBOT_RADIUS),
         Angle = RNG.Next(360),
         CannonAngle = 0,
         FireCooldown = 0,
         HP = 1,
     };
     var collided = false;
     do
     {
         collided = false;
         foreach (var r2 in Robots)
         {
             if (RobotsOverlap(r1, r2))
             {
                 collided = true;
                 r1.X = RNG.Next(ARENAWIDTH - ROBOT_RADIUS);
                 r1.Y = RNG.Next(ARENAHEIGHT - ROBOT_RADIUS);
                 r1.Angle = RNG.Next(360);
                 break;
             }
         }
     } while (collided);
     return r1;
 }
Example #5
0
        private void Forward(int i)
        {
            var r = Robots[i];

            var y = r.Y + Sin(r.Angle) * ROBOT_SPEED;
            var x = r.X + Cos(r.Angle) * ROBOT_SPEED;
            var r1 = new Robot { X = x, Y = y };

            if (InRectangle(x, y, ROBOT_RADIUS, 0, 0, ARENAWIDTH, ARENAHEIGHT) && Robots.All(r2 => r == r2 || !RobotsOverlap(r1, r2)))
            {
                r.X = x;
                r.Y = y;
                ++r.Steps;
            }
        }
Example #6
0
 private bool BulletOverlapsRobot(Bullet b, Robot r)
 {
     var xd = Math.Abs(b.X - r.X);
     var yd = Math.Abs(b.Y - r.Y);
     return Math.Sqrt(xd * xd + yd * yd) <= ROBOT_RADIUS + BULLET_RADIUS;
 }