/// <summary> /// On charge nos variables /// </summary> public void LoadContent() { this.menuManager.LoadContent(); this.menuManager.MenuCourant = this.menuManager.TrouverMenu("MainMenu"); // Créer un nouveau SpriteBatch, utilisée pour dessiner les textures. this.spriteBatch = new SpriteBatch(this.graphics.GraphicsDevice); // Charger les sprites. JoueurSprite.LoadContent(this.GetContent(), this.graphics); ArrierePlanEspace.LoadContent(this.GetContent(), this.graphics); Obus.LoadContent(this.GetContent(), this.graphics); EnnemiShip.LoadContent(this.GetContent(), this.graphics); EnnemiSpinner.LoadContent(this.GetContent(), this.graphics); PowerUp_Fire_Shot.LoadContent(this.GetContent(), this.graphics); PowerUp_Energy_Ball.LoadContent(this.GetContent(), this.graphics); PowerUp_One_Projectile.LoadContent(this.GetContent(), this.graphics); PowerUp_Three_Projectile.LoadContent(this.GetContent(), this.graphics); PowerUp_Two_Projectile.LoadContent(this.GetContent(), this.graphics); this.policePetit = this.GetContent().Load <SpriteFont>(@"Pipeline/Polices/PoliceItem"); this.policeGrand = this.GetContent().Load <SpriteFont>(@"Pipeline/Polices/PoliceTitre"); // Créer les sprites du jeu. Premièrement le sprite du joueur centrer au bas de l'écran. On limite ensuite // ses déplacements à l'écran. this.vaisseauJoueur = new JoueurSprite(this.graphics.GraphicsDevice.Viewport.Width / 8f, this.graphics.GraphicsDevice.Viewport.Height / 2f); this.vaisseauJoueur.BoundsRect = new Rectangle(0, 0, this.graphics.GraphicsDevice.Viewport.Width, this.graphics.GraphicsDevice.Viewport.Height); this.vaisseauJoueur.ShootObus += Shoot; this.vaisseauJoueur.NbVies = 3; this.bruitageRamasser = this.GetContent().Load <SoundEffect>(@"Pipeline\SoundFX\pickup"); // Créer ensuite les sprites représentant les arrière-plans. this.arrierePlanEspace = new ArrierePlanEspace(this.graphics); // Charger le bruitage de fond du jeu. this.bruitageFond = this.GetContent().Load <Song>(@"Pipeline\Songs\scifi072"); this.mainmenuImage = this.GetContent().Load <Texture2D>(@"ArrieresPlans\mainmenu.jpg"); // Charger les textures associées aux effets visuels gérées par Game. this.particulesExplosions = this.GetContent().Load <Texture2D>(@"Explosion\explosionAsteroides"); bruitageExplosion = this.GetContent().Load <SoundEffect>(@"Pipeline\SoundFX\explosion001"); // Paramétrer la musique de fond et la démarrer. MediaPlayer.Volume = 0.05f; // pour mieux entendre les autres effets sonores MediaPlayer.IsRepeating = true; MediaPlayer.Play(bruitageFond); MediaPlayer.Pause(); }
/// <summary> /// Boucle de jeu /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime) { if (vaisseauJoueur != null && vaisseauJoueur.NbVies < 1) { etatJeu = Etats.Pause; this.SuspendreEffetsSonores(true); this.ClearLists(); this.vaisseauJoueur = null; jeuFini = true; } if (fading) { _faderAlpha += _faderAlphaIncrement; // Lighting things back! if (_faderAlpha >= 255) { switchScenes = true; _faderAlphaIncrement = -_faderAlphaIncrement; } else if (_faderAlpha <= 0) { fading = false; } } if (this.EtatJeu == Etats.Demarrer) { if (!fading) { this.menuManager.MenuCourant.GetInput(gameTime); } else { if (switchScenes) { this.EtatJeu = etatJeuProchain; if (EtatJeu == Etats.Info) { menuManager.MenuCourant = menuManager.TrouverMenu("Information"); } } } } else if (this.EtatJeu == Etats.Info) { if (!fading) { if (switchScenes) { switchScenes = false; } this.menuManager.MenuCourant.GetInput(gameTime); } else { if (switchScenes && this.etatJeuProchain == Etats.Demarrer) { switchScenes = false; this.EtatJeu = etatJeuProchain; menuManager.MenuCourant = menuManager.TrouverMenu("MainMenu"); } } } else if (this.EtatJeu == Etats.Jouer || this.EtatJeu == Etats.Pause) { if (!fading) { if (switchScenes) { switchScenes = false; menuManager.MenuCourant = null; SuspendreEffetsSonores(false); } // Permettre de quitter le jeu via le service d'input. if (ServiceHelper.Get <IInputService>().Quitter(1)) { this.Initialize(); this.LoadContent(); return; } // Est-ce que le bouton de pause a été pressé? if (ServiceHelper.Get <IInputService>().Pause(1)) { this.Pause = !Pause; } // Si le jeu est en pause, interrompre la mise à jour if (Pause) { return; } float delayTimer = (float)gameTime.ElapsedGameTime.TotalSeconds; delaySecondRestant -= delayTimer; if (delaySecondRestant <= 0) { delaySecondRestant = delaySecond; pointsAutre += 1f; } // Mettre à joueur les sprites du jeu this.vaisseauJoueur.Update(gameTime, this.graphics); this.arrierePlanEspace.Update(gameTime, this.graphics); this.updateEnnemi(gameTime); // Mettre à jour les obus this.UpdateObus(gameTime); // Mettre à jour les particules d'explosion this.UpdateParticulesExplosions(gameTime); foreach (EnnemiSprite sprite in listeEnnemis) { bool collision = sprite.Collision(vaisseauJoueur); if (!this.vaisseauJoueur.IsRespawned && collision) { this.vaisseauJoueur.Health -= 5f; this.listeEnnemisFini.Add(sprite); this.CreerExplosion(sprite, particulesExplosions, gameTime, 1f); bruitageExplosion.Play(0.25f, 0f, 0f); if (vaisseauJoueur.Health < 1) { vaisseauJoueur.IsRespawned = true; vaisseauJoueur.NbVies -= 1; this.vaisseauJoueur.Position = this.vaisseauJoueur.PositionInitiale; } } } foreach (EnnemiSprite s in listeEnnemisFini) { listeEnnemis.Remove(s); } UpdatePowerUps(gameTime); } } }