rhythmbullet/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs

87 lines
2.8 KiB
C#
Raw Normal View History

2018-09-15 19:05:14 +00:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Game.Screens;
using RhythmBullet.Zer01HD.Utilities.UI;
2018-09-15 19:05:14 +00:00
using System;
using System.Diagnostics;
2018-09-15 19:05:14 +00:00
namespace RhythmBullet.Zer01HD.Game
{
class LoadingScreen : Screen
2018-09-15 19:05:14 +00:00
{
Texture2D texture;
Color color;
2018-10-31 00:47:01 +00:00
Rectangle rectangleBounds;
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)
2018-09-15 19:05:14 +00:00
{
color = Color.White;
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)
{
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();
2018-09-15 19:05:14 +00:00
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, rectangleBounds, color);
2018-09-15 19:05:14 +00:00
base.Draw(spriteBatch);
}
2018-09-15 19:05:14 +00:00
}
}