Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace Game
- {
- class IntroScreen : Scene
- {
- private SpriteBatch _spriteBatch;
- private Texture2D _backgroundScreen;
- private const String BackgroundName = "Backgrounds/IntroScreen";
- private double _startTime;
- private Color _color;
- private bool _started;
- public override void Draw(GameTime gameTime, GraphicsDevice graphicsDevice)
- {
- _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
- _spriteBatch.Draw(_backgroundScreen, new Vector2(0, 0), _color);
- _spriteBatch.End();
- }
- public override void Update(GameTime gameTime, ContentManager content, KeyboardState keyboardState, KeyboardState oldKeyboardState, GamePadState gamePadState, GamePadState oldGamePadState)
- {
- if (_started) {
- _startTime = gameTime.TotalGameTime.TotalMilliseconds;
- _started = false;
- }
- double deltaTime = gameTime.TotalGameTime.TotalMilliseconds - _startTime;
- if ((deltaTime >2000) && (deltaTime < 3000))
- Brighter(4);
- if ((keyboardState.IsKeyUp(Keys.Space)) && (oldKeyboardState.IsKeyDown(Keys.Space)) ||
- ((gamePadState.Buttons.A == ButtonState.Released) && (oldGamePadState.Buttons.A == ButtonState.Pressed)))
- {
- ForceExitLevelToMenu();
- }
- }
- public override void LoadContent(ContentManager content, GraphicsDevice graphicsDevice)
- {
- _spriteBatch = new SpriteBatch(graphicsDevice);
- _backgroundScreen = content.Load<Texture2D>(BackgroundName);
- _color = new Color(255,255,255,255);
- SetBrightness(0);
- _started = true;
- }
- private void SetBrightness(byte level)
- {
- _color.A = level;
- }
- private void Brighter(byte amount)
- {
- if ((_color.A + amount) < 255) _color.A += amount; else _color.A = 255;
- }
- private void Darker(byte amount)
- {
- if ((_color.A - amount) > 0) _color.A -= amount; else _color.A = 0;
- }
- public override void ForceExitLevelToMenu()
- {
- NextScene = SceneManager.Scenes.MAIN_MENU;
- ExitScene = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment