Ejemplo n.º 1
0
        /// <summary>
        /// Acts as a drawing delegate for DrawObjectWithTransform
        /// After performing the necessary transformation (translate/rotate)
        /// DrawObjectWithTransform will invoke this method
        /// </summary>
        /// <param name="o">The object to draw</param>
        /// <param name="e">The PaintEventArgs to access the graphics</param>
        private void ShipDrawer(object o, PaintEventArgs e)
        {
            Ship   ship = o as Ship;
            Bitmap shipSprite;
            int    x, y;
            Point  p;

            x = WorldSpaceToImageSpace(this.Size.Width, (int)ship.GetLocation().GetX() - (SHIP_SIZE.Width / 2));
            y = WorldSpaceToImageSpace(this.Size.Width, (int)ship.GetLocation().GetY() - (SHIP_SIZE.Height / 2));
            p = new Point(x, y);

            if (theWorld.GetMarioMode() && ship.GetID() == theWorld.GetCurrentPlayer())
            {
                shipSprite = marioShip;
            }
            else
            {
                if (ship.GetThrust())
                {
                    shipSprite = shipSpritesThrust[ship.GetID() % shipSprites.Count];
                }
                else
                {
                    shipSprite = shipSprites[ship.GetID() % shipSprites.Count];
                }
            }

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.DrawImage(shipSprite, p);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Acts as a drawing delegate for DrawObjectWithTransform
        /// After performing the necessary transformation (translate/rotate)
        /// DrawObjectWithTransform will invoke this method.
        /// Draws a ship with the images that are loaded in the LoadImages() method.
        /// </summary>
        /// <param name="o">The object to draw</param>
        /// <param name="e">The PaintEventArgs to access the graphics</param>
        private void ShipDrawer(object o, PaintEventArgs e)
        {
            Ship ship = o as Ship;

            int width  = 35;
            int height = 35;

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // Rectangles are drawn starting from the top-left corner.
            // So if we want the rectangle centered on the player's location, we have to offset it
            // by half its size to the left (-width/2) and up (-height/2)
            Rectangle r      = new Rectangle(-(width / 2), -(height / 2), width, height);
            int       shipID = ship.GetShipID() % 8;

            if (!ship.GetThrust())
            {
                e.Graphics.DrawImage(shipImages[shipID], r);
            }
            else
            {
                e.Graphics.DrawImage(shipImages[shipID + 8], r);
            }
        }