From ced3d03bdb3ce866d832e03fb212865140905a9a Mon Sep 17 00:00:00 2001 From: Thomas Leyh Date: Sun, 24 Jul 2016 08:14:18 +0200 Subject: Add project files. --- V3/Screens/VictoryScreen.cs | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 V3/Screens/VictoryScreen.cs (limited to 'V3/Screens/VictoryScreen.cs') diff --git a/V3/Screens/VictoryScreen.cs b/V3/Screens/VictoryScreen.cs new file mode 100644 index 0000000..ffb2406 --- /dev/null +++ b/V3/Screens/VictoryScreen.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Ninject; +using V3.Input; + +namespace V3.Screens +{ + // ReSharper disable once ClassNeverInstantiated.Global + public sealed class VictoryScreen : AbstractScreen, IInitializable + { + private static TimeSpan sTotalDelay = TimeSpan.FromSeconds(1); + + private readonly ContentManager mContentManager; + private readonly GraphicsDeviceManager mGraphicsDeviceManager; + + private Rectangle mVictoryRectangle; + private Vector2 mFontCenter; + private Vector2 mCenter; + private SpriteFont mVictoryFont; + private Texture2D mRectangle; + + private TimeSpan mDelayTimer = sTotalDelay; + + /// + /// Creates a victory screen if the player defeats the boss enemy. + /// + + public VictoryScreen(ContentManager contentManager, + GraphicsDeviceManager graphicsDeviceManager + ) + : base(false, true) + { + mContentManager = contentManager; + mGraphicsDeviceManager = graphicsDeviceManager; + } + + public override bool HandleKeyEvent(IKeyEvent keyEvent) + { + return false; + } + + public void Initialize() + { + mRectangle = mContentManager.Load("Sprites/WhiteRectangle"); + mVictoryFont = mContentManager.Load("Fonts/VictoryFont"); + } + + public override void Update(GameTime gameTime) + { + var viewport = mGraphicsDeviceManager.GraphicsDevice.Viewport; + if (mDelayTimer > TimeSpan.Zero) + mDelayTimer -= gameTime.ElapsedGameTime; + + mCenter = new Vector2(viewport.Width / 2f, viewport.Height / 2f); + mFontCenter = mVictoryFont.MeasureString("Die Rache ist euer!") / 2; + mVictoryRectangle = new Rectangle(0, (int)mCenter.Y - (int)mFontCenter.Y - 10, viewport.Width, (int)mFontCenter.Y * 2 - 10); + } + + public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) + { + float displayRatio = (float)(1 - mDelayTimer.TotalMilliseconds / sTotalDelay.TotalMilliseconds); + spriteBatch.Begin(); + spriteBatch.Draw(mRectangle, + mVictoryRectangle, + Color.Black * 0.8f * displayRatio); + + spriteBatch.DrawString(mVictoryFont, + "Die Rache ist euer!", + mCenter, + Color.DarkGoldenrod * displayRatio, 0, mFontCenter, 1.0f, SpriteEffects.None, 0.5f); + spriteBatch.End(); + } + } + } -- cgit v1.2.1