diff --git a/RhythmBullet/Content/RhythmBullet.png b/RhythmBullet/Content/RhythmBullet.png index 0655c08..73560cb 100644 Binary files a/RhythmBullet/Content/RhythmBullet.png and b/RhythmBullet/Content/RhythmBullet.png differ diff --git a/RhythmBullet/RhythmBulletGame.cs b/RhythmBullet/RhythmBulletGame.cs index a67a182..d0f5c72 100644 --- a/RhythmBullet/RhythmBulletGame.cs +++ b/RhythmBullet/RhythmBulletGame.cs @@ -23,19 +23,18 @@ namespace RhythmBullet public const int WORLD_HEIGHT = 3; public static int pixels_per_WU; - public GraphicsDeviceManager Graphics; + GraphicsDeviceManager graphics; SpriteBatch spriteBatch; + public Color BackgroundColor; public readonly ContentSystem Assets; readonly ResolutionContentResolver resolutionContentResolver; public PreferencesManager preferencesManager; private Screen currentScreen; - + private bool resizing; public RhythmBulletGame() { - Graphics = new GraphicsDeviceManager(this); - Graphics.PreferredBackBufferWidth = 320; - Graphics.PreferredBackBufferHeight = 320; - Window.IsBorderless = true; + graphics = new GraphicsDeviceManager(this); + BackgroundColor = new Color(0, 0, 0, 255); Content.RootDirectory = "Content"; Assets = new ContentSystem(Content); resolutionContentResolver = new ResolutionContentResolver(); @@ -45,6 +44,10 @@ namespace RhythmBullet preferencesManager = new PreferencesManager(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/RhythmBullet", new General(), new Controls()); + preferencesManager.Load(); + Resolution resolution = preferencesManager.GetPreferences().Resolution; + graphics.PreferredBackBufferWidth = resolution.Width; + graphics.PreferredBackBufferHeight = resolution.Height; } public Screen Screen @@ -72,13 +75,9 @@ namespace RhythmBullet /// protected override void Initialize() { - //Load preferences - preferencesManager.Load(); - Resolution resolution = preferencesManager.GetPreferences().Resolution; resolutionContentResolver.Width = resolution.Width; resolutionContentResolver.Height = resolution.Height; - QueueContent(); Debug.WriteLine("Initial setup complete."); base.Initialize(); } @@ -91,8 +90,8 @@ namespace RhythmBullet { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); - Screen = new LoadingScreen(Content.Load("RhythmBullet"), new Rectangle(0,0, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight)); - // TODO: use this.Content to load your game content here + QueueContent(); + Screen = new SplashScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); } /// @@ -101,7 +100,7 @@ namespace RhythmBullet /// protected override void UnloadContent() { - // TODO: Unload any non ContentManager content here + Assets.UnloadAll(); } /// @@ -114,6 +113,10 @@ namespace RhythmBullet if (!Assets.Done) { Assets.Update(); + } else if (resizing) + { + resizing = false; + PostResize(); } Screen.Update(gameTime); @@ -126,7 +129,7 @@ namespace RhythmBullet /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { - GraphicsDevice.Clear(Color.Transparent); + GraphicsDevice.Clear(BackgroundColor); spriteBatch.Begin(); Screen.Draw(spriteBatch); spriteBatch.End(); @@ -134,21 +137,26 @@ namespace RhythmBullet base.Draw(gameTime); } - public void PreAssetLoad() + public void Resize(int width, int height) { + resolutionContentResolver.Width = width; + resolutionContentResolver.Height = height; + graphics.PreferredBackBufferWidth = width; + graphics.PreferredBackBufferHeight = height; + resizing = true; Assets.UnloadAll(); - resolutionContentResolver.Width = Graphics.PreferredBackBufferWidth; - resolutionContentResolver.Height = Graphics.PreferredBackBufferHeight; QueueContent(); Screen.AssetLoadStateChange(true); + Screen = new SplashScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); } - public void PostAssetLoad() + private void PostResize() { + graphics.ApplyChanges(); Screen.AssetLoadStateChange(false); } - void QueueContent() + private void QueueContent() { Assets.Queue("Tech-Circle1"); Assets.Queue("polyjet-standard"); diff --git a/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs b/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs index d6c50a9..f9918b4 100644 --- a/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs +++ b/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs @@ -34,7 +34,8 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem try { assets.Add(assetName, contentManager.Load(path)); - } catch (ContentLoadException cle) + } + catch (ContentLoadException cle) { Debug.WriteLine("Failed to load " + assetName + "with modified path: " + cle.Message); Debug.WriteLine("Loading asset from root: " + assetName); @@ -99,10 +100,13 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem /// the string name used to load the asset public void Remove(string name) { - if (assets.ContainsKey(name)) + lock (queue) { - assets[name].Dispose(); - assets.Remove(name); + if (assets.ContainsKey(name)) + { + assets[name].Dispose(); + assets.Remove(name); + } } } @@ -122,12 +126,12 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem /// public void UnloadAll() { - foreach (KeyValuePair asset in assets) + lock (queue) { - asset.Value.Dispose(); - assets.Remove(asset.Key); + contentManager.Unload(); + assets.Clear(); + ClearQueue(); } - ClearQueue(); } public bool Done diff --git a/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs b/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs index 58a2b95..6944649 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs @@ -5,20 +5,46 @@ using RhythmBullet.Zer01HD.UI; 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 + class SplashScreen : Screen { Texture2D recrown; Rectangle rectangleBounds; - public LoadingScreen(Texture2D recrown, Rectangle bounds) + float proportion = 0.4f; + RhythmBulletGame rhythmBullet; + float progress; + public SplashScreen(RhythmBulletGame rhythmBullet, Rectangle dimensions) { - this.recrown = recrown; - this.rectangleBounds = bounds; + this.recrown = rhythmBullet.Content.Load("RhythmBullet"); + this.rhythmBullet = rhythmBullet; + 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 < 0.8f) + { + float delta = (float) gameTime.ElapsedGameTime.TotalSeconds; + progress += (delta/6f); + if (progress > 1f) + { + progress = 1f; + } + rhythmBullet.BackgroundColor.R = (byte)(progress * 255); + rhythmBullet.BackgroundColor.G = (byte)(progress * 255); + rhythmBullet.BackgroundColor.B = (byte)(progress * 255); + + } + base.Update(gameTime); } public override void Draw(SpriteBatch spriteBatch)