Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.88 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 Collapse_Duty
  15. {
  16.  
  17.  
  18. public class GameplayScreen
  19. {
  20. GraphicsDeviceManager graphics;
  21. //GraphicsDevice device;
  22. Joueur objJoueurs;
  23. JoueurIA IA;
  24. Decors Background;
  25. Decors Foreground;
  26. Decors Background2;
  27. Physique objPhysique;
  28. Curseur Curs;
  29. Texture2D textureBalles;
  30. Texture2D[] textureJoueurCours = new Texture2D[2];
  31. Texture2D textureArmes;
  32. Texture2D[] textureExplosion = new Texture2D[27];
  33. Texture2D textureHUD;
  34. Texture2D fader;
  35. Texture2D texturePause;
  36. Texture2D texExploBlend;
  37. Texture2D texMEGABOOM;
  38. Texture2D pauseSelect;
  39. SpriteFont font;
  40. Texture2D texPartAk;
  41. Vector2 pausePos;
  42. int etatSelectPause = 0;
  43.  
  44.  
  45. //////////////////////////
  46. ////////DEBUT MODIF ULYSSE 10/02
  47. //////////////////////////
  48. Rectangle rectBackgroundVie;
  49. Rectangle rectVie;
  50. Texture2D texPixelBlanc;
  51. //////////////////////////
  52. ////////FIN MODIF ULYSSE 10/02
  53. //////////////////////////
  54.  
  55. public static SoundEffect tir;
  56. public static Song musique;
  57. public static SoundEffect death;
  58.  
  59.  
  60. int numberOfPlayers = 3;
  61. int nbIA = 1;
  62. Color colorFader = Color.White;
  63. public int cptPause = 0;
  64. bool pause = false;
  65. public static int screenWidth = 1024;
  66. public static int screenHeight = 768;
  67. private float totalFPS = 0f, tempsTotal = 0f, displayFPS = 0f, fps = 0;
  68. public static Vector2 vecNorm = new Vector2(0, 0);
  69. public static Vector2 ovecNorm = new Vector2(0, 0);
  70. public static bool megaboom = false;
  71. KeyboardState prevKB, prevKB2;
  72. GamePadState prevGP;
  73. bool prevStartPressed = false;
  74.  
  75. ContentManager Content;
  76.  
  77. public GameplayScreen(ContentManager ContM, int n)
  78. {
  79. Content = ContM;
  80. numberOfPlayers = n;
  81. }
  82. public void nbJoueur(int n)
  83. {
  84.  
  85. }
  86. public void Initialize(GraphicsDeviceManager graphics)
  87. {
  88. graphics.PreferredBackBufferWidth = screenWidth;
  89. graphics.PreferredBackBufferHeight = screenHeight;
  90. graphics.IsFullScreen = false;
  91. graphics.ApplyChanges();
  92. //Window.Title = "Collapse Duty - Soutenance 1 - Salle 311 - 14h30 - 06/01/11";
  93. objJoueurs = new Joueur(Content, texPartAk);
  94. if (numberOfPlayers == 1)
  95. IA = new JoueurIA(Content);
  96. colorFader.A = 0;
  97. Curs = new Curseur();
  98. Background = new Decors();
  99. Foreground = new Decors();
  100. Background2 = new Decors();
  101. objPhysique = new Physique();
  102.  
  103. //Window.AllowUserResizing = true;
  104. }
  105.  
  106. public void LoadContent()
  107. {
  108. //device = graphics.GraphicsDevice;
  109.  
  110. Curs.textureCurs = Content.Load<Texture2D>("crosshair");
  111. Background.setup(Content.Load<Texture2D>("bgcity"));
  112. Foreground.setup(Content.Load<Texture2D>("fg_city"));
  113. Background2.setup(Content.Load<Texture2D>("bgnight"));
  114. for (int i = 0; i < textureJoueurCours.Length; i++)
  115. textureJoueurCours[i] = Content.Load<Texture2D>("soldat/joueur" + (i + 1));
  116. for (int i = 0; i < textureExplosion.Length; i++)
  117. textureExplosion[i] = Content.Load<Texture2D>("explosion/explosions_" + (i + 2));
  118. textureArmes = Content.Load<Texture2D>("gun");
  119. textureBalles = Content.Load<Texture2D>("bullet");
  120. fader = Content.Load<Texture2D>("fader");
  121. texPartAk = Content.Load<Texture2D>("partikule");
  122. pauseSelect = Content.Load<Texture2D>(@"Menu2\hoverpause");
  123. font = Content.Load<SpriteFont>("font");
  124. texturePause = Content.Load<Texture2D>(@"Menu2\pauseu");
  125. //texExploBlend = Content.Load<Texture2D>("exploBlend");
  126. texMEGABOOM = Content.Load<Texture2D>("megaboom");
  127. //////////////////////////
  128. ////////DEBUT MODIF ULYSSE 10/02
  129. //////////////////////////
  130. texPixelBlanc = Content.Load<Texture2D>("pixelBlanc");
  131. //////////////////////////
  132. ////////FIN MODIF ULYSSE 10/02
  133. //////////////////////////
  134. objJoueurs.SetUpPlayers(numberOfPlayers, textureJoueurCours);
  135. if (numberOfPlayers == 1)
  136. {
  137. IA.SetUpPlayers(nbIA, textureJoueurCours);
  138. }
  139. textureHUD = Content.Load<Texture2D>("HUD");
  140.  
  141. //tir = Content.Load<SoundEffect>("AK47");
  142. //death = Content.Load<SoundEffect>("death");
  143. //musique = Content.Load<Song>("MusicBackground");
  144. //MediaPlayer.IsRepeating = true;
  145. //MediaPlayer.Volume = 10f;
  146. //MediaPlayer.Play(musique);
  147.  
  148.  
  149. }
  150.  
  151.  
  152. public void Update(GameTime gameTime)
  153. {
  154.  
  155. checkPause();
  156. if (pause == false)
  157. {
  158. Curs.Update();
  159. objJoueurs.Update(Foreground, Foreground.colorDataForeground, textureHUD, gameTime);
  160. if (numberOfPlayers == 1)
  161. IA.Update(Foreground, Foreground.colorDataForeground, textureHUD, gameTime);
  162. calcFps(gameTime);
  163. Physique Phys = new Physique();
  164. }
  165. else
  166. {
  167. if(Keyboard.GetState().IsKeyDown(Keys.M))
  168. {
  169. Game1.isInGame = false;
  170. }
  171. if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Up))
  172. {
  173. etatSelectPause = (etatSelectPause - 1) % 2;
  174. }
  175. if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Down))
  176. {
  177. etatSelectPause = (etatSelectPause + 1) % 2;
  178. }
  179. if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Enter) && etatSelectPause == 0)
  180. {
  181. pause = false;
  182.  
  183. }
  184. if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Enter) && etatSelectPause == 1)
  185. {
  186. Game1.isInGame = false;
  187. Foreground.resetDek();
  188. }
  189. prevKB2 = Keyboard.GetState();
  190. }
  191.  
  192.  
  193. }
  194.  
  195. public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
  196. {
  197.  
  198.  
  199. Background2.Draw(spriteBatch, Joueur.posP1, 50, (Background2.tex.Width - 1024) / 2, (Background2.tex.Height - 768) / 2);
  200. Background.Draw(spriteBatch, Joueur.posP1, 20, (Background.tex.Width - 1024) / 2, (Background.tex.Height - 768) / 2);
  201. Foreground.Draw(spriteBatch);
  202. objJoueurs.DrawPlayers(spriteBatch, textureHUD);
  203. if (numberOfPlayers == 1)
  204. IA.DrawPlayers(spriteBatch, textureHUD);
  205. Curs.Draw(spriteBatch);
  206. //objGuns.Draw(spriteBatch);
  207. DebugDraw(spriteBatch);
  208. if (pause)
  209. {
  210. if(colorFader.A < 200)
  211. colorFader.A += 5;
  212. spriteBatch.Draw(fader, new Rectangle(0, 0, 1024, 768), colorFader);
  213. spriteBatch.Draw(texturePause, new Vector2(screenWidth / 2 - texturePause.Width / 2, screenHeight / 2 - texturePause.Height / 2), Color.White);
  214. cptPause++;
  215. if (etatSelectPause == 0)
  216. {
  217. spriteBatch.Draw(pauseSelect, new Vector2(360, 365), Color.White);
  218. }
  219. else
  220. {
  221.  
  222. spriteBatch.Draw(pauseSelect, new Vector2(360, 415), Color.White);
  223.  
  224. }
  225. }
  226. else
  227. {
  228. cptPause = 10;
  229. }
  230.  
  231.  
  232.  
  233.  
  234. }
  235.  
  236. public void DebugDraw (SpriteBatch spriteBatch)
  237. {
  238. spriteBatch.DrawString(font,
  239. //"Nombre de balles (j1): " + objGuns.debuGun(0).ToString() +
  240. //"Nombre d'obus (j1): " + objCanon.debuGun(0).ToString()+
  241. "\nFPS: " + fps.ToString() +
  242. //"\nTemps Arme (j1): " + Arme.armes[0].tempsJeu +
  243. "\nVecNorm Balle1: (" + vecNorm.X + " || " + vecNorm.Y + ")" +
  244. "\noVecNorm Balle1: (" + ovecNorm.X + " || " + ovecNorm.Y + ")"
  245. , new Vector2(10, 10), Color.Black);
  246. /*spriteBatch.DrawString(font,
  247. "\nPosBalle :"
  248. , new Vector2(10, 50), Color.White);
  249. if(Balles.listeBalle.Count != 0)
  250. spriteBatch.DrawString(font,
  251. "\nPosBalle : x = " + Balles.listeBalle[0].Position.X + " y = " + Balles.listeBalle[0].Position.Y
  252. , new Vector2(10, 50), Color.White); */
  253.  
  254. //////////////////////////
  255. ////////DEBUT MODIF ULYSSE 10/02
  256. //////////////////////////
  257. int pos = 200;
  258. for (int i = 0; i < Joueur.lifedisp.Length; i++)
  259. {
  260. //Le rectangle qui contient la vie
  261. rectBackgroundVie = new Rectangle((int)pos, 17, 100, 10);
  262. spriteBatch.Draw(texPixelBlanc, rectBackgroundVie, Color.White);
  263.  
  264. //Le rectangle qui contient la vie restante
  265. rectVie = new Rectangle((int)pos, 17, Joueur.lifedisp[i], 10);
  266. spriteBatch.Draw(texPixelBlanc, rectVie, Color.Red);
  267.  
  268.  
  269. spriteBatch.DrawString(font, "Vie Joueur " + (i + 1) + ": " + Joueur.lifedisp[i], new Vector2(pos, 15), Color.Red);
  270. pos += 200;
  271. }
  272.  
  273. //////////////////////////
  274. ////////FIN MODIF ULYSSE 10/02
  275. //////////////////////////
  276.  
  277. }
  278.  
  279. public void checkPause()
  280. {
  281. KeyboardState kb = Keyboard.GetState();
  282. GamePadState gp = GamePad.GetState(PlayerIndex.One);
  283.  
  284.  
  285. bool StartPressed = gp.Buttons.Start == ButtonState.Pressed;
  286.  
  287. if ((kb.IsKeyDown(Keys.P) && kb != prevKB) || (gp.IsButtonDown(Buttons.Start) && gp != prevGP) && prevStartPressed != StartPressed)
  288. {
  289. pause = !pause;
  290. }
  291. //if (kb != prevKB && kb.IsKeyDown(Keys.Enter) && etatSelectPause == 0)
  292. //{
  293. // pause = false;
  294. //}
  295. //if (kb != prevKB && kb.IsKeyDown(Keys.Enter) && etatSelectPause == 1)
  296. //{
  297. // pause = false;
  298. // Game1.isInGame = false;
  299. //}
  300.  
  301. //if ((kb.IsKeyDown(Keys.Enter)) && pause && kb != prevKB)
  302. // Game1.isInGame = false;
  303.  
  304. prevKB = kb;
  305. prevGP = gp;
  306. prevStartPressed = StartPressed;
  307. }
  308.  
  309. public void calcFps(GameTime GT)
  310. {
  311.  
  312. float ElapsedTime = (float)GT.ElapsedRealTime.TotalSeconds;
  313. tempsTotal += ElapsedTime;
  314. if (tempsTotal >= 1)
  315. {
  316. displayFPS = totalFPS;
  317. totalFPS = 0;
  318. tempsTotal = 0;
  319. }
  320. totalFPS += 1;
  321. fps = displayFPS;
  322.  
  323. }
  324.  
  325. }
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement