PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/2Stick Shooter with External Editor/Repository/Cosmic_Guardian/CosmicGuardian/CosmicGuardian/CosmicGuardian/OptionsMenu.cs

https://bitbucket.org/IVmost/portfolio
C# | 259 lines | 232 code | 23 blank | 4 comment | 65 complexity | 3d83c71b88cf3515b4a1bfc2e5ed5fb2 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Audio;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.GamerServices;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using Microsoft.Xna.Framework.Input;
  11. using Microsoft.Xna.Framework.Media;
  12. namespace CosmicGuardian
  13. {
  14. //Options menu class
  15. class OptionsMenu
  16. {
  17. SpriteFont font1, font2;
  18. SpriteBatch spriteBatch;
  19. private int screenHeight, screenWidth;
  20. private Texture2D background, dpad, aButton, bButton, blueButton, greyButton, controlsImage;
  21. private Boolean howToActivated, exitActivated, musicActivated, soundActivated, navLatch, selectLatch, exitPressed, showControls;
  22. private SoundEffect navSound;
  23. public Boolean playMusic, playSoundEffects;
  24. private String musicString, soundEffectsString;
  25. //Options menu constructor
  26. public OptionsMenu(Texture2D back, Texture2D d, Texture2D a, Texture2D b, Texture2D blue, Texture2D grey, Texture2D c, int height, int width, SpriteBatch batch, SpriteFont f1, SpriteFont f2, SoundEffect s)
  27. {
  28. background = back;
  29. dpad = d;
  30. aButton = a;
  31. bButton = b;
  32. screenHeight = height;
  33. screenWidth = width;
  34. spriteBatch = batch;
  35. font1 = f1;
  36. font2 = f2;
  37. blueButton = blue;
  38. greyButton = grey;
  39. controlsImage = c;
  40. howToActivated = true;
  41. exitActivated = false;
  42. navLatch = false;
  43. selectLatch = false;
  44. exitPressed = false;
  45. showControls = false;
  46. playMusic = true;
  47. playSoundEffects = true;
  48. musicString = "Music: ON";
  49. soundEffectsString = "Sound FX: ON";
  50. navSound = s;
  51. }
  52. //Update options menu
  53. public virtual void Update(GameTime gameTime, MainMenu m)
  54. {
  55. inputStruct i = InputDriver.PollGamePadInput(PlayerIndex.One);
  56. if (!showControls)
  57. {
  58. if (howToActivated)
  59. {
  60. if (i.menuNavigate.Down == ButtonState.Pressed && !navLatch)
  61. {
  62. howToActivated = false;
  63. musicActivated = true;
  64. navLatch = true;
  65. if (playSoundEffects)
  66. navSound.Play();
  67. }
  68. if (i.menuNavigate.Up == ButtonState.Pressed && !navLatch)
  69. {
  70. howToActivated = false;
  71. exitActivated = true;
  72. navLatch = true;
  73. if (playSoundEffects)
  74. navSound.Play();
  75. }
  76. }
  77. else if (musicActivated)
  78. {
  79. if (i.menuNavigate.Down == ButtonState.Pressed && !navLatch)
  80. {
  81. musicActivated = false;
  82. soundActivated = true;
  83. navLatch = true;
  84. if (playSoundEffects)
  85. navSound.Play();
  86. }
  87. if (i.menuNavigate.Up == ButtonState.Pressed && !navLatch)
  88. {
  89. musicActivated = false;
  90. howToActivated = true;
  91. navLatch = true;
  92. if (playSoundEffects)
  93. navSound.Play();
  94. }
  95. }
  96. else if (soundActivated)
  97. {
  98. if (i.menuNavigate.Down == ButtonState.Pressed && !navLatch)
  99. {
  100. soundActivated = false;
  101. exitActivated = true;
  102. navLatch = true;
  103. if (playSoundEffects)
  104. navSound.Play();
  105. }
  106. if (i.menuNavigate.Up == ButtonState.Pressed && !navLatch)
  107. {
  108. soundActivated = false;
  109. musicActivated = true;
  110. navLatch = true;
  111. if (playSoundEffects)
  112. navSound.Play();
  113. }
  114. }
  115. else if (exitActivated)
  116. {
  117. if (i.menuNavigate.Down == ButtonState.Pressed && !navLatch)
  118. {
  119. howToActivated = true;
  120. exitActivated = false;
  121. navLatch = true;
  122. if (playSoundEffects)
  123. navSound.Play();
  124. }
  125. if (i.menuNavigate.Up == ButtonState.Pressed && !navLatch)
  126. {
  127. soundActivated = true;
  128. exitActivated = false;
  129. navLatch = true;
  130. if (playSoundEffects)
  131. navSound.Play();
  132. }
  133. }
  134. if (exitActivated)
  135. {
  136. if (i.enterButton)
  137. {
  138. exitPressed = true;
  139. }
  140. if (!i.enterButton && exitPressed)
  141. {
  142. m.displayOptionsMenu = false;
  143. m.displayMainMenu = true;
  144. howToActivated = true;
  145. exitActivated = false;
  146. exitPressed = false;
  147. }
  148. }
  149. if (howToActivated)
  150. {
  151. if (i.enterButton)
  152. {
  153. showControls = true;
  154. }
  155. }
  156. if (musicActivated)
  157. {
  158. if (i.enterButton && !selectLatch)
  159. {
  160. playMusic = !playMusic;
  161. selectLatch = true;
  162. }
  163. }
  164. if (soundActivated)
  165. {
  166. if (i.enterButton && !selectLatch)
  167. {
  168. playSoundEffects = !playSoundEffects;
  169. m.playSounds = playSoundEffects;
  170. selectLatch = true;
  171. }
  172. }
  173. if (!i.enterButton)
  174. selectLatch = false;
  175. if ((i.menuNavigate.Down == ButtonState.Released) && (i.menuNavigate.Up == ButtonState.Released))
  176. {
  177. navLatch = false;
  178. }
  179. }
  180. else
  181. {
  182. if (i.cancelButton)
  183. showControls = false;
  184. }
  185. if (playMusic)
  186. musicString = "Music: ON";
  187. else
  188. musicString = "Music: OFF";
  189. if (playSoundEffects)
  190. soundEffectsString = "Sound FX: ON";
  191. else
  192. soundEffectsString = "Sound FX: OFF";
  193. }
  194. //Draw options menu
  195. public virtual void Draw(GameTime gameTime)
  196. {
  197. spriteBatch.Draw(background, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  198. spriteBatch.DrawString(font1, "Select", new Vector2(80, screenHeight - 57 * Defines.Screen_height_Scaler), Color.White);
  199. spriteBatch.DrawString(font1, "Navigate", new Vector2(80, screenHeight - 135 * Defines.Screen_height_Scaler), Color.White);
  200. spriteBatch.Draw(aButton, new Vector2(5, screenHeight - 75 * Defines.Screen_height_Scaler), Color.White);
  201. spriteBatch.Draw(dpad, new Vector2(5, screenHeight - 150 * Defines.Screen_height_Scaler), new Rectangle(0, 0, dpad.Width, dpad.Height), Color.White, 0.0f, new Vector2(0, 0), 0.1f, SpriteEffects.None, 0);
  202. if (showControls)
  203. {
  204. Vector2 temp = new Vector2(screenWidth / 2 - controlsImage.Width / 2, screenHeight / 2 - controlsImage.Height / 2);
  205. spriteBatch.Draw(controlsImage, temp, Color.White);
  206. spriteBatch.Draw(bButton, new Vector2(temp.X, temp.Y - bButton.Height), Color.White);
  207. spriteBatch.DrawString(font1, "Back", new Vector2(temp.X + bButton.Width, temp.Y - 45), Color.White);
  208. }
  209. else
  210. {
  211. spriteBatch.DrawString(font2, "OPTIONS", new Vector2(430 * Defines.Screen_Width_Scaler, 100*Defines.Screen_height_Scaler), Color.White);
  212. if (howToActivated)
  213. spriteBatch.Draw(blueButton, new Vector2(430 * Defines.Screen_Width_Scaler, 180 * Defines.Screen_height_Scaler), Color.White);
  214. else
  215. spriteBatch.Draw(greyButton, new Vector2(430 * Defines.Screen_Width_Scaler, 180 * Defines.Screen_height_Scaler), Color.White);
  216. if (musicActivated)
  217. spriteBatch.Draw(blueButton, new Vector2(430 * Defines.Screen_Width_Scaler, blueButton.Height + 210 * Defines.Screen_height_Scaler), Color.White);
  218. else
  219. spriteBatch.Draw(greyButton, new Vector2(430 * Defines.Screen_Width_Scaler, blueButton.Height + 210 * Defines.Screen_height_Scaler), Color.White);
  220. if (soundActivated)
  221. spriteBatch.Draw(blueButton, new Vector2(430 * Defines.Screen_Width_Scaler, blueButton.Height * 2 + 240 * Defines.Screen_height_Scaler), Color.White);
  222. else
  223. spriteBatch.Draw(greyButton, new Vector2(430 * Defines.Screen_Width_Scaler, blueButton.Height * 2 + 240 * Defines.Screen_height_Scaler), Color.White);
  224. if (exitActivated)
  225. spriteBatch.Draw(blueButton, new Vector2(430 * Defines.Screen_Width_Scaler, blueButton.Height * 3 + 270 * Defines.Screen_height_Scaler), Color.White);
  226. else
  227. spriteBatch.Draw(greyButton, new Vector2(430 * Defines.Screen_Width_Scaler, blueButton.Height * 3 + 270 * Defines.Screen_height_Scaler), Color.White);
  228. spriteBatch.DrawString(font1, "Control", new Vector2(blueButton.Width + 440 * Defines.Screen_Width_Scaler, 155 * Defines.Screen_height_Scaler + blueButton.Height / 2), Color.White);
  229. spriteBatch.DrawString(font1, "Layout", new Vector2(blueButton.Width + 440 * Defines.Screen_Width_Scaler, 175 * Defines.Screen_height_Scaler + blueButton.Height / 2), Color.White);
  230. spriteBatch.DrawString(font1, musicString, new Vector2(blueButton.Width + 440 * Defines.Screen_Width_Scaler, blueButton.Height * 1.5f + 200 * Defines.Screen_height_Scaler), Color.White);
  231. spriteBatch.DrawString(font1, soundEffectsString, new Vector2(blueButton.Width + 440 * Defines.Screen_Width_Scaler, blueButton.Height * 2.5f + 225 * Defines.Screen_height_Scaler), Color.White);
  232. spriteBatch.DrawString(font1, "Exit", new Vector2(blueButton.Width + 440 * Defines.Screen_Width_Scaler, blueButton.Height * 3.5f + 255 * Defines.Screen_height_Scaler), Color.White);
  233. }
  234. }
  235. }
  236. }