Beispiel #1
0
        /// <summary>
        /// Fonction qui fait tirer les projectiles         
        /// </summary>
        private void JoueurTirerProjectile()
        {
            if (ServiceHelper.Get<IInputService>().TirerNord(1))
            {
                Projectile pj = new Projectile(new Vector2(this.joueur.Position.X, this.joueur.Position.Y), 0);
                pj.TypeProjectile = Projectile.TypesProjectiles.Joueur;

                if (ServiceHelper.Get<IInputService>().DeplacementDroite(1) > 0)
                {
                    pj.VitesseHorizontale += this.joueur.VitesseHorizontal * 1.2f;
                }
                else if (ServiceHelper.Get<IInputService>().DeplacementGauche(1) > 0)
                {
                    pj.VitesseHorizontale -= this.joueur.VitesseHorizontal * 1.2f;
                }

                this.listeProjectiles.Add(pj);
            }
            else if (ServiceHelper.Get<IInputService>().TirerEst(1))
            {
                Projectile pj = new Projectile(new Vector2(this.joueur.Position.X, this.joueur.Position.Y), 2);
                pj.TypeProjectile = Projectile.TypesProjectiles.Joueur;

                if (ServiceHelper.Get<IInputService>().DeplacementAvant(1) > 0)
                {
                    pj.VitesseVerticale -= this.joueur.VitesseVerticale * 1.2f;
                }
                else if (ServiceHelper.Get<IInputService>().DeplacementArriere(1) > 0)
                {
                    pj.VitesseVerticale += this.joueur.VitesseVerticale * 1.2f;
                }

                this.listeProjectiles.Add(pj);
            }
            else if (ServiceHelper.Get<IInputService>().TirerSud(1))
            {
                Projectile pj = new Projectile(new Vector2(this.joueur.Position.X, this.joueur.Position.Y), 4);
                pj.TypeProjectile = Projectile.TypesProjectiles.Joueur;

                if (ServiceHelper.Get<IInputService>().DeplacementDroite(1) > 0)
                {
                    pj.VitesseHorizontale += this.joueur.VitesseHorizontal * 1.2f;
                }
                else if (ServiceHelper.Get<IInputService>().DeplacementGauche(1) > 0)
                {
                    pj.VitesseHorizontale -= this.joueur.VitesseHorizontal * 1.2f;
                }

                this.listeProjectiles.Add(pj);
            }
            else if (ServiceHelper.Get<IInputService>().TirerOuest(1))
            {
                Projectile pj = new Projectile(new Vector2(this.joueur.Position.X, this.joueur.Position.Y), 6);
                pj.TypeProjectile = Projectile.TypesProjectiles.Joueur;

                if (ServiceHelper.Get<IInputService>().DeplacementAvant(1) > 0)
                {
                    pj.VitesseVerticale -= this.joueur.VitesseVerticale * 1.2f;
                }
                else if (ServiceHelper.Get<IInputService>().DeplacementArriere(1) > 0)
                {
                    pj.VitesseVerticale += this.joueur.VitesseVerticale * 1.2f;
                }

                this.listeProjectiles.Add(pj);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Permet d'implanter les comportements logiques du jeu tels que
        /// la mise à jour du monde, la détection de collisions, la lecture d'entrées
        /// et les effets audio.
        /// </summary>
        /// <param name="gameTime">Fournie un instantané du temps de jeu.</param>
        protected override void Update(GameTime gameTime)
        {
            // Si le jeu est en cours de démarrage, passer à l'état de jouer.
            if (this.EtatJeu == Etats.Demarrer)
            {
                // L'usager veut-il démarrer la partie?
                if (ServiceHelper.Get<IInputService>().Sauter(1))
                {
                    this.EtatJeu = Etats.Jouer;

                    base.Update(gameTime);
                    return;
                }
                else if (ServiceHelper.Get<IInputService>().Pause(1))
                {
                    this.EtatJeu = Etats.Jouer;
                    this.joueur.VieDeJoueur = 99;

                    base.Update(gameTime);
                    return;
                }

                // Rien d'autre à faire alors on quitte la fonction
                base.Update(gameTime);
                return;
            }

            // Si le jeu est en cours de démarrage, passer à l'état de jouer.
            if (this.EtatJeu == Etats.GameOver)
            {
                if (ServiceHelper.Get<IInputService>().Sauter(1))
                {
                    // Bruitage de fond.
                    if (this.bruitageGameOverActif.State == SoundState.Playing)
                    {
                        this.bruitageGameOverActif.Stop();
                    }

                    this.contMort = 0;
                    this.GameOverState = false;
                    this.EtatJeu = Etats.Demarrer;
                    this.joueur = new Joueur(1150, 300);
                    this.joueur.BoundsRect = new Rectangle(0, 0, 600, 600);
                    this.joueur.GetValiderDeplacement = this.ValiderDeplacement;
                    this.joueur.VieDeJoueur = 10;
                    this.MondeCourant = Mondes.MAP_1_1;
                    this.boolClef = false;
                    this.boolFood = false;
                    this.joueur.Clef = false;
                    this.ClearMap();
                    this.LoadMap11();
                }

                if (ServiceHelper.Get<IInputService>().Quitter(1))
                {
                    // Bruitage de fond.
                    if (this.bruitageGameOverActif.State == SoundState.Playing)
                    {
                        this.bruitageGameOverActif.Stop();
                    }

                    this.Quitter = !this.Quitter;
                }

                // Rien d'autre à faire alors on quitte la fonction
                base.Update(gameTime);
                return;
            }

            // Si le jeu est en cours de terminaison, l'écran de générique demeure affichée
            // jusqu'à ce que le générique soit terminé ou que l'usager presse la touche
            // appropriée
            if (this.EtatJeu == Etats.Quitter)
            {
                if (this.bruitageFinOn != true)
                {
                    bruitageFin.Play();
                    this.bruitageFinOn = true;
                }

                // L'usager veut-il quitter immédiatement
                if (ServiceHelper.Get<IInputService>().Quitter(1))
                {
                    this.Exit();
                }

                // Modifier la position du générique de sorte qu'il monte lentement vers le haut
                this.generiqueScrollPos--;

                // Rien d'autre à faire alors on quitte la fonction
                base.Update(gameTime);
                return;
            }

            // Un menu est-il affiché?
            if (this.MenuCourant != null)
            {
                // Oui, alors gérer les inputs pour ce menu.
                this.MenuCourant.GetInput(gameTime);

                // Lorsqu'un menu est affiché, le jeu est en pause alors il n'y a rien d'autre
                // à faire dans Update().
                base.Update(gameTime);
                return;
            }

            // Permettre de quitter via le clavier.
            if (ServiceHelper.Get<IInputService>().Quitter(1))
            {
                this.MenuCourant = this.TrouverMenu("QuitterMenu");
            }

            // Est-ce que le bouton de pause a été pressé?
            if (ServiceHelper.Get<IInputService>().Pause(1))
            {
                this.PauseP = !this.PauseP;
            }

            // Si le jeu est en pause, interrompre la mise à jour.
            if (this.EtatJeu == Etats.PauseP)
            {
                base.Update(gameTime);
                return;
            }

            // Si le jeu est en pause, interrompre la mise à jour.
            if (this.Pause)
            {
                base.Update(gameTime);
                return;
            }

            // S'assurer que le bruitage de fond est en lecture.migh
            if (this.bruitageFondActif.State == SoundState.Stopped)
            {
                this.bruitageFondActif.Play();
                this.bruitageFondActif.Volume = 0.1f;
            }

            // Bruitage de fond.
            if (this.bruitageFondActif.State == SoundState.Paused)
            {
                this.bruitageFondActif.Play();
            }

            // Mettre à jour les particules d'explosion
            this.UpdateParticulesExplosions(gameTime);

            // Appelé pour arrêter le jeu aprés l'animation de mourir.
            if (this.joueur.Etat == Personnage.Etats.Mort && this.joueur.IndexTuile == 4)
            {
                if (this.contMort++ > 150)
                {
                    this.bruitageGameOverActif.Play();
                    this.GameOverState = !this.GameOverState;
                }

                base.Update(gameTime);
                return;
            }

            // Mettre à jour le sprite du joueur puis centrer la camera sur celui-ci.
            this.joueur.Update(gameTime, this.graphics);

            if (this.joueur.CouleurCollison <= 99)
            {
                this.joueur.CouleurCollison++;
            }

            if (this.joueur.VieDeJoueur == 0)
            {
                this.joueur.CouleurCollison = 100;

                if (this.bruitageMortActif.State != SoundState.Playing && this.contMort == 0)
                {
                    this.bruitageMort.Play();
                }

                this.bruitageFondActif.Stop();

                this.joueur.SuspendreEffetsSonores(true);

                switch ((gameTime.TotalGameTime.Milliseconds / 4) % 4)
                {
                    case 0:
                        this.joueur.Direction = Personnage.Directions.Nord;
                        break;
                    case 1:
                        this.joueur.Direction = Personnage.Directions.Est;
                        break;
                    case 2:
                        this.joueur.Direction = Personnage.Directions.Sud;
                        break;
                    default:
                        this.joueur.Direction = Personnage.Directions.Ouest;
                        break;
                }

                if (this.contMort++ > 110)
                {
                    this.joueur.Etat = Personnage.Etats.Mort;
                }

                this.bruitageFondActif.Pause();
                base.Update(gameTime);
                return;
            }

            if (this.joueur.Etat == Personnage.Etats.Tombe && this.joueur.ContTombe > 60)
            {
                this.joueur.AngleRotation = this.joueur.ContTombe = 0;
                this.joueur.Etat = Personnage.Etats.Stationnaire;
                this.joueur.Direction = Personnage.Directions.Nord;
                this.joueur.Echelle = 1.0f;
                this.joueur.Position = this.monde.PositionInitiale;
                this.joueur.VieDeJoueur--;
            }

            this.camera.Centrer(this.joueur.Position);

            // Mettre à jour les ogres.
            foreach (Ennemi ogre in this.listeOgres)
            {
                ogre.SeTournerVers(this.joueur.Position);

                // Déterminer si on doit créer un nouvel astéroide.
                if (this.randomPJEnemi.NextDouble() < this.probPJ)
                {
                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.Nord)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X, ogre.Position.Y - 60), 0);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.NordEst)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X + 60, ogre.Position.Y - 60), 1);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.Est)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X + 60, ogre.Position.Y), 2);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.SudEst)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X + 60, ogre.Position.Y + 60), 3);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.Sud)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X, ogre.Position.Y + 60), 4);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.SudOuest)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X - 60, ogre.Position.Y + 60), 5);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.Ouest)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X - 60, ogre.Position.Y), 6);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }

                    // Créer le sprite
                    if (ogre.Direction == Personnage.Directions.NordOuest)
                    {
                        Projectile pj = new Projectile(new Vector2(ogre.Position.X - 60, ogre.Position.Y - 60), 7);
                        pj.TypeProjectile = Projectile.TypesProjectiles.Ennemi;
                        this.listeProjectiles.Add(pj);
                    }
                }

                if (ogre.Collision(this.joueur) && this.joueur.CouleurCollison > 99)
                {
                    this.joueur.VieDeJoueur--;
                    this.joueur.CouleurCollison = 0;
                    this.bruitageFrapper.Play();
                }

                ogre.Update(gameTime, this.graphics);
            }

            // Se débarasser des astéroïdes ayant quitté l'écran.
            foreach (Ennemi ogre in this.listeOgresFini)
            {
                this.listeOgres.Remove(ogre);
            }

            this.GestionProjectile(gameTime);

            this.GestionSwtich(gameTime);

            this.UpdateVieDeJoueur();

            foreach (Food food in this.listeFood)
            {
                if (this.joueur.Collision(food))
                {
                    this.boolFood = false;
                    this.joueur.VieDeJoueur = 10;
                    this.listeFoodFini.Add(food);
                    this.bruitageItem.Play();
                }
            }

            foreach (Food food in this.listeFoodFini)
            {
                this.listeFood.Remove(food);
            }

            foreach (Clef clef in this.listeClef)
            {
                if (this.joueur.Collision(clef))
                {
                    this.boolClef = true;
                    this.joueur.Clef = true;
                    this.listeClefFini.Add(clef);
                    this.bruitageItem.Play();

                    Clef clef1 = new Clef(600 - 16, 15);
                    this.listeClef.Add(clef1);
                    break;
                }
            }

            foreach (Clef clef in this.listeClefFini)
            {
                this.listeClef.Remove(clef);
            }

            foreach (Projectile pj in this.listeProjectiles)
            {
                pj.Update(gameTime, this.graphics);
            }

            foreach (Bloc bloc in this.listeBloc)
            {
                if (bloc.VideDeBloc > 0)
                {
                    bloc.Update(gameTime, this.graphics);
                }

                if (bloc.BlocEchelle <= 0.05f)
                {
                    this.listeBlocFini.Add(bloc);
                }
            }

            foreach (Bloc bloc in this.listeBlocFini)
            {
                // if (bloc.BlocEchelle <= 0.05f)
                {
                    this.listeBloc.Remove(bloc);
                }
            }

            this.GestionAtteintUneSortie();

            this.listeProjectileFini.Clear();
            this.listeVideJoueurFini.Clear();

            base.Update(gameTime);
        }