Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- namespace Collapse_Duty
- {
- public class GameplayScreen
- {
- GraphicsDeviceManager graphics;
- //GraphicsDevice device;
- Joueur objJoueurs;
- JoueurIA IA;
- Decors Background;
- Decors Foreground;
- Decors Background2;
- Physique objPhysique;
- Curseur Curs;
- Texture2D textureBalles;
- Texture2D[] textureJoueurCours = new Texture2D[2];
- Texture2D textureArmes;
- Texture2D[] textureExplosion = new Texture2D[27];
- Texture2D textureHUD;
- Texture2D fader;
- Texture2D texturePause;
- Texture2D texExploBlend;
- Texture2D texMEGABOOM;
- Texture2D pauseSelect;
- SpriteFont font;
- Texture2D texPartAk;
- Vector2 pausePos;
- int etatSelectPause = 0;
- //////////////////////////
- ////////DEBUT MODIF ULYSSE 10/02
- //////////////////////////
- Rectangle rectBackgroundVie;
- Rectangle rectVie;
- Texture2D texPixelBlanc;
- //////////////////////////
- ////////FIN MODIF ULYSSE 10/02
- //////////////////////////
- public static SoundEffect tir;
- public static Song musique;
- public static SoundEffect death;
- int numberOfPlayers = 3;
- int nbIA = 1;
- Color colorFader = Color.White;
- public int cptPause = 0;
- bool pause = false;
- public static int screenWidth = 1024;
- public static int screenHeight = 768;
- private float totalFPS = 0f, tempsTotal = 0f, displayFPS = 0f, fps = 0;
- public static Vector2 vecNorm = new Vector2(0, 0);
- public static Vector2 ovecNorm = new Vector2(0, 0);
- public static bool megaboom = false;
- KeyboardState prevKB, prevKB2;
- GamePadState prevGP;
- bool prevStartPressed = false;
- ContentManager Content;
- public GameplayScreen(ContentManager ContM, int n)
- {
- Content = ContM;
- numberOfPlayers = n;
- }
- public void nbJoueur(int n)
- {
- }
- public void Initialize(GraphicsDeviceManager graphics)
- {
- graphics.PreferredBackBufferWidth = screenWidth;
- graphics.PreferredBackBufferHeight = screenHeight;
- graphics.IsFullScreen = false;
- graphics.ApplyChanges();
- //Window.Title = "Collapse Duty - Soutenance 1 - Salle 311 - 14h30 - 06/01/11";
- objJoueurs = new Joueur(Content, texPartAk);
- if (numberOfPlayers == 1)
- IA = new JoueurIA(Content);
- colorFader.A = 0;
- Curs = new Curseur();
- Background = new Decors();
- Foreground = new Decors();
- Background2 = new Decors();
- objPhysique = new Physique();
- //Window.AllowUserResizing = true;
- }
- public void LoadContent()
- {
- //device = graphics.GraphicsDevice;
- Curs.textureCurs = Content.Load<Texture2D>("crosshair");
- Background.setup(Content.Load<Texture2D>("bgcity"));
- Foreground.setup(Content.Load<Texture2D>("fg_city"));
- Background2.setup(Content.Load<Texture2D>("bgnight"));
- for (int i = 0; i < textureJoueurCours.Length; i++)
- textureJoueurCours[i] = Content.Load<Texture2D>("soldat/joueur" + (i + 1));
- for (int i = 0; i < textureExplosion.Length; i++)
- textureExplosion[i] = Content.Load<Texture2D>("explosion/explosions_" + (i + 2));
- textureArmes = Content.Load<Texture2D>("gun");
- textureBalles = Content.Load<Texture2D>("bullet");
- fader = Content.Load<Texture2D>("fader");
- texPartAk = Content.Load<Texture2D>("partikule");
- pauseSelect = Content.Load<Texture2D>(@"Menu2\hoverpause");
- font = Content.Load<SpriteFont>("font");
- texturePause = Content.Load<Texture2D>(@"Menu2\pauseu");
- //texExploBlend = Content.Load<Texture2D>("exploBlend");
- texMEGABOOM = Content.Load<Texture2D>("megaboom");
- //////////////////////////
- ////////DEBUT MODIF ULYSSE 10/02
- //////////////////////////
- texPixelBlanc = Content.Load<Texture2D>("pixelBlanc");
- //////////////////////////
- ////////FIN MODIF ULYSSE 10/02
- //////////////////////////
- objJoueurs.SetUpPlayers(numberOfPlayers, textureJoueurCours);
- if (numberOfPlayers == 1)
- {
- IA.SetUpPlayers(nbIA, textureJoueurCours);
- }
- textureHUD = Content.Load<Texture2D>("HUD");
- //tir = Content.Load<SoundEffect>("AK47");
- //death = Content.Load<SoundEffect>("death");
- //musique = Content.Load<Song>("MusicBackground");
- //MediaPlayer.IsRepeating = true;
- //MediaPlayer.Volume = 10f;
- //MediaPlayer.Play(musique);
- }
- public void Update(GameTime gameTime)
- {
- checkPause();
- if (pause == false)
- {
- Curs.Update();
- objJoueurs.Update(Foreground, Foreground.colorDataForeground, textureHUD, gameTime);
- if (numberOfPlayers == 1)
- IA.Update(Foreground, Foreground.colorDataForeground, textureHUD, gameTime);
- calcFps(gameTime);
- Physique Phys = new Physique();
- }
- else
- {
- if(Keyboard.GetState().IsKeyDown(Keys.M))
- {
- Game1.isInGame = false;
- }
- if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Up))
- {
- etatSelectPause = (etatSelectPause - 1) % 2;
- }
- if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Down))
- {
- etatSelectPause = (etatSelectPause + 1) % 2;
- }
- if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Enter) && etatSelectPause == 0)
- {
- pause = false;
- }
- if (Keyboard.GetState() != prevKB2 && Keyboard.GetState().IsKeyDown(Keys.Enter) && etatSelectPause == 1)
- {
- Game1.isInGame = false;
- Foreground.resetDek();
- }
- prevKB2 = Keyboard.GetState();
- }
- }
- public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
- {
- Background2.Draw(spriteBatch, Joueur.posP1, 50, (Background2.tex.Width - 1024) / 2, (Background2.tex.Height - 768) / 2);
- Background.Draw(spriteBatch, Joueur.posP1, 20, (Background.tex.Width - 1024) / 2, (Background.tex.Height - 768) / 2);
- Foreground.Draw(spriteBatch);
- objJoueurs.DrawPlayers(spriteBatch, textureHUD);
- if (numberOfPlayers == 1)
- IA.DrawPlayers(spriteBatch, textureHUD);
- Curs.Draw(spriteBatch);
- //objGuns.Draw(spriteBatch);
- DebugDraw(spriteBatch);
- if (pause)
- {
- if(colorFader.A < 200)
- colorFader.A += 5;
- spriteBatch.Draw(fader, new Rectangle(0, 0, 1024, 768), colorFader);
- spriteBatch.Draw(texturePause, new Vector2(screenWidth / 2 - texturePause.Width / 2, screenHeight / 2 - texturePause.Height / 2), Color.White);
- cptPause++;
- if (etatSelectPause == 0)
- {
- spriteBatch.Draw(pauseSelect, new Vector2(360, 365), Color.White);
- }
- else
- {
- spriteBatch.Draw(pauseSelect, new Vector2(360, 415), Color.White);
- }
- }
- else
- {
- cptPause = 10;
- }
- }
- public void DebugDraw (SpriteBatch spriteBatch)
- {
- spriteBatch.DrawString(font,
- //"Nombre de balles (j1): " + objGuns.debuGun(0).ToString() +
- //"Nombre d'obus (j1): " + objCanon.debuGun(0).ToString()+
- "\nFPS: " + fps.ToString() +
- //"\nTemps Arme (j1): " + Arme.armes[0].tempsJeu +
- "\nVecNorm Balle1: (" + vecNorm.X + " || " + vecNorm.Y + ")" +
- "\noVecNorm Balle1: (" + ovecNorm.X + " || " + ovecNorm.Y + ")"
- , new Vector2(10, 10), Color.Black);
- /*spriteBatch.DrawString(font,
- "\nPosBalle :"
- , new Vector2(10, 50), Color.White);
- if(Balles.listeBalle.Count != 0)
- spriteBatch.DrawString(font,
- "\nPosBalle : x = " + Balles.listeBalle[0].Position.X + " y = " + Balles.listeBalle[0].Position.Y
- , new Vector2(10, 50), Color.White); */
- //////////////////////////
- ////////DEBUT MODIF ULYSSE 10/02
- //////////////////////////
- int pos = 200;
- for (int i = 0; i < Joueur.lifedisp.Length; i++)
- {
- //Le rectangle qui contient la vie
- rectBackgroundVie = new Rectangle((int)pos, 17, 100, 10);
- spriteBatch.Draw(texPixelBlanc, rectBackgroundVie, Color.White);
- //Le rectangle qui contient la vie restante
- rectVie = new Rectangle((int)pos, 17, Joueur.lifedisp[i], 10);
- spriteBatch.Draw(texPixelBlanc, rectVie, Color.Red);
- spriteBatch.DrawString(font, "Vie Joueur " + (i + 1) + ": " + Joueur.lifedisp[i], new Vector2(pos, 15), Color.Red);
- pos += 200;
- }
- //////////////////////////
- ////////FIN MODIF ULYSSE 10/02
- //////////////////////////
- }
- public void checkPause()
- {
- KeyboardState kb = Keyboard.GetState();
- GamePadState gp = GamePad.GetState(PlayerIndex.One);
- bool StartPressed = gp.Buttons.Start == ButtonState.Pressed;
- if ((kb.IsKeyDown(Keys.P) && kb != prevKB) || (gp.IsButtonDown(Buttons.Start) && gp != prevGP) && prevStartPressed != StartPressed)
- {
- pause = !pause;
- }
- //if (kb != prevKB && kb.IsKeyDown(Keys.Enter) && etatSelectPause == 0)
- //{
- // pause = false;
- //}
- //if (kb != prevKB && kb.IsKeyDown(Keys.Enter) && etatSelectPause == 1)
- //{
- // pause = false;
- // Game1.isInGame = false;
- //}
- //if ((kb.IsKeyDown(Keys.Enter)) && pause && kb != prevKB)
- // Game1.isInGame = false;
- prevKB = kb;
- prevGP = gp;
- prevStartPressed = StartPressed;
- }
- public void calcFps(GameTime GT)
- {
- float ElapsedTime = (float)GT.ElapsedRealTime.TotalSeconds;
- tempsTotal += ElapsedTime;
- if (tempsTotal >= 1)
- {
- displayFPS = totalFPS;
- totalFPS = 0;
- tempsTotal = 0;
- }
- totalFPS += 1;
- fps = displayFPS;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement