Guest User

Untitled

a guest
Nov 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Framework.Input;
  6.  
  7. namespace Game
  8. {
  9.     class IntroScreen : Scene
  10.     {
  11.         private SpriteBatch _spriteBatch;
  12.         private Texture2D _backgroundScreen;
  13.         private const String BackgroundName = "Backgrounds/IntroScreen";
  14.         private double _startTime;
  15.         private Color _color;
  16.         private bool _started;
  17.  
  18.         public override void Draw(GameTime gameTime, GraphicsDevice graphicsDevice)
  19.         {
  20.             _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
  21.             _spriteBatch.Draw(_backgroundScreen, new Vector2(0, 0), _color);
  22.             _spriteBatch.End();
  23.         }
  24.  
  25.         public override void Update(GameTime gameTime, ContentManager content, KeyboardState keyboardState, KeyboardState oldKeyboardState, GamePadState gamePadState, GamePadState oldGamePadState)
  26.         {
  27.  
  28.             if (_started) {
  29.                 _startTime = gameTime.TotalGameTime.TotalMilliseconds;
  30.                 _started = false;
  31.             }
  32.  
  33.             double deltaTime = gameTime.TotalGameTime.TotalMilliseconds - _startTime;
  34.  
  35.             if ((deltaTime >2000) && (deltaTime < 3000))
  36.                 Brighter(4);
  37.  
  38.             if ((keyboardState.IsKeyUp(Keys.Space)) && (oldKeyboardState.IsKeyDown(Keys.Space)) ||
  39.             ((gamePadState.Buttons.A == ButtonState.Released) && (oldGamePadState.Buttons.A == ButtonState.Pressed)))
  40.             {
  41.                 ForceExitLevelToMenu();
  42.             }
  43.  
  44.         }
  45.  
  46.         public override void LoadContent(ContentManager content, GraphicsDevice graphicsDevice)
  47.         {
  48.             _spriteBatch = new SpriteBatch(graphicsDevice);
  49.             _backgroundScreen = content.Load<Texture2D>(BackgroundName);
  50.             _color = new Color(255,255,255,255);
  51.             SetBrightness(0);
  52.             _started = true;
  53.            
  54.         }
  55.  
  56.         private void SetBrightness(byte level)
  57.         {
  58.             _color.A = level;
  59.         }
  60.  
  61.         private void Brighter(byte amount)
  62.         {
  63.             if ((_color.A + amount) < 255) _color.A += amount; else _color.A = 255;
  64.         }
  65.  
  66.         private void Darker(byte amount)
  67.         {
  68.             if ((_color.A - amount) > 0) _color.A -= amount; else _color.A = 0;
  69.         }
  70.  
  71.         public override void ForceExitLevelToMenu()
  72.         {
  73.             NextScene = SceneManager.Scenes.MAIN_MENU;
  74.             ExitScene = true;
  75.         }
  76.     }
  77. }
Add Comment
Please, Sign In to add comment