Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 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 Assignment_1_faces
  15. {
  16.  
  17. public class Game1 : Microsoft.Xna.Framework.Game
  18. {
  19. GraphicsDeviceManager graphics;
  20. SpriteBatch spriteBatch;
  21.  
  22. #region Game World
  23. Texture2D smileyFace;
  24. Texture2D normalFace;
  25. Texture2D sadFace;
  26. Texture2D normalFace2;
  27.  
  28. Rectangle faceY;
  29. Rectangle faceX;
  30. Rectangle faceB;
  31. Rectangle faceA;
  32.  
  33. Rectangle happyRect;
  34. Rectangle normalRect;
  35. Rectangle normal2Rect;
  36. Rectangle sadRect;
  37.  
  38.  
  39.  
  40. SpriteFont score;
  41. SpriteFont runCount;
  42. SpriteFont scoreNumber;
  43. SpriteFont runCountNumber;
  44.  
  45. int scorePoint = 0;
  46. int runPoint = 0;
  47. int startPos;
  48.  
  49. // SoundEffect point;
  50. // SoundEffect resetPoint;
  51. // SoundEffect gameOver;
  52.  
  53. GamePadState oldPad1;
  54.  
  55. Random rand = new Random();
  56.  
  57.  
  58. #endregion
  59.  
  60.  
  61.  
  62. public Game1()
  63. {
  64. graphics = new GraphicsDeviceManager(this);
  65. Content.RootDirectory = "Content";
  66. }
  67.  
  68. protected override void Initialize()
  69. {
  70. faceY = new Rectangle (350, 50, 100, 150);
  71. faceX = new Rectangle(100, 200, 100, 150);
  72. faceB = new Rectangle(600, 200, 100, 150);
  73. faceA = new Rectangle(350, 400, 100, 150);
  74. base.Initialize();
  75. }
  76.  
  77. protected override void LoadContent()
  78. {
  79.  
  80. spriteBatch = new SpriteBatch(GraphicsDevice);
  81.  
  82. score = this.Content.Load<SpriteFont>("score");
  83. scoreNumber = this.Content.Load<SpriteFont>("scoreNumber");
  84. runCount = this.Content.Load<SpriteFont>("runCount");
  85. runCountNumber = this.Content.Load<SpriteFont>("runCountNumber");
  86.  
  87.  
  88.  
  89. smileyFace = this.Content.Load<Texture2D>("hFace");
  90. normalFace = this.Content.Load<Texture2D>("nFace");
  91. normalFace2 = this.Content.Load<Texture2D>("nFace2");
  92. sadFace = this.Content.Load<Texture2D>("sFace");
  93.  
  94.  
  95. //point = this.Content.Load<SoundEffect>("ting");
  96. //resetPoint = this.Content.Load<SoundEffect>("snare");
  97. //gameOver = this.Content.Load<SoundEffect>("top");
  98.  
  99.  
  100.  
  101.  
  102.  
  103. }
  104.  
  105. protected override void UnloadContent()
  106. {
  107. }
  108.  
  109. protected override void Update(GameTime gameTime)
  110. {
  111. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  112. this.Exit();
  113.  
  114. /*GamePadState pad1 = GamePad.GetState(PlayerIndex.One);
  115. if (pad1.Buttons.Start == ButtonState.Released
  116. && oldPad1.Buttons.Start == ButtonState.Pressed)
  117. */
  118. startPos = rand.Next(1, 5);
  119. if (startPos == 1)
  120. {
  121.  
  122. happyRect = faceY;
  123. sadRect = faceX;
  124. normalRect = faceB;
  125. normal2Rect = faceA;
  126.  
  127. }
  128.  
  129.  
  130. if (startPos == 2)
  131. {
  132. happyRect = faceX;
  133. normalRect = faceB;
  134. normal2Rect = faceA;
  135. sadRect = faceY;
  136.  
  137. }
  138. if (startPos == 3)
  139. {
  140. happyRect = faceB;
  141. normalRect = faceA;
  142. normal2Rect = faceY;
  143. sadRect = faceX;
  144.  
  145. }
  146. if (startPos == 4)
  147. {
  148. happyRect = faceA;
  149. normalRect = faceY;
  150. normal2Rect = faceX;
  151. sadRect = faceB;
  152.  
  153. }
  154.  
  155. //oldPad1 = pad1;
  156.  
  157. base.Update(gameTime);
  158. }
  159.  
  160. protected override void Draw(GameTime gameTime)
  161. {
  162. GraphicsDevice.Clear(Color.YellowGreen);
  163.  
  164. Vector2 nowVector1 = new Vector2(15, 15);
  165. Vector2 nowVector2 = new Vector2(15, 50);
  166.  
  167.  
  168. spriteBatch.Begin();
  169. spriteBatch.DrawString(
  170. scoreNumber,
  171. scorePoint.ToString(),
  172. new Vector2(115, 15),
  173. Color.Red);
  174. spriteBatch.DrawString(
  175. runCountNumber,
  176. runPoint.ToString(),
  177. new Vector2(145, 50),
  178. Color.Blue);
  179.  
  180. spriteBatch.DrawString(score, "Score: ",
  181. nowVector1, Color.Red);
  182. spriteBatch.DrawString(runCount, "Run Count: ",
  183. nowVector2, Color.Blue);
  184.  
  185. spriteBatch.Draw(smileyFace, happyRect, Color.White);
  186. spriteBatch.Draw(normalFace, normalRect, Color.White);
  187. spriteBatch.Draw(normalFace, normal2Rect, Color.White);
  188. spriteBatch.Draw(sadFace, sadRect, Color.White);
  189. spriteBatch.End();
  190.  
  191. base.Draw(gameTime);
  192. }
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement