Ejemplo n.º 1
0
        /// <summary>
        /// issue [A.1.5] of the design document
        /// </summary>
        /// <param name="graphics"></param>
        public void Render(Graphics graphics)
        {
            Pen pen = new Pen(TeamColor);

            int   healthMeterX         = (int)Location.X + (int)(DimensionsUtil.GetAvatarWidth() - 20);
            int   healthMeterY         = (int)Location.Y + 20;
            float healthMeterBarHeight = ((float)Health / (float)_maxHealth) * DimensionsUtil.GetHealthMeterHeight();

            int        ammoMeterX         = (int)Location.X + 10;
            int        ammoMeterY         = (int)Location.Y + 20;
            float      ammoMeterBarHeight = ((float)Ammo / (float)_maxAmmo) * DimensionsUtil.GetAmmoMeterHeight();
            Color      healthMeterColor   = MeterUtil.GetColorFromValue(Health);
            SolidBrush healthMeterBrush   = new SolidBrush(healthMeterColor);

            Color      ammoMeterColor = MeterUtil.GetColorFromValue(Ammo);
            SolidBrush ammoMeterBrush = new SolidBrush(ammoMeterColor);

            GraphicsPath graphicsPath       = new GraphicsPath();
            RectangleF   avatarMainBody     = new RectangleF(Location, Size);
            RectangleF   avatarGun          = new RectangleF(Location.X + ((Size.Width / 2) - (DimensionsUtil.GetGunWidth() / 2)), Location.Y - DimensionsUtil.GetGunHeight(), DimensionsUtil.GetGunWidth(), DimensionsUtil.GetGunHeight());
            RectangleF   healthMeterOutline = new RectangleF(healthMeterX, healthMeterY, DimensionsUtil.GetHealthMeterWidth(), DimensionsUtil.GetHealthMeterHeight());
            RectangleF   ammoMeterOutline   = new RectangleF(ammoMeterX, ammoMeterY, DimensionsUtil.GetAmmoMeterWidth(), DimensionsUtil.GetAmmoMeterHeight());

            graphicsPath.AddRectangle(avatarMainBody);
            graphicsPath.AddRectangle(avatarGun);
            graphicsPath.AddRectangle(healthMeterOutline);
            graphicsPath.AddRectangle(ammoMeterOutline);

            RectangleF healthMeterBar = new RectangleF(healthMeterX, healthMeterY + (DimensionsUtil.GetHealthMeterHeight() - healthMeterBarHeight), DimensionsUtil.GetHealthMeterWidth(), healthMeterBarHeight);
            RectangleF ammoMeterBar   = new RectangleF(ammoMeterX, ammoMeterY + DimensionsUtil.GetAmmoMeterHeight() - ammoMeterBarHeight, DimensionsUtil.GetAmmoMeterWidth(), ammoMeterBarHeight);

            GraphicsPath healthMeterBarPath = new GraphicsPath();

            healthMeterBarPath.AddRectangle(healthMeterBar);

            GraphicsPath ammoMeterBarPath = new GraphicsPath();

            ammoMeterBarPath.AddRectangle(ammoMeterBar);

            Matrix rotationMatrix = new Matrix(1, 0, 0, 1, 0, 0);
            PointF rotationPoint  = new PointF(avatarMainBody.Location.X + (DimensionsUtil.GetAvatarWidth() / 2), avatarMainBody.Location.Y + (DimensionsUtil.GetAvatarHeight() / 2));

            switch (FacingDirection)
            {
            case FacingDirectionType.North:
                break;

            case FacingDirectionType.East:
                rotationMatrix.RotateAt(90F, rotationPoint);
                break;

            case FacingDirectionType.South:
                rotationMatrix.RotateAt(180F, rotationPoint);
                break;

            case FacingDirectionType.West:
                rotationMatrix.RotateAt(270F, rotationPoint);
                break;
            }

            graphicsPath.Transform(rotationMatrix);
            ammoMeterBarPath.Transform(rotationMatrix);
            healthMeterBarPath.Transform(rotationMatrix);

            graphics.FillPath(healthMeterBrush, healthMeterBarPath);
            graphics.FillPath(ammoMeterBrush, ammoMeterBarPath);

            graphics.DrawPath(pen, graphicsPath);

            //render the shield, ignoring any rotations (rotations are ignored because it is easier for collision detection with the shield)
            switch (ShieldLocation)
            {
            case ShieldLocationType.Front:
                graphics.DrawLine(pen, Location.X, Location.Y - DimensionsUtil.GetAvatarShieldOffset(), Location.X + Size.Width, Location.Y - DimensionsUtil.GetAvatarShieldOffset());
                break;

            case ShieldLocationType.Back:
                graphics.DrawLine(pen, Location.X, Location.Y + DimensionsUtil.GetAvatarShieldOffset() + Size.Height, Location.X + Size.Width, Location.Y + DimensionsUtil.GetAvatarShieldOffset() + Size.Height);
                break;

            case ShieldLocationType.Left:
                graphics.DrawLine(pen, Location.X - DimensionsUtil.GetAvatarShieldOffset(), Location.Y, Location.X - DimensionsUtil.GetAvatarShieldOffset(), Location.Y + Size.Height);
                break;

            case ShieldLocationType.Right:
                graphics.DrawLine(pen, Location.X + Size.Width + DimensionsUtil.GetAvatarShieldOffset(), Location.Y, Location.X + Size.Width + DimensionsUtil.GetAvatarShieldOffset(), Location.Y + Size.Height);
                break;
            }
        }