From 9c50226eb7ccf11bf30be627bc3d7bbe0e964caf Mon Sep 17 00:00:00 2001 From: Recrown Date: Wed, 31 Oct 2018 23:58:26 -0500 Subject: [PATCH] basic transition system for between screen transitions (restructured folders) --- RhythmBullet/RhythmBullet.csproj | 2 +- RhythmBullet/RhythmBulletGame.cs | 22 ++++- .../{MainScreen => Screens}/MainScreen.cs | 4 +- .../Zer01HD/Utilities/UI/LoadingScreen.cs | 86 ++++++++++++------- RhythmBullet/Zer01HD/Utilities/UI/Screen.cs | 39 ++++++++- 5 files changed, 114 insertions(+), 39 deletions(-) rename RhythmBullet/Zer01HD/Game/{MainScreen => Screens}/MainScreen.cs (78%) diff --git a/RhythmBullet/RhythmBullet.csproj b/RhythmBullet/RhythmBullet.csproj index d97fbe2..4e5c60d 100644 --- a/RhythmBullet/RhythmBullet.csproj +++ b/RhythmBullet/RhythmBullet.csproj @@ -51,7 +51,7 @@ - + diff --git a/RhythmBullet/RhythmBulletGame.cs b/RhythmBullet/RhythmBulletGame.cs index 8fe92c4..1895f45 100644 --- a/RhythmBullet/RhythmBulletGame.cs +++ b/RhythmBullet/RhythmBulletGame.cs @@ -34,7 +34,7 @@ namespace RhythmBullet public RhythmBulletGame() { graphics = new GraphicsDeviceManager(this); - + BackgroundColor = Color.Black; Content.RootDirectory = "Content"; Assets = new ContentSystem(Content); resolutionContentResolver = new ResolutionContentResolver(); @@ -91,7 +91,7 @@ namespace RhythmBullet // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); QueueContent(); - Screen = new LoadingScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); + Screen = new LoadingScreen(Content.Load("RhythmBullet"), new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); } /// @@ -118,7 +118,21 @@ namespace RhythmBullet resizing = false; PostResize(); } - Screen.Update(gameTime); + switch (Screen.State) { + case ScreenState.EnterTransition: + Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor); + break; + case ScreenState.ExitTransition: + Screen transitionScreen = Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor); + if (transitionScreen != null) + { + Screen = transitionScreen; + } + break; + case ScreenState.Normal: + Screen.Update(gameTime); + break; + } base.Update(gameTime); } @@ -148,7 +162,7 @@ namespace RhythmBullet Assets.UnloadAll(); QueueContent(); Screen.AssetLoadStateChange(true); - Screen = new LoadingScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); + Screen = new LoadingScreen(Content.Load("RhythmBullet"), new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); } private void PostResize() diff --git a/RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs b/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs similarity index 78% rename from RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs rename to RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs index dcd628f..12ed928 100644 --- a/RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs +++ b/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs @@ -7,12 +7,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RhythmBullet.Zer01HD.Game.MainScreen +namespace RhythmBullet.Zer01HD.Game.Screens { class MainScreen : Screen { - Viewport viewport = new Viewport(); - public MainScreen() { diff --git a/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs b/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs index 608a5c0..ade5e82 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs @@ -1,60 +1,86 @@ using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; -using RhythmBullet.Zer01HD.UI; +using RhythmBullet.Zer01HD.Game.Screens; using RhythmBullet.Zer01HD.Utilities.UI; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace RhythmBullet.Zer01HD.Game { class LoadingScreen : Screen { - Texture2D recrown; + Texture2D texture; Color color; Rectangle rectangleBounds; - float proportion = 0.4f; - RhythmBulletGame rhythmBullet; - double progress; - double timePassed; - public LoadingScreen(RhythmBulletGame rhythmBullet, Rectangle dimensions) + float proportion = 0.5f; + bool recorded; + float rR, rG, rB; + float progR, progG, progB; + float progC = 254; + public LoadingScreen(Texture2D texture, Rectangle dimensions) : base(true) { color = Color.White; - this.recrown = rhythmBullet.Content.Load("RhythmBullet"); - this.rhythmBullet = rhythmBullet; + this.texture = texture; rectangleBounds = new Rectangle(0, 0, (int)(dimensions.Height * proportion), (int)(dimensions.Height * proportion)); rectangleBounds.X = (dimensions.Width - rectangleBounds.Width) / 2; rectangleBounds.Y = (dimensions.Height - rectangleBounds.Height) / 2; - } public override void Update(GameTime gameTime) { - if (progress < 1f) - { - double delta = gameTime.ElapsedGameTime.TotalSeconds; - timePassed += delta; - progress = timePassed / 4; - if (progress > 0.9f) - { - progress = 0.9f; - } - rhythmBullet.BackgroundColor.R = (byte)(progress * 255); - rhythmBullet.BackgroundColor.G = (byte)(progress * 255); - rhythmBullet.BackgroundColor.B = (byte)(progress * 255); - - } base.Update(gameTime); } + public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor) + { + float deltaf = (float)delta; + if (progR < 254 || progG < 254 || progB < 254) + { + if (!recorded) + { + rR = (Color.White.R - BGColor.R) / 2.5f; + rG = (Color.White.G - BGColor.G) / 2.5f; + rB = (Color.White.B - BGColor.B) / 2.5f; + recorded = true; + } + progR += rR * deltaf; + progR = Math.Min(progR, 254); + progG += rG * deltaf; + progG = Math.Min(progG, 254); + progB += rB * deltaf; + progB = Math.Min(progB, 254); + BGColor.R = (byte)progR; + BGColor.G = (byte)progG; + BGColor.B = (byte)progB; + } + else if (progC > 0) + { + float rate = deltaf * 255 / 1.5f; + progC -= rate; + progC = Math.Max(progC, 0); + color.R = (byte)progC; + color.G = (byte)progC; + color.B = (byte)progC; + color.A = (byte)progC; + } + else if (assetsLoaded) + { + DoneTransition(); + StartExitTransition(); + } + base.EnteringTransition(delta, assetsLoaded, ref BGColor); + } + + public override Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor) + { + return new MainScreen(); + } + public override void Draw(SpriteBatch spriteBatch) { - spriteBatch.Draw(recrown, rectangleBounds, color); + spriteBatch.Draw(texture, rectangleBounds, color); base.Draw(spriteBatch); } + } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs b/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs index f2e3074..2e793b4 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs @@ -8,11 +8,20 @@ using System.Threading.Tasks; namespace RhythmBullet.Zer01HD.Utilities.UI { + public enum ScreenState { EnterTransition, ExitTransition, Normal } + public class Screen { + ScreenState state; + + public Screen(bool useEnterTransition = false) + { + state = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal; + } + public virtual void Update(GameTime gameTime) { - + } public virtual void Draw(SpriteBatch spriteBatch) @@ -20,6 +29,16 @@ namespace RhythmBullet.Zer01HD.Utilities.UI } + public virtual void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor) + { + + } + + public virtual Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor) + { + return null; + } + public virtual void Show() { @@ -34,5 +53,23 @@ namespace RhythmBullet.Zer01HD.Utilities.UI { } + + public ScreenState State + { + get + { + return state; + } + } + + public void DoneTransition() + { + state = ScreenState.Normal; + } + + public void StartExitTransition() + { + state = ScreenState.ExitTransition; + } } }