InstructionsScreen.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //-----------------------------------------------------------------------------
  2. // BackgroundScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. // using System.Threading;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Input.Touch;
  15. using Microsoft.Xna.Framework.Input;
  16. namespace CatapultGame
  17. {
  18. class InstructionsScreen : GameScreen
  19. {
  20. Texture2D background;
  21. SpriteFont font;
  22. // Background threaded loading removed; we load on the main thread.
  23. public InstructionsScreen ()
  24. {
  25. EnabledGestures = GestureType.Tap;
  26. TransitionOnTime = TimeSpan.FromSeconds (0);
  27. TransitionOffTime = TimeSpan.FromSeconds (0.5);
  28. }
  29. public override void LoadContent ()
  30. {
  31. background = Load<Texture2D> ("Textures/Backgrounds/instructions");
  32. font = Load<SpriteFont> ("Fonts/MenuFont");
  33. }
  34. public override void Update (GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
  35. {
  36. base.Update (gameTime, otherScreenHasFocus, coveredByOtherScreen);
  37. }
  38. public override void HandleInput (InputState input)
  39. {
  40. PlayerIndex player;
  41. if (input.IsNewKeyPress (Keys.Space, ControllingPlayer, out player) ||
  42. input.IsNewKeyPress (Keys.Enter, ControllingPlayer, out player) ||
  43. input.MouseGesture.HasFlag(MouseGestureType.LeftClick) ||
  44. input.IsNewButtonPress (Buttons.Start, ControllingPlayer, out player)) {
  45. // Start gameplay immediately on the main thread
  46. ExitScreen();
  47. ScreenManager.AddScreen(new GameplayScreen(), null);
  48. }
  49. foreach (var gesture in input.Gestures) {
  50. if (gesture.GestureType == GestureType.Tap) {
  51. ExitScreen();
  52. ScreenManager.AddScreen(new GameplayScreen(), null);
  53. }
  54. }
  55. base.HandleInput (input);
  56. }
  57. public override void Draw (GameTime gameTime)
  58. {
  59. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  60. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  61. // Draw Background
  62. spriteBatch.Draw (background, new Vector2 (0, 0),
  63. new Color (255, 255, 255, TransitionAlpha));
  64. spriteBatch.End ();
  65. }
  66. }
  67. }