Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Net;
  12. using Microsoft.Xna.Framework.Storage;
  13.  
  14. namespace cutscene_tester2
  15. {
  16. /// <summary>
  17. /// This is the main type for your game
  18. /// </summary>
  19. public class Game1 : Microsoft.Xna.Framework.Game
  20. {
  21. GraphicsDeviceManager graphics;
  22. SpriteBatch spriteBatch;
  23. Rectangle textBox;
  24. Texture2D rose;
  25. SpriteFont font;
  26. String text, typedText;
  27. Double typedTextLength;
  28. int delayInMilliseconds;
  29. bool isDoneDrawing;
  30.  
  31. public Game1()
  32. {
  33. graphics = new GraphicsDeviceManager(this);
  34. Content.RootDirectory = "Content";
  35. }
  36.  
  37. /// <summary>
  38. /// Allows the game to perform any initialization it needs to before starting to run.
  39. /// This is where it can query for any required services and load any non-graphic
  40. /// related content. Calling base.Initialize will enumerate through any components
  41. /// and initialize them as well.
  42. /// </summary>
  43. protected override void Initialize()
  44. {
  45. // TODO: Add your initialization logic here
  46. textBox = new Rectangle(600, 0, 200, 200);
  47.  
  48. base.Initialize();
  49. }
  50.  
  51. /// <summary>
  52. /// LoadContent will be called once per game and is the place to load
  53. /// all of your content.
  54. /// </summary>
  55. protected override void LoadContent()
  56. {
  57. // Create a new SpriteBatch, which can be used to draw textures.
  58. spriteBatch = new SpriteBatch(GraphicsDevice);
  59. rose = Content.Load<Texture2D>("paper");
  60. font = Content.Load<SpriteFont>("SpriteFont1");
  61. text = "Yo wazzup";
  62.  
  63. delayInMilliseconds = 100;
  64. isDoneDrawing = false;
  65.  
  66. // TODO: use this.Content to load your game content here
  67. }
  68.  
  69. /// <summary>
  70. /// UnloadContent will be called once per game and is the place to unload
  71. /// all content.
  72. /// </summary>
  73. protected override void UnloadContent()
  74. {
  75. // TODO: Unload any non ContentManager content here
  76. }
  77.  
  78. /// <summary>
  79. /// checks to see if isDoneDrawing is set to true.
  80. /// If false, it then checks to see if the delay is at 0, dispalying all the text at once.
  81. /// otherwise, we check to see if ttl is less then the text length, meaning it wasn't fully pritned
  82. /// </summary>
  83. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  84. protected override void Update(GameTime gameTime)
  85. {
  86. // Allows the game to exit
  87. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  88. this.Exit();
  89. KeyboardState keyboardstate = Keyboard.GetState();
  90.  
  91. if (!isDoneDrawing)
  92. {
  93. if (delayInMilliseconds == 0)
  94. {
  95. typedText = text;
  96. isDoneDrawing = true;
  97.  
  98.  
  99. }
  100. else if (typedTextLength < text.Length)
  101. {
  102. typedTextLength = typedTextLength + gameTime.ElapsedGameTime.TotalMilliseconds / delayInMilliseconds;
  103.  
  104. if (typedTextLength >= text.Length)
  105. {
  106. typedTextLength = text.Length;
  107. isDoneDrawing = true;
  108.  
  109. }
  110.  
  111. typedText = text.Substring(0, (int)typedTextLength);
  112. }
  113. }
  114.  
  115. if (isDoneDrawing)
  116. {
  117. if (keyboardstate.IsKeyDown(Keys.A))
  118. {
  119.  
  120. text = "How you doin?";
  121. isDoneDrawing = false;
  122. }
  123.  
  124.  
  125. }
  126.  
  127. // TODO: Add your update logic here
  128.  
  129. base.Update(gameTime);
  130. }
  131.  
  132. /// <summary>
  133. /// This is called when the game should draw itself.
  134. /// </summary>
  135. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  136. protected override void Draw(GameTime gameTime)
  137. {
  138. GraphicsDevice.Clear(Color.CornflowerBlue);
  139. spriteBatch.Begin();
  140. spriteBatch.Draw(rose, textBox, Color.White);
  141.  
  142. spriteBatch.DrawString(font, typedText, new Vector2(textBox.X, textBox.Y), Color.White);
  143.  
  144. spriteBatch.End();
  145.  
  146. // TODO: Add your drawing code here
  147.  
  148. base.Draw(gameTime);
  149. }
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement