Exemplo n.º 1
0
        /// <summary>
        /// Draws the animated sprite.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            // Save off the previous bounding box before the draw method advances the current frame
            this.PreviousBoundingBox = this.BoundingBox;

            if (this.IsAlive && this._isActive)
            {
                // Flip the sprite to face the way we are moving.
                if (this.Velocity.X > 0)
                {
                    this._flip = SpriteEffects.FlipHorizontally;
                }
                else if (Velocity.X < 0)
                {
                    this._flip = SpriteEffects.None;
                }

                if (!this.IsInvincible || ((int)(this._timeOfInvincibility.TotalMilliseconds / 250) % 2 == 0))
                {
                    this._animationPlayer.Draw(gameTime, spriteBatch, this.Position, this._flip);
                }

#if DEBUG
                // Draw debug outline
                if (ScreenManager.DEBUG_ENABLED)
                {
                    var boundingBox = this.SourceRectangle.HasValue ? this.SourceRectangle.Value : this.Texture.Bounds;
                    boundingBox = new Rectangle((int)this.Position.X, (int)this.Position.Y, boundingBox.Width, boundingBox.Height);
                    DrawingUtils.DrawBorder(spriteBatch, boundingBox, 1, Color.Blue);
                }
#endif
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the menu.
        /// </summary>
        /// <param name="gameTime">Time passed since the last call to Draw.</param>
        public override void Draw(GameTime gameTime)
        {
            this.ScreenManager.SpriteBatch.Begin();

            // Draw the background
            this.ScreenManager.SpriteBatch.Draw(this._background, this.ScreenManager.GraphicsDevice.Viewport.Bounds, Color.White);

            // Calculate the string position
            var text             = (this._score + (int)(this._percentPointsToAdd * this._pointsToAward)).ToString();
            var centerOfLocation = (int)(this._scoreLocation.X + ((this._scoreLocation.Right - this._scoreLocation.Left) / 2));
            var leftOfCenter     = (int)this._font.MeasureString(text).X / -2;
            var position         = new Vector2(centerOfLocation + leftOfCenter, this._scoreLocation.Y);

            // Draw the score
            DrawingUtils.DrawShadowedString(this.ScreenManager.SpriteBatch, this._font, text, position, this._color);

            // Show the continue "menu" item
            if (this._showTextBox)
            {
                var centerX        = this.ScreenManager.GraphicsDevice.Viewport.Width / 2;
                var centerY        = this.ScreenManager.GraphicsDevice.Viewport.Height / 2;
                var centerXDialog  = this._nameDialog.Width / 2;
                var centerYDialog  = this._nameDialog.Height / 2;
                var dialogPosition = new Rectangle(centerX - centerXDialog, centerY - centerYDialog, this._nameDialog.Width, this._nameDialog.Height);

                this.ScreenManager.SpriteBatch.Draw(this._nameDialog, dialogPosition, Color.White);

                this._textBox.X     = dialogPosition.X + 58;
                this._textBox.Y     = dialogPosition.Y + 166;
                this._textBox.Width = 440;

                this._textBox.Draw(this.ScreenManager.SpriteBatch, gameTime);
            }
            else if (this._transitionHelper.State == TransitionHelper.TransitionState.Complete)
            {
                // Pulsate the size of the selected menu entry.
                double time = gameTime.TotalGameTime.TotalSeconds;

                float pulsate = (float)Math.Sin(time * 6) + 1;

                float scale = 1 + pulsate * 0.05f * this._selectionFade;

                this.ScreenManager.SpriteBatch.DrawString(
                    this._menuFont, this._menuText, this._menuPosition, this._menuTextColor, 0,
                    Vector2.Zero, scale, SpriteEffects.None, 0);
            }

            this.ScreenManager.SpriteBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draw everything in the level from background to foreground.
        /// </summary>
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (this._player != null)
            {
                // Draw all the background layers
                spriteBatch.Begin();

                for (int i = 0; i <= this._levelInfo.EntityLayer; ++i)
                {
                    this._layers[i].Draw(spriteBatch, this._cameraPosition);
                }

                spriteBatch.End();

                // Calculate the current camera view port
                this.ScrollCamera(spriteBatch.GraphicsDevice.Viewport);
                Matrix cameraTransform = Matrix.CreateTranslation(-this._cameraPosition, 0.0f, 0.0f);

                // Draw the player and all of the sprites
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cameraTransform);

                this._player.Draw(gameTime, spriteBatch);
                if (this._screenManager.DebugEnabled)
                {
                    DrawingUtils.DrawRectangle(spriteBatch, this._player.BoundingBox, this._screenManager.TransparentTexture, Color.White, false, 1);
                }

                this._sprites.ForEach((sprite) =>
                {
                    sprite.Draw(gameTime, spriteBatch);
                    if (this._screenManager.DebugEnabled)
                    {
                        DrawingUtils.DrawRectangle(spriteBatch, sprite.BoundingBox, this._screenManager.TransparentTexture, Color.White, false, 1);
                    }
                });

                spriteBatch.End();

                // Draw all the foreground layers
                spriteBatch.Begin();

                for (int i = this._levelInfo.EntityLayer + 1; i < this._layers.Count; ++i)
                {
                    this._layers[i].Draw(spriteBatch, this._cameraPosition);
                }

                spriteBatch.End();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draws the sprite.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (this.Texture != null)
            {
                spriteBatch.Draw(this.Texture, this.Position, Color.White);

#if DEBUG
                // Draw debug outline
                if (ScreenManager.DEBUG_ENABLED)
                {
                    var boundingBox = this.SourceRectangle.HasValue ? this.SourceRectangle.Value : this.Texture.Bounds;
                    boundingBox = new Rectangle((int)this.Position.X, (int)this.Position.Y, boundingBox.Width, boundingBox.Height);
                    DrawingUtils.DrawBorder(spriteBatch, boundingBox, 1, Color.Yellow);
                }
#endif
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the sprite.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            var pixel = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);

            pixel.SetData(new[] { this._color });
            spriteBatch.Draw(pixel, this.BoundingBox, Color.White);

#if DEBUG
            // Draw debug outline
            if (ScreenManager.DEBUG_ENABLED)
            {
                var boundingBox = this.SourceRectangle.HasValue ? this.SourceRectangle.Value : this.Texture.Bounds;
                boundingBox = new Rectangle((int)this.Position.X, (int)this.Position.Y, boundingBox.Width, boundingBox.Height);
                DrawingUtils.DrawBorder(spriteBatch, boundingBox, 1, Color.Purple);
            }
#endif
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draws the sprite.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            // Save off the previous bounding box before the draw method advances the current frame
            this.PreviousBoundingBox = this.BoundingBox;

            if (this.IsActive || (this._spawning && this._drawEnemy))
            {
                var flip = this._direction > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
                this._animationPlayer.Draw(gameTime, spriteBatch, this.Position, flip);

#if DEBUG
                // Draw debug outline
                if (ScreenManager.DEBUG_ENABLED)
                {
                    var boundingBox = this.SourceRectangle.HasValue ? this.SourceRectangle.Value : this.Texture.Bounds;
                    boundingBox = new Rectangle((int)this.Position.X, (int)this.Position.Y, boundingBox.Width, boundingBox.Height);
                    DrawingUtils.DrawBorder(spriteBatch, boundingBox, 1, Color.Red);
                }
#endif
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Draws the HUD
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();

            // Draw the Hud overlay.
            spriteBatch.Draw(this._hudTexture, this._hudRectangle, Color.White);

            // Draw time
            DrawingUtils.DrawShadowedString(spriteBatch, this._hudFont, _timeString, _timeLocation, _timeColor);

            // Draw score
            DrawingUtils.DrawShadowedString(spriteBatch, this._hudFont, string.IsNullOrEmpty(_scoreString) ? "$0.00" : String.Format("${0}", _scoreString), _scoreLocation, _defaultFontColor);

            // IF there's a message, show it
            if (!string.IsNullOrEmpty(_message))
            {
                DrawingUtils.DrawShadowedString(spriteBatch, this._hudFont, _message, _messageLocation, _defaultFontColor);
            }

            spriteBatch.End();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draws the sprite.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="spriteBatch">The sprite batch.</param>
        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (this.Texture != null)
            {
                spriteBatch.Draw(this.Texture, this.Position, this.SourceRectangle, Color.White);

                //spriteBatch.Draw(this.Texture, this.Position, this.SourceRectangle,
                //    this.TintColor, this.Rotation, this.Origin,
                //    this.Scale, this.Effects, this.LayerDepth);

#if DEBUG
                // Draw debug outline
                if (ScreenManager.DEBUG_ENABLED)
                {
                    var boundingBox = this.SourceRectangle.HasValue ? this.SourceRectangle.Value : this.Texture.Bounds;
                    boundingBox = new Rectangle((int)this.Position.X, (int)this.Position.Y, boundingBox.Width, boundingBox.Height);
                    DrawingUtils.DrawBorder(spriteBatch, boundingBox, 1, Color.White);
                }
#endif
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Draws the specified sprite batch.
 /// </summary>
 /// <param name="spriteBatch">The sprite batch.</param>
 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Begin();
     DrawingUtils.DrawShadowedString(spriteBatch, this._hudFont, _timeString, _timeLocation, _timeColor);
     spriteBatch.End();
 }