コード例 #1
0
        private void UpdatePlaying(GameTime gameTime, KeyboardState state)
        {
            if (MediaPlayer.State == MediaState.Playing)
            {
                MediaPlayer.Volume = 0.20f;
            }
            if (MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.IsRepeating = true;
                MediaPlayer.Volume      = 0.25f;
                MediaPlayer.Play(gameMusic);
            }

            if (balle.getEnable() == false)
            {
                balle.setPositionX(palette.getPositionX() + 40);
            }

            // Vérification si balle sort par le bas de l'écran
            soundEngineInstance = death.CreateInstance();
            if (balle.getPositionY() > screenBound.Bottom)
            {
                lives        -= 1;
                hearts[lives] = null;
                hearts.Remove(hearts[lives]);
                if (lives == 0)
                {
                    LoadContent();
                }
                Texture2D balleSprite = Content.Load <Texture2D>("balle");
                balle = new Balle(balleSprite, screenBound, new Vector2(screenBound.Width / 2 - 10, screenBound.Height - 70), new Vector2(0, 1), false);
                palette.returnToStart();
                balle.setEnable(false);

                soundEngineInstance.Volume = 0.50f;
                soundEngineInstance.Play();
            }


            if (state.IsKeyDown(Keys.Enter))
            {
                pressed   = true;
                gameState = GameState.Paused;
            }

            // Update la position de la palette
            palette.Update(state);

            // Update position de la balle + vérification collision avec mur
            soundEngineInstance = balleMur.CreateInstance();
            balle.Update(state, gameTime, soundEngineInstance);

            // Vérification collision balle avec palette
            soundEngineInstance = ballePalette.CreateInstance();
            balle.checkPaddleCollision(palette.getLocation(), soundEngineInstance);

            // Vérification collision balle avec briques
            soundEngineInstance = explosionBrique.CreateInstance();
            for (int i = 0; i < briques.Count; ++i)
            {
                if (balle.checkBrickCollision(briques[i].getLocation()))
                {
                    briques[i].setHp(briques[i].getHp() - 1);
                    if (briques[i].getHp() == 0)
                    {
                        briques[i] = null;
                        briques.Remove(briques[i]);

                        soundEngineInstance.Volume = 0.50f;
                        soundEngineInstance.Play();
                    }
                    else
                    {
                        briques[i].setColor(Color.LightBlue);
                    }
                    if (briques.Count == 0)
                    {
                        LoadContent();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            backgroundPlay = Content.Load <Texture2D>("background_play");
            backgroundMenu = Content.Load <Texture2D>("background_menu");

            Texture2D paletteSprite = Content.Load <Texture2D>("palette");

            palette = new Palette(paletteSprite, screenBound);

            Texture2D briqueSprite = Content.Load <Texture2D>("brique");

            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
            {
                briques.Add(new Brique(briqueSprite, Color.LimeGreen, new Vector2(i, 100 + briqueSprite.Height), 1));
            }
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
            {
                briques.Add(new Brique(briqueSprite, Color.Fuchsia, new Vector2(i, 100), 1));
            }
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
            {
                briques.Add(new Brique(briqueSprite, Color.Orange, new Vector2(i, 100 - briqueSprite.Height), 1));
            }
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
            {
                briques.Add(new Brique(briqueSprite, Color.DodgerBlue, new Vector2(i, 100 - 2 * briqueSprite.Height), 2));
            }
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
            {
                briques.Add(new Brique(briqueSprite, Color.DarkOrchid, new Vector2(i, 100 - 3 * briqueSprite.Height), 1));
            }
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
            {
                briques.Add(new Brique(briqueSprite, Color.DeepPink, new Vector2(i, 100 - 4 * briqueSprite.Height), 1));
            }

            Texture2D balleSprite = Content.Load <Texture2D>("balle");

            balle = new Balle(balleSprite, screenBound, new Vector2(screenBound.Width / 2 - (balleSprite.Width), screenBound.Height - 70), new Vector2(0, 1), false);

            Texture2D boutonStartSprite      = Content.Load <Texture2D>("boutonStart");
            Texture2D boutonStartHighlighted = Content.Load <Texture2D>("boutonStart_highlighted");
            Texture2D boutonStartActivated   = Content.Load <Texture2D>("boutonStart_activated");

            boutonStart          = new Bouton(boutonStartSprite, boutonStartHighlighted, boutonStartActivated, (screenBound.Width / 4) - (boutonStartSprite.Width / 2), screenBound.Height - 100);
            boutonStart.Clicked += (s, e) => gameState = GameState.Loading;
            Texture2D boutonExitSprite = Content.Load <Texture2D>("boutonExit");
            Texture2D boutonExitHigh   = Content.Load <Texture2D>("boutonExit_highlighted");
            Texture2D boutonExitAct    = Content.Load <Texture2D>("boutonExit_Activated");

            boutonExit          = new Bouton(boutonExitSprite, boutonExitHigh, boutonExitAct, 3 * (screenBound.Width / 4) - (boutonStartSprite.Width / 2), screenBound.Height - 100);
            boutonExit.Clicked += (s, e) => Exit();
            Texture2D boutonResumeSprite = Content.Load <Texture2D>("boutonResume");
            Texture2D boutonResumeHigh   = Content.Load <Texture2D>("boutonResume_Highlighted");
            Texture2D boutonResumeAct    = Content.Load <Texture2D>("boutonResume_Activated");

            boutonResume          = new Bouton(boutonResumeSprite, boutonResumeHigh, boutonResumeAct, screenBound.Width / 2 - boutonResumeSprite.Width / 2, screenBound.Height / 2 - boutonResumeSprite.Height / 2);
            boutonResume.Clicked += (s, e) => gameState = GameState.Loading;
            Texture2D chiffre3Sprite = Content.Load <Texture2D>("3");

            chiffre = new WaitTime(chiffre3Sprite, screenBound);

            balleAnim  = new Balle(balleSprite, screenBound, new Vector2(screenBound.Width / 2 - (balleSprite.Width), screenBound.Height - 150), new Vector2(r.Next(1, 10), r.Next(-10, -1)), true);
            balleAnim2 = new Balle(balleSprite, screenBound, new Vector2(screenBound.Width / 2 - 3 * (balleSprite.Width), screenBound.Height - 150), new Vector2(r.Next(1, 10), r.Next(-10, -1)), true);
            lives      = 3;
            Texture2D heartSprite = Content.Load <Texture2D>("heart");

            for (int i = 0; i < lives * (heartSprite.Width + 5); i += heartSprite.Width + 5)
            {
                hearts.Add(new Heart(heartSprite, new Vector2(i + 5, screenBound.Height - 30)));
            }

            balleMur        = Content.Load <SoundEffect>("HitWall");
            ballePalette    = Content.Load <SoundEffect>("HitPalette");
            explosionBrique = Content.Load <SoundEffect>("Explosion");
            death           = Content.Load <SoundEffect>("Death");
            deathFinal      = Content.Load <SoundEffect>("DeathFinal");
            countdown       = Content.Load <SoundEffect>("321");

            mainMenuMusic = Content.Load <Song>("mainMenuMusic");
            gameMusic     = Content.Load <Song>("gameMusic");
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: KaribouSpatial/TFOL
        private void UpdatePlaying(GameTime gameTime, KeyboardState state)
        {
            if (MediaPlayer.State == MediaState.Playing)
            {
                MediaPlayer.Volume = 0.20f;
            }
            if (MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.IsRepeating = true;
                MediaPlayer.Volume = 0.25f;
                MediaPlayer.Play(gameMusic);
            }

            if (balle.getEnable() == false)
            {
                balle.setPositionX(palette.getPositionX() + 40);
            }

            // Vérification si balle sort par le bas de l'écran
            soundEngineInstance = death.CreateInstance();
            if (balle.getPositionY() > screenBound.Bottom)
            {
                lives -= 1;
                if (lives == 0)
                {
                    LoadContent();
                }
                Texture2D balleSprite = Content.Load<Texture2D>("balle");
                balle = new Balle(balleSprite, screenBound, new Vector2(screenBound.Width / 2 - 10, screenBound.Height - 70));
                palette.returnToStart();
                balle.setEnable(false);

                soundEngineInstance.Volume = 0.50f;
                soundEngineInstance.Play();
            }

            if (state.IsKeyDown(Keys.Enter))
            {
                gameState = GameState.Paused;
            }

            // Update la position de la palette
            palette.Update(state);

            // Update position de la balle + vérification collision avec mur
            soundEngineInstance = balleMur.CreateInstance();
            balle.Update(state, gameTime, soundEngineInstance);

            // Vérification collision balle avec palette
            soundEngineInstance = ballePalette.CreateInstance();
            balle.checkPaddleCollision(palette.getLocation(), soundEngineInstance);

            // Vérification collision balle avec briques
            soundEngineInstance = explosionBrique.CreateInstance();
            for (int i = 0; i < briques.Count; ++i)
            {
                if (balle.checkBrickCollision(briques[i].getLocation()))
                {
                    briques[i].setHp(briques[i].getHp() - 1);
                    if (briques[i].getHp() == 0)
                    {
                        briques[i] = null;
                        briques.Remove(briques[i]);

                        soundEngineInstance.Volume = 0.50f;
                        soundEngineInstance.Play();
                    }
                    else
                    {
                        briques[i].setColor(Color.LightBlue);
                    }
                    if (briques.Count == 0)
                    {
                        LoadContent();
                    }
                }
            }
        }
コード例 #4
0
        public void checkBallCollision(Balle ball)
        {
            bool      inCollision = false;
            Rectangle up          = new Rectangle((int)boutonPosition.X, (int)boutonPosition.Y,
                                                  bound.Width, 0);
            Rectangle down = new Rectangle((int)boutonPosition.X, (int)boutonPosition.Y + bound.Height,
                                           bound.Width, 0);
            Rectangle left = new Rectangle((int)boutonPosition.X, (int)boutonPosition.Y,
                                           0, bound.Height);
            Rectangle right = new Rectangle((int)boutonPosition.X + bound.Width, (int)boutonPosition.Y,
                                            0, bound.Height);

            if (ball.getLocation().Intersects(up) && !inCollision)
            {
                if (ball.getDirection().Y > 0)
                {
                    ball.setDirection(new Vector2(ball.getDirection().X, -1 * (ball.getDirection().Y)));
                }
                else
                {
                    ball.setDirection(new Vector2(-1 * ball.getDirection().X, ball.getDirection().Y + 1));
                }
                inCollision = true;
            }
            else if (ball.getLocation().Intersects(down) && !inCollision)
            {
                if (ball.getDirection().Y < 0)
                {
                    ball.setDirection(new Vector2(ball.getDirection().X, -1 * (ball.getDirection().Y)));
                }
                else
                {
                    ball.setDirection(new Vector2(-1 * ball.getDirection().X, ball.getDirection().Y + 1));
                }
                inCollision = true;
            }
            else if (ball.getLocation().Intersects(left) && !inCollision)
            {
                if (ball.getDirection().X > 0)
                {
                    ball.setDirection(new Vector2((-1 * ball.getDirection().X), ball.getDirection().Y));
                }
                else
                {
                    ball.setDirection(new Vector2(ball.getDirection().X + 1, -1 * ball.getDirection().Y));
                }
                inCollision = true;
            }
            else if (ball.getLocation().Intersects(right) && !inCollision)
            {
                if (ball.getDirection().X < 0)
                {
                    ball.setDirection(new Vector2((-1 * ball.getDirection().X), ball.getDirection().Y));
                }
                else
                {
                    ball.setDirection(new Vector2(ball.getDirection().X + 1, -1 * ball.getDirection().Y));
                }
                inCollision = true;
            }
        }
コード例 #5
0
ファイル: Game1.cs プロジェクト: KaribouSpatial/TFOL
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            backgroundPlay = Content.Load<Texture2D>("background_play");
            backgroundMenu = Content.Load<Texture2D>("background_menu");

            Texture2D paletteSprite = Content.Load<Texture2D>("palette");
            palette = new Palette(paletteSprite, screenBound);

            Texture2D briqueSprite = Content.Load<Texture2D>("brique");
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
                briques.Add(new Brique(briqueSprite, Color.LimeGreen, new Vector2(i, 100 + briqueSprite.Height), 1));
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
                briques.Add(new Brique(briqueSprite, Color.Fuchsia, new Vector2(i, 100), 1));
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
                briques.Add(new Brique(briqueSprite, Color.Orange, new Vector2(i, 100 - briqueSprite.Height), 1));
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
                briques.Add(new Brique(briqueSprite, Color.DodgerBlue, new Vector2(i, 100 - 2*briqueSprite.Height), 2));
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
                briques.Add(new Brique(briqueSprite, Color.DarkOrchid, new Vector2(i, 100 - 3*briqueSprite.Height), 1));
            for (int i = 0; i < screenBound.Width; i += briqueSprite.Width)
                briques.Add(new Brique(briqueSprite, Color.DeepPink, new Vector2(i, 100 - 4*briqueSprite.Height), 1));

            Texture2D balleSprite = Content.Load<Texture2D>("balle");
            balle = new Balle(balleSprite, screenBound, new Vector2(screenBound.Width / 2 - (balleSprite.Width), screenBound.Height - 70));

            Texture2D boutonStartSprite = Content.Load<Texture2D>("boutonStart");
            Texture2D boutonStartHighlighted = Content.Load<Texture2D>("boutonStart_highlighted");
            Texture2D boutonStartActivated = Content.Load<Texture2D>("boutonStart_activated");
            boutonStart = new Bouton(boutonStartSprite, boutonStartHighlighted, boutonStartActivated, (screenBound.Width / 4) - (boutonStartSprite.Width / 2), screenBound.Height - 100);
            boutonStart.Clicked += (s, e) => gameState = GameState.Loading;
            Texture2D boutonExitSprite = Content.Load<Texture2D>("boutonExit");
            Texture2D boutonExitHigh = Content.Load<Texture2D>("boutonExit_highlighted");
            Texture2D boutonExitAct = Content.Load<Texture2D>("boutonExit_Activated");
            boutonExit = new Bouton(boutonExitSprite, boutonExitHigh, boutonExitAct, 3*(screenBound.Width / 4) - (boutonStartSprite.Width / 2), screenBound.Height - 100);
            boutonExit.Clicked += (s, e) => Exit();
            Texture2D boutonResumeSprite = Content.Load<Texture2D>("boutonResume");
            Texture2D boutonResumeHigh = Content.Load<Texture2D>("boutonResume_Highlighted");
            Texture2D boutonResumeAct = Content.Load<Texture2D>("boutonResume_Activated");
            boutonResume = new Bouton(boutonResumeSprite, boutonResumeHigh, boutonResumeAct, screenBound.Width/2 - boutonResumeSprite.Width/2, screenBound.Height/2 - boutonResumeSprite.Height/2);
            boutonResume.Clicked += (s, e) => gameState = GameState.Loading;
            Texture2D chiffre3Sprite = Content.Load<Texture2D>("3");
            chiffre = new WaitTime(chiffre3Sprite, screenBound);

            lives = 3;

            balleMur = Content.Load<SoundEffect>("HitWall");
            ballePalette = Content.Load<SoundEffect>("HitPalette");
            explosionBrique = Content.Load<SoundEffect>("Explosion");
            death = Content.Load<SoundEffect>("Death");
            deathFinal = Content.Load<SoundEffect>("DeathFinal");
            countdown = Content.Load<SoundEffect>("321");

            mainMenuMusic = Content.Load<Song>("mainMenuMusic");
            gameMusic = Content.Load<Song>("gameMusic");
        }