Exemplo n.º 1
0
 public virtual void Draw(SpriteBatch spriteBatch)
 {
     BackgroundSprite.Draw(spriteBatch, BackgroundLocation);
 }
Exemplo n.º 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            frameCounter.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            var fps = string.Format("FPS: {0}", frameCounter.AverageFramesPerSecond);

            spriteBatch.Begin();

            //this.explosionSprite.Draw(gameTime, spriteBatch);
            backgroundSprite.Draw(gameTime, spriteBatch);
            starGenerator.Draw(gameTime, spriteBatch);

            enemyGenerator.Draw(gameTime, spriteBatch);

            if (spaceshipSprite.IsActive)
            {
                spaceshipSprite.Draw(gameTime, spriteBatch);
            }

            laserPool.Draw(gameTime, spriteBatch);

            explosionPool.Draw(gameTime, spriteBatch);

            this.gameOverScene.Draw(gameTime, spriteBatch);

            var scoreString     = string.Format("Score: {0}", this.score.ToString().PadLeft(7, '0'));
            var scoreStringSize = scoreFont.MeasureString(scoreString);

            spriteBatch.DrawString(scoreFont, scoreString, new Vector2(GraphicsDevice.Viewport.Width - scoreStringSize.X - 20, 5), Color.Yellow);

            #region Output Debug Information

            if (settings.ShowDebugInfo)
            {
                // FPS
                spriteBatch.DrawString(messageFont, fps, Vector2.One, Color.Yellow);

                // Spacecraft Information
                var spaceCraftInfo = string.Format("[Spacecraft] X = {0}, Y = {1}", spaceshipSprite.X, spaceshipSprite.Y);
                spriteBatch.DrawString(messageFont, spaceCraftInfo, new Vector2(1, 15), Color.Yellow);

                // Laser Pool Information
                var laserPoolCountStr = string.Format("[Laser Pool] Count = {0}", this.laserPool.Count);
                spriteBatch.DrawString(messageFont, laserPoolCountStr, new Vector2(1, 30), Color.Yellow);

                // Enemy Pool Information
                var enemyPoolCountStr = string.Format("[Enemy Pool] Count = {0}", this.enemyPool.Count);
                spriteBatch.DrawString(messageFont, enemyPoolCountStr, new Vector2(1, 45), Color.Yellow);

                // Explosion Pool Information
                var explPoolCountStr = string.Format("[Expln Pool] Count = {0}", this.explosionPool.Count);
                spriteBatch.DrawString(messageFont, explPoolCountStr, new Vector2(1, 60), Color.Yellow);

                // Viewport Information
                var viewportInfoStr = string.Format("[ Viewport ] Width = {0}, Height = {1}",
                                                    GraphicsDevice.Viewport.Width,
                                                    GraphicsDevice.Viewport.Height);
                spriteBatch.DrawString(messageFont, viewportInfoStr, new Vector2(1, 75), Color.Yellow);

                // Game time Information
                var gameTimeInfoStr = string.Format("[ GameTime ] Total = {0}", gameTime.TotalGameTime);
                spriteBatch.DrawString(messageFont, gameTimeInfoStr, new Vector2(1, 90), Color.Yellow);
            }


            #endregion

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 3
0
        public void DrawBackground()
        {
            int       i, i2, frame;
            Rectangle srcCornerRect = new Rectangle(0, 0, 16, 16);

            frame = 0;

            OuterSpace.spriteobj.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortDepthBackToFront);

            //draw background
            if (IsSpriteLoaded[0] == true)
            {
                for (i = windowRectangle.Left; i <= (windowRectangle.Right - 16); i += 16)
                {
                    if (i < (windowRectangle.Right - 16) && i > windowRectangle.Left)
                    {
                        frame = 1;
                    }

                    BackgroundSprite.Draw(i, windowRectangle.Top, BackgroundSprite.sourceFrame[frame], 0, WindowColor);

                    i2 = windowRectangle.Top + 16;
                    while (i2 < (windowRectangle.Bottom - 16))
                    {
                        BackgroundSprite.Draw(i, i2, BackgroundSprite.sourceFrame[frame + 3], 0, WindowColor);
                        i2 = i2 + 16;
                    }

                    BackgroundSprite.Draw(i, windowRectangle.Bottom - 16, BackgroundSprite.sourceFrame[frame + 6], 0, WindowColor);

                    frame++;
                }
            }

            //draw corners
            if (IsSpriteLoaded[1])
            {
                CornerSprite[0].Draw(windowRectangle.Left, windowRectangle.Top, new Rectangle(0, 0, 16, 32), 0,
                                     Color.FromArgb(255, 255, 255, 255));
            }

            if (IsSpriteLoaded[2])
            {
                CornerSprite[1].Draw(windowRectangle.Right - CornerSprite[1].spritewidth, windowRectangle.Top,
                                     new Rectangle(0, 0, 16, 32), 0, Color.FromArgb(255, 255, 255, 255));
            }

            if (IsSpriteLoaded[3])
            {
                CornerSprite[2].Draw(windowRectangle.Right - CornerSprite[1].spritewidth,
                                     windowRectangle.Bottom - CornerSprite[2].spriteheight, srcCornerRect, 0,
                                     Color.FromArgb(255, 255, 255, 255));
            }

            if (IsSpriteLoaded[4])
            {
                CornerSprite[3].Draw(windowRectangle.Left, windowRectangle.Bottom - CornerSprite[3].spriteheight,
                                     srcCornerRect, 0, Color.FromArgb(255, 255, 255, 255));
            }

            //draw borders
            if (IsSpriteLoaded[5])
            {
                for (i = (windowRectangle.Left + BorderSprite[0].spritewidth); i <= (windowRectangle.Right - (BorderSprite[0].spritewidth * 2)); i += BorderSprite[0].spritewidth)
                {
                    BorderSprite[0].Draw(i, windowRectangle.Top, new Rectangle(0, 0, 16, 32), 0,
                                         Color.FromArgb(255, 255, 255, 255));
                }
            }

            if (IsSpriteLoaded[6])
            {
                for (i = (windowRectangle.Top + CornerSprite[1].spriteheight); i <= (windowRectangle.Bottom - (CornerSprite[2].spriteheight * 2)); i += BorderSprite[1].spriteheight)
                {
                    BorderSprite[1].Draw(windowRectangle.Right - BorderSprite[1].spritewidth, i,
                                         srcCornerRect, 0, Color.FromArgb(255, 255, 255, 255));
                }
            }

            if (IsSpriteLoaded[7])
            {
                for (i = (windowRectangle.Right - (CornerSprite[1].spritewidth * 2)); i >= (windowRectangle.Left + CornerSprite[3].spritewidth); i += -BorderSprite[2].spritewidth)
                {
                    BorderSprite[2].Draw(i, windowRectangle.Bottom - BorderSprite[2].spriteheight,
                                         srcCornerRect, 0, Color.FromArgb(255, 255, 255, 255));
                }
            }

            if (IsSpriteLoaded[8])
            {
                for (i = (windowRectangle.Bottom - (CornerSprite[3].spriteheight * 2)); i >= (windowRectangle.Top + CornerSprite[0].spriteheight); i += -BorderSprite[3].spriteheight)
                {
                    BorderSprite[3].Draw(windowRectangle.Left, i, srcCornerRect, 0,
                                         Color.FromArgb(255, 255, 255, 255));
                }
            }

            //draw caption
            if (IsSpriteLoaded[9])
            {
                int       width          = (CaptionSprite.spritewidth / 3);
                int       newwidth       = width;
                Rectangle captionSrcRect = new Rectangle(width, 0, width, CaptionSprite.spriteheight);

                i = windowRectangle.Left;
                CaptionSprite.Draw(windowRectangle.Left, windowRectangle.Top,
                                   new Rectangle(0, 0, width, CaptionSprite.spriteheight), 0, WindowColor);

                i += width;
                do
                {
                    CaptionSprite.Draw(i, windowRectangle.Top, captionSrcRect, 0, WindowColor);

                    i += newwidth;

                    if (i + newwidth > windowRectangle.Right - newwidth)
                    {
                        newwidth = (windowRectangle.Right - newwidth) - i;
                    }
                }while (i < (windowRectangle.Right - newwidth) & newwidth > 0);

                CaptionSprite.Draw(i, windowRectangle.Top,
                                   new Rectangle(width * 2, 0, width, CaptionSprite.spriteheight), 0, WindowColor);
            }

            OuterSpace.spriteobj.Flush();
            OuterSpace.spriteobj.End();

            //draw caption text
            OuterSpace.textfont.DrawText(windowRectangle.Left + 12, windowRectangle.Top + 8, Color.Black, GetWindowText());
            OuterSpace.textfont.DrawText(windowRectangle.Left + 10, windowRectangle.Top + 6, WindowColor, GetWindowText());
        }