Beispiel #1
0
        private void DrawBullet(Bullet b, Graphics g)
        {
            if (b.Exploding && b.ExplosionTick > .5 * BPS) return;

            var frame = (Math.Abs(b.ExplosionTick / (int)(.5 / 16 * BPS)) + int.MaxValue / 2) % 16;
            g.TranslateTransform((float)b.X, (float)b.Y);
            if (b.Exploding)
            {
                g.DrawImage(ExplosionImage, new Rectangle(-12, -12, 24, 24),
                    new Rectangle(0 + 24 * (frame % 4), 0 + 24 * (frame / 4), 24, 24), GraphicsUnit.Pixel);
            }
            else
            {
                g.RotateTransform((float)b.Angle);
                g.DrawImage(BulletImage, new Rectangle(-2, -2, 13, 5));
                g.RotateTransform(-(float)b.Angle);
            }
            g.TranslateTransform(-(float)b.X, -(float)b.Y);
        }
Beispiel #2
0
        private void TickBullet(Bullet b)
        {
            if (!b.Exploding)
            {
                b.Y += Sin(b.Angle) * BULLET_SPEED;
                b.X += Cos(b.Angle) * BULLET_SPEED;

                if (b.X < 0 || b.X > ARENAWIDTH || b.Y < 0 || b.Y > ARENAHEIGHT)
                {
                    b.Exploding = true;
                }

                var hit = Robots.FirstOrDefault(r => BulletOverlapsRobot(b, r));
                if (null != hit)
                {
                    hit.HP -= DAMAGE_PER_BULLET_HIT;
                    b.Exploding = true;
                }
            }else
            {
                ++b.ExplosionTick;
                if(b.ExplosionTick > 1000)
                {
                    b.Exploded = true;
                }
            }
        }
Beispiel #3
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;
 }