Exemplo n.º 1
0
        public void Update(GameTime gametime)
        {
            KeyboardState KState = Keyboard.GetState();

            if (!fight)
            {
                if (KState.IsKeyDown(Keys.Q))
                {
                    //map.SourceRectangle = new Rectangle(map.SourceRectangle.Value.X - gameTime.ElapsedGameTime.Milliseconds / 5, map.SourceRectangle.Value.Y, 1300, 1000);

                    Direction = "left";
                    timer++;

                    if (timer == 15)
                    {
                        timer = 0;
                        if (colonne == 6)
                        {
                            colonne = 3;
                        }
                        else
                        {
                            colonne++;
                        }
                    }

                    if (persoPosition.X <= 0)
                    {
                        map = map4;
                        persoPosition.X = (screenWidth - persoTexture.Width / 6);
                    }
                    else
                    {
                        persoPosition += (new Vector2((-vitesse), 0));
                    }
                }
                else if (KState.IsKeyDown(Keys.Z))
                {
                    //map.SourceRectangle = new Rectangle(map.SourceRectangle.Value.X, map.SourceRectangle.Value.Y - gameTime.ElapsedGameTime.Milliseconds /5, 1300, 1000);

                    Direction = "up";
                    timer++;

                    if (timer == 15)
                    {
                        timer = 0;
                        if (colonne == 6)
                        {
                            colonne = 2;
                        }
                        else
                        {
                            colonne++;
                        }
                    }
                    if (persoPosition.Y <= 0)
                    {
                        mapnumber += 3;
                        persoPosition.Y = screenHeight - persoTexture.Height / 4;
                    }
                    else
                    {
                        persoPosition += new Vector2(0, -vitesse);
                    }
                }
                else if (KState.IsKeyDown(Keys.S))
                {
                    // map.SourceRectangle = new Rectangle(map.SourceRectangle.Value.X, map.SourceRectangle.Value.Y + gameTime.ElapsedGameTime.Milliseconds / 5, 1300, 1000);

                    Direction = "down";
                    timer++;

                    if (timer == 15)
                    {
                        timer = 0;
                        if (colonne == 6)
                        {
                            colonne = 2;
                        }
                        else
                        {
                            colonne++;
                        }
                    }
                    if (persoPosition.Y >= (screenHeight - persoTexture.Height / 4))
                    {
                        mapnumber -= 3;
                        persoPosition.Y = 0;
                    }
                    else
                    {
                        persoPosition += new Vector2(0, vitesse);
                    }

                }
                else if (KState.IsKeyDown(Keys.D))
                {
                    Direction = "right";
                    timer++;

                    if (timer == 15)
                    {
                        timer = 0;
                        if (colonne == 6)
                        {
                            colonne = 3;
                        }
                        else
                        {
                            colonne++;
                        }
                    }
                    if (persoPosition.X >= (screenWidth - persoTexture.Width / 6))
                    {
                        mapnumber += 1;
                        persoPosition.X = 0;
                    }
                    else
                    {
                        persoPosition += new Vector2(vitesse, 0);
                    }

                }
            }
                switch (Direction)
                {
                    case "up":

                        ligne = 3;
                        Rectsprite = new Rectangle((colonne - 1) * 32, (ligne - 1) * 63, 30, 63);
                        break;

                    case "down":

                        ligne = 1;
                        Rectsprite = new Rectangle((colonne - 1) * 32, (ligne - 1) * 63, 30, 62);
                        break;

                    case "left":

                        ligne = 2;
                        Rectsprite = new Rectangle((colonne - 1) * 32, (ligne - 1) * 63, 30, 63);
                        break;
                    case "right":

                        ligne = 4;
                        Rectsprite = new Rectangle((colonne - 1) * 32, (ligne - 1) * 63, 30, 63);
                        break;
                }

                persoRectangle = new Rectangle((int)persoPosition.X, (int)persoPosition.Y + persoTexture.Height / 8, persoTexture.Width / 12, persoTexture.Height / 8);
        }
Exemplo n.º 2
0
        protected override void LoadContent()
        {
            IsMouseVisible = true;

            // Screen stuff
            graphics.PreferredBackBufferWidth = screenWidth;
            graphics.PreferredBackBufferHeight = screenHeight;

            //  graphics.IsFullScreen = true;
            graphics.ApplyChanges();

            spriteBatch = new SpriteBatch(GraphicsDevice);

            song1 = Content.Load<Song>("Song/Song1");
            song2 = Content.Load<Song>("Song/Song2");
            song3 = Content.Load<Song>("Song/SongFight");
            songGameOver = Content.Load<Song>("Song/songGameOver");
            songVictory = Content.Load<Song>("Song/Victory");
            //Video
            video = Content.Load<Video>("Intro");
            playerVideo = new VideoPlayer();
            //Button
            btnPlay = new cButton(Content.Load<Texture2D>("Button/PlayButton"), graphics.GraphicsDevice, 100, 75);
            btnPlay.setPosition(new Vector2(screenWidth / 2 - btnPlay.size.X / 2, screenHeight / 2 - 100));

            btnOptions = new cButton(Content.Load<Texture2D>("Button/OptionsButton"), graphics.GraphicsDevice, 250, 100);
            btnOptions.setPosition(new Vector2(screenWidth / 2 - btnOptions.size.X / 2, screenHeight / 2));

            btnQuit = new cButton(Content.Load<Texture2D>("Button/QuitButton"), graphics.GraphicsDevice, 100, 75);
            btnQuit.setPosition(new Vector2(screenWidth / 2 - btnQuit.size.X / 2, screenHeight / 2 + 125));

            //Fight
            btnStartFight = new cButton(Content.Load<Texture2D>("Button/StartFight"), graphics.GraphicsDevice, 150, 70);
            btnStartFight.setPosition(new Vector2(screenWidth / 2 - 100, screenHeight / 2));

            btnAttack1 = new cButton(Content.Load<Texture2D>("Button/AttackButton"), graphics.GraphicsDevice, 120, 45);
            btnAttack1.setPosition(new Vector2(50, screenHeight / 2 + 200));

            btnSpell = new cButton(Content.Load<Texture2D>("Button/SpellButton"), graphics.GraphicsDevice, 120, 45);
            btnSpell.setPosition(new Vector2(170, screenHeight / 2 + 200));

            btnObjects = new cButton(Content.Load<Texture2D>("Button/ObjectsButton"), graphics.GraphicsDevice, 120, 45);
            btnObjects.setPosition(new Vector2(100, screenHeight / 2 + 250));

            btnEndFight = new cButton(Content.Load<Texture2D>("Button/EndFight"), graphics.GraphicsDevice, 75, 44);
            btnEndFight.setPosition(new Vector2(1200, 710));

            //Enemy
            enemy1 = new Enemy(Content.Load<Texture2D>("Sprites/enemy"), new Vector2(800, 600), new Rectangle(600 - 30, 800, 30, 59), new Rectangle(0, 0, 30, 59), 200);
            enemy2 = new Enemy(Content.Load<Texture2D>("Sprites/enemy"), new Vector2(350, 400), new Rectangle(438 - 30, 350, 30, 59), new Rectangle(0, 0, 30, 59), 400);

            //PNJ
            pnj1 = new PNJ(Content.Load<Texture2D>("pnj1"), new Vector2(1100, 280));

            //Speech
            btnNext = new cButton(Content.Load<Texture2D>("Button/Next"), graphics.GraphicsDevice, 75, 44);
            btnNext.setPosition(new Vector2(1200, 710));

            speechBoxTexture = Content.Load<Texture2D>("SpeechBox");
            speechBoxRectangle = new Rectangle(0, 700, speechBoxTexture.Width, speechBoxTexture.Height);

            //Pause
            pausedTexture = Content.Load<Texture2D>("Menu/Paused");
            pausedRectangle = new Rectangle(0, 0, pausedTexture.Width, pausedTexture.Height);

            btnPlay2 = new cButton(Content.Load<Texture2D>("Button/PlayButton2"), graphics.GraphicsDevice, 100, 75);
            btnPlay2.setPosition(new Vector2(screenWidth / 2 - btnPlay.size.X / 2, screenHeight / 2 - 100));

            btnOptions2 = new cButton(Content.Load<Texture2D>("Button/OptionsButton2"), graphics.GraphicsDevice, 250, 100);
            btnOptions2.setPosition(new Vector2(screenWidth / 2 - btnOptions2.size.X / 2, screenHeight / 2));

            btnQuit2 = new cButton(Content.Load<Texture2D>("Button/QuitButton2"), graphics.GraphicsDevice, 100, 75);
            btnQuit2.setPosition(new Vector2(screenWidth / 2 - btnQuit2.size.X / 2, screenHeight / 2 + 125));

            //inventaire
            inventaireTexture = Content.Load<Texture2D>("Menu/inventaire");
            inventaireRectangle = new Rectangle(0, 0, inventaireTexture.Width, inventaireTexture.Height);

            //Book
            bookTexture = Content.Load<Texture2D>("Book");
            bookRectangle = new Rectangle(200, 330, bookTexture.Width, bookTexture.Height);
            bookRectangle2 = new Rectangle(30, 45, bookTexture.Width, bookTexture.Height);

            //Options
            btnVolume0 = new cButton(Content.Load<Texture2D>("Volume/volume0"), graphics.GraphicsDevice, 100, 75);
            btnVolume0.setPosition(new Vector2(screenWidth / 8 - btnVolume0.size.X / 2 + 100, screenHeight / 2));

            btnVolume25 = new cButton(Content.Load<Texture2D>("Volume/volume25"), graphics.GraphicsDevice, 100, 75);
            btnVolume25.setPosition(new Vector2(screenWidth / 8 - btnVolume25.size.X / 2 + 300, screenHeight / 2));

            btnVolume50 = new cButton(Content.Load<Texture2D>("Volume/volume50"), graphics.GraphicsDevice, 100, 75);
            btnVolume50.setPosition(new Vector2(screenWidth / 8 - btnVolume50.size.X / 2 + 500, screenHeight / 2));

            btnVolume75 = new cButton(Content.Load<Texture2D>("Volume/volume75"), graphics.GraphicsDevice, 100, 75);
            btnVolume75.setPosition(new Vector2(screenWidth / 8 - btnVolume75.size.X / 2 + 700, screenHeight / 2));

            btnVolume100 = new cButton(Content.Load<Texture2D>("Volume/volume100"), graphics.GraphicsDevice, 100, 75);
            btnVolume100.setPosition(new Vector2(screenWidth / 8 - btnVolume100.size.X / 2 + 900, screenHeight / 2));

            btnPlay3 = new cButton(Content.Load<Texture2D>("Button/PlayButton3"), graphics.GraphicsDevice, 100, 75);
            btnPlay3.setPosition(new Vector2(screenWidth / 2 - btnPlay3.size.X / 2, screenHeight / 4));

            //health
            healthTexture = Content.Load<Texture2D>("Barres/Health");
            manaTexture = Content.Load<Texture2D>("Barres/Mana");
            healthBoxTexture = Content.Load<Texture2D>("Barres/HealthBox");
            enemyHealthTexture = Content.Load<Texture2D>("Barres/HealthEnemy");

            //TexteHealth
            spriteFont = Content.Load<SpriteFont>("SpriteFont1");

            //Moteur à particules
            snow = new ParticleGenerator(Content.Load<Texture2D>("snow"), graphics.GraphicsDevice.Viewport.Width, 50);

            //map
            Tiles.Content = Content;

            map8.Generate(new int[,]{
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,9,9,9,9,9,9,9,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,9,6,6,6,6,6,6,9,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,9,6,6,6,6,6,6,6,9,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,9,6,6,6,6,6,6,6,6,9,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,9,6,6,6,6,6,6,6,6,6,9,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,6,6,11,11,11,11,11,11,11,11,11,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,9,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,6,6,6,6,6,11,11,11,11,11,11,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,9,11,11,11,},
               {11,11,11,11,11,11,11,6,6,6,6,6,6,6,6,11,11,11,11,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,11,11,11,11,11,11,},
               {11,11,11,11,11,11,6,6,6,6,6,9,6,6,6,6,11,11,6,6,6,11,11,11,11,6,6,6,6,6,6,6,6,6,6,6,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,6,6,6,6,9,9,9,6,6,6,6,6,6,6,11,11,11,11,11,11,6,6,6,6,6,6,6,6,6,6,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,6,6,6,6,6,9,6,6,6,6,6,6,6,11,11,11,11,11,11,11,11,6,6,6,6,6,6,6,6,6,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,6,6,6,6,6,6,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,6,6,6,6,6,6,6,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,6,6,6,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,6,6,11,11,11,11,11,11,11,11,11,11,11,11,11,11,},
               {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,6,6,6,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,},
               }, 32);

            map5.Generate(new int[,]{
               {10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,4,5,4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,},
               {1,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,1,1,1,1,1,4,5,4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,},
               {1,1,1,10,10,10,10,10,10,1,1,10,10,10,10,10,10,10,1,1,1,1,1,1,4,5,4,1,1,10,10,10,10,10,10,10,10,10,10,10,10,10,10,},
               {1,1,1,1,10,10,10,1,1,1,1,10,10,10,1,10,10,1,1,1,1,1,1,1,4,5,4,1,1,1,1,1,1,10,10,10,10,10,10,10,10,10,10,},
               {1,1,1,1,8,8,8,1,1,1,1,4,5,4,4,4,4,4,4,1,1,1,1,1,4,5,4,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,10,},
               {1,1,1,1,8,8,8,8,8,1,1,4,5,5,5,5,5,5,4,1,1,4,4,4,4,5,4,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,},
               {1,1,1,8,8,8,8,8,8,8,8,4,4,4,4,4,4,5,4,1,1,4,5,5,5,5,4,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,},
               {1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,5,4,4,4,4,5,4,4,4,4,1,1,1,1,1,8,8,8,1,1,1,1,10,10,10,10,},
               {1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,4,1,1,1,1,1,1,1,1,8,8,8,8,1,1,10,10,10,10,10,},
               {1,1,1,1,1,1,4,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,5,4,1,1,1,1,1,1,1,8,8,8,8,8,1,1,1,10,10,10,10,},
               {4,4,4,4,4,4,4,5,4,4,4,4,4,4,4,4,4,1,1,1,1,4,5,4,1,1,1,1,1,1,8,8,8,8,8,8,1,1,1,1,10,10,10,},
               {5,5,5,5,5,5,5,5,4,1,1,1,1,1,1,1,1,1,1,1,1,4,5,4,1,1,1,1,1,1,8,8,8,1,1,1,1,1,1,1,10,10,10,},
               {4,4,4,4,4,4,4,5,4,1,1,1,1,1,1,1,1,1,1,1,1,4,5,4,4,1,1,1,1,1,1,8,1,1,1,1,1,1,1,10,10,10,10,},
               {1,1,1,1,1,1,4,5,4,1,4,4,1,1,1,1,1,1,1,1,1,4,5,5,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,},
               {1,1,1,1,1,1,4,5,4,4,4,5,4,1,1,1,1,1,1,1,1,4,4,5,5,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,},
               {4,1,1,1,1,1,4,5,5,5,5,5,5,4,1,1,1,1,1,1,1,1,4,4,5,5,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,},
               {5,4,1,1,1,1,4,5,5,5,5,7,5,5,4,1,1,1,1,1,1,1,1,4,4,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,10,10,10,},
               {5,5,4,4,4,4,4,5,5,7,7,7,7,7,4,4,1,1,1,1,1,1,1,1,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,10,},
               {7,5,5,5,5,5,5,5,5,5,7,7,7,5,5,4,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,10,10,10,},
               {7,5,5,5,5,5,5,5,5,5,5,5,5,5,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,},
               {7,7,5,5,5,5,5,5,5,5,5,5,5,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,},
               {7,7,7,5,5,5,5,5,5,5,5,5,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,},
               {7,7,7,7,5,5,5,5,5,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,10,},
               {7,7,7,7,7,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,10,10,},
               }, 32);
            map = map5;
        }
Exemplo n.º 3
0
        protected override void Update(GameTime gameTime)
        {
            presentKey = Keyboard.GetState();
            MouseState mouse = Mouse.GetState();
            Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);

            if (CurrentGameState == GameState.Playing && !paused && !inventaire && !talking)
            {
                IsMouseVisible = false;
            }
            else
            {
                IsMouseVisible = true;
            }

            switch (CurrentGameState)
            {
                case GameState.Video:

                    if (playOnce)
                    {

                        playOnce = false;
                    }

                    if (presentKey.IsKeyDown(Keys.Enter) && pastKey.IsKeyUp(Keys.Enter))
                    {

                        CurrentGameState = GameState.MainMenu;
                        MediaPlayer.Play(song1);
                    }
                     break;

                case GameState.Title:

                    if (presentKey.IsKeyDown(Keys.Enter))
                    {
                        CurrentGameState = GameState.Video;
                        playerVideo.Play(video);

                    }
                    break;

                case GameState.MainMenu:

                    if (btnPlay.isClicked == true)
                    {
                        MediaPlayer.Stop();
                        CurrentGameState = GameState.Playing;
                        MediaPlayer.Play(song2);
                    }

                    if (btnOptions.isClicked == true)
                        CurrentGameState = GameState.Options;

                    if (btnQuit.isClicked == true)
                        Exit();

                    btnOptions.Update(mouse, gameTime);
                    btnQuit.Update(mouse, gameTime);
                    btnPlay.Update(mouse, gameTime);
                    break;

                case GameState.Playing:

                    if (map == map5)
                    {
                        //Enemy
                        if (enemy1.health > 0)
                            enemy1.Update(gameTime, player.persoPosition);

                        if (enemy2.health > 0)
                            enemy2.Update(gameTime, player.persoPosition);
                        if (enemy1.Collision(player.persoPosition))
                        {
                            previousPosX = player.persoPosition.X;
                            previousPosY = player.persoPosition.Y;
                            turn = -1;
                            btnEndFight.isClicked = false;
                            Isfighting = true;
                            MediaPlayer.Play(song3);
                            enemy = enemy1;
                            attackChoisi = "";
                        }
                        else if (enemy2.Collision(player.persoPosition))
                        {
                            previousPosX = player.persoPosition.X;
                            previousPosY = player.persoPosition.Y;
                            turn = -1;
                            Isfighting = true;
                            MediaPlayer.Play(song3);
                            btnEndFight.isClicked = false;
                            enemy = enemy2;
                            attackChoisi = "";
                        }
                        foreach (CollisionTiles tile in map5.CollisionTiles)
                        {
                            if (tile.num >= 7)
                                player.Collision(tile.Rectangle);
                        }
                    }

                    if (map == map8)
                    {
                        //Moteur à particules
                        snow.update(gameTime, graphics.GraphicsDevice);
                        foreach (CollisionTiles tile in map8.CollisionTiles)
                        {
                            if (tile.num >= 7)
                                player.Collision(tile.Rectangle);
                        }
                        if (player.persoPosition.X <= 250 && player.persoPosition.X >= 200 && player.persoPosition.Y < 350 && player.persoPosition.Y > 280)
                            bookState = 1;
                    }
                    if (player.persoPosition.Y <= 0)
                    {
                        map = map8;
                        player.persoPosition.Y = (screenHeight - player.persoTexture.Height / 4);
                    }
                    else if (player.persoPosition.Y >= screenHeight - player.persoTexture.Height / 4)
                    {
                        map = map5;
                        player.persoPosition.Y = player.persoTexture.Height / 4 - 40;
                    }
                    if (Isfighting)
                    {
                        CurrentGameState = GameState.Fight;
                    }

                    if (!paused && !inventaire)
                    {
                        timerInventaire++;

                        //Perso
                        player.Update(gameTime);

                        //PNJ
                        if (pnj1.Collision(player.persoPosition))
                        {
                            talking = true;
                        }
                        if (talking)
                        {
                            btnNext.Update(mouse, gameTime);
                            if (btnNext.isClicked)
                                bookState = 2;
                            if (!pnj1.Collision(player.persoPosition))
                                talking = false;
                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                        {
                            btnPlay2.isClicked = false;
                            btnPlay2.Update(mouse, gameTime);
                            btnPlay3.isClicked = false;
                            btnPlay3.Update(mouse, gameTime);
                            btnOptions2.isClicked = false;
                            btnOptions2.Update(mouse, gameTime);
                            paused = true;
                        }

                        if (timerInventaire > 15)
                        {
                            if (Keyboard.GetState().IsKeyDown(Keys.I))
                            {
                                inventaire = true;
                                timerInventaire = 0;
                            }
                        }
                    }
                    else if (inventaire)
                    {
                        timerInventaire++;
                        if (timerInventaire > 15)
                        {
                            if (Keyboard.GetState().IsKeyDown(Keys.I))
                            {
                                inventaire = false;
                                timerInventaire = 0;
                            }
                        }

                    }

                    else if (paused)
                    {

                        MediaPlayer.Pause();
                        if (btnPlay2.isClicked)
                        {
                            paused = false;
                            MediaPlayer.Resume();
                        }
                        else if (btnOptions2.isClicked)
                        {
                            CurrentGameState = GameState.Options;
                            MediaPlayer.Resume();
                        }
                        if (btnQuit2.isClicked)
                            Exit();

                        btnPlay2.Update(mouse, gameTime);
                        btnOptions2.Update(mouse, gameTime);
                        btnQuit2.Update(mouse, gameTime);
                    }

                    break;

                case GameState.Options:
                    timerOptions++;
                    if (timerOptions > 5)
                    {
                        if (btnPlay3.isClicked)
                        {
                            timerOptions = 0;
                            paused = false;
                            CurrentGameState = GameState.Playing;
                        }
                        if (btnVolume0.isClicked)
                        {
                            MediaPlayer.Volume = 0.0f;
                            btnVolume25.isClicked = false;
                            btnVolume50.isClicked = false;
                            btnVolume75.isClicked = false;
                            btnVolume100.isClicked = false;
                            btnVolume0.Update(mouse, gameTime);
                            btnVolume25.Update(mouse, gameTime);
                            btnVolume50.Update(mouse, gameTime);
                            btnVolume75.Update(mouse, gameTime);
                            btnVolume100.Update(mouse, gameTime);
                        }

                        if (btnVolume25.isClicked)
                        {
                            MediaPlayer.Volume = 0.25f;
                            btnVolume0.isClicked = false;
                            btnVolume50.isClicked = false;
                            btnVolume75.isClicked = false;
                            btnVolume100.isClicked = false;
                            btnVolume0.Update(mouse, gameTime);
                            btnVolume25.Update(mouse, gameTime);
                            btnVolume50.Update(mouse, gameTime);
                            btnVolume75.Update(mouse, gameTime);
                            btnVolume100.Update(mouse, gameTime);
                        }

                        if (btnVolume50.isClicked)
                        {
                            MediaPlayer.Volume = 0.5f;
                            btnVolume0.isClicked = false;
                            btnVolume25.isClicked = false;
                            btnVolume75.isClicked = false;
                            btnVolume100.isClicked = false;
                            btnVolume0.Update(mouse, gameTime);
                            btnVolume25.Update(mouse, gameTime);
                            btnVolume50.Update(mouse, gameTime);
                            btnVolume75.Update(mouse, gameTime);
                            btnVolume100.Update(mouse, gameTime);
                        }
                        if (btnVolume75.isClicked)
                        {
                            MediaPlayer.Volume = 0.75f;
                            btnVolume0.isClicked = false;
                            btnVolume25.isClicked = false;
                            btnVolume50.isClicked = false;

                            btnVolume100.isClicked = false;
                            btnVolume0.Update(mouse, gameTime);
                            btnVolume25.Update(mouse, gameTime);
                            btnVolume50.Update(mouse, gameTime);
                            btnVolume75.Update(mouse, gameTime);
                            btnVolume100.Update(mouse, gameTime);
                        }
                        if (btnVolume100.isClicked)
                        {
                            MediaPlayer.Volume = 1.0f;
                            btnVolume0.isClicked = false;
                            btnVolume25.isClicked = false;
                            btnVolume50.isClicked = false;
                            btnVolume75.isClicked = false;
                            btnVolume0.Update(mouse, gameTime);
                            btnVolume25.Update(mouse, gameTime);
                            btnVolume50.Update(mouse, gameTime);
                            btnVolume75.Update(mouse, gameTime);
                            btnVolume100.Update(mouse, gameTime);
                        }

                        btnVolume0.Update(mouse, gameTime);
                        btnVolume25.Update(mouse, gameTime);
                        btnVolume50.Update(mouse, gameTime);
                        btnVolume75.Update(mouse, gameTime);
                        btnVolume100.Update(mouse, gameTime);
                        btnPlay3.Update(mouse, gameTime);

                    }

                    break;

                case GameState.Fight:

                    player.persoPosition.X = 200;
                    player.persoPosition.Y = screenHeight / 2 + 100;
                    player.fight = true;
                    player.colonne = 2;
                    player.Direction = "right";
                    player.Update(gameTime);
                    healthBoxRectangle = new Rectangle(10, 10, healthBoxTexture.Width, healthBoxTexture.Height);
                    healthRectangle = new Rectangle(16, 14, (player.health * 379) / player.healthMax, 35);
                    manaRectangle = new Rectangle(115, 62, (player.mana * 280) / player.manaMax, manaTexture.Height);
                    enemyHealthRectangle = new Rectangle((1030 - enemy.health / 2), (screenHeight / 2 - enemyHealthTexture.Height / 2 + 100), enemy.health, enemyHealthTexture.Height);
                    if (turn == -1 && btnStartFight.isClicked)
                    {
                        turn = 0;
                    }
                    if (turn % 2 == 0 && player.health > 0 && enemy.health > 0)
                    {
                        if (btnAttack1.isClicked && pastMouse.LeftButton == ButtonState.Released)
                        {
                            btnAttack1.isClicked = false;
                            attackChoisi = "Basic attack";
                            btnAttack1.Update(mouse, gameTime);
                            degat = rand.Next(15, 20);
                            manaPerdu = 0;
                        }

                        if (btnSpell.isClicked && pastMouse.LeftButton == ButtonState.Released)
                        {
                            btnSpell.isClicked = false;
                            attackChoisi = "Fire Ball";
                            btnSpell.Update(mouse, gameTime);
                            degat = rand.Next(150, 170);
                            manaPerdu = 20;

                        }
                        if (presentKey.IsKeyDown(Keys.Enter) && pastKey.IsKeyUp(Keys.Enter) && (attackChoisi == "Basic attack" || attackChoisi == "Fire Ball"))
                        {
                            if (degat >= enemy.health)
                            {
                                MediaPlayer.Play(songVictory);
                            }
                            enemy.health -= degat;
                            player.mana -= manaPerdu;
                            turn++;
                            attackChoisi = "";

                        }

                    }

                    else if (presentKey.IsKeyDown(Keys.Enter) && pastKey.IsKeyUp(Keys.Enter) && turn % 2 == 1 && player.health > 0 && enemy.health > 0)
                    {
                        player.health -= rand.Next(100, 120);
                        turn++;
                    }
                    if (player.health <= 0)
                    {
                        CurrentGameState = GameState.GameOver;
                        MediaPlayer.Play(songGameOver);
                    }
                    if (enemy.health <= 0)
                    {
                        enemy.health = 0;

                        if (btnEndFight.isClicked)
                        {
                            player.persoPosition.X = previousPosX;
                            player.persoPosition.Y = previousPosY;
                            player.fight = false;
                            btnStartFight.isClicked = false;
                            CurrentGameState = GameState.Playing;
                            Isfighting = false;
                            enemy.enemyPosition.X = -100;
                            enemy.enemyPosition.Y = -100;
                            MediaPlayer.Play(song2);
                        }
                    }

                    btnStartFight.Update(mouse, gameTime);
                    btnAttack1.Update(mouse, gameTime);
                    btnObjects.Update(mouse, gameTime);
                    btnSpell.Update(mouse, gameTime);
                    btnEndFight.Update(mouse, gameTime);

                    break;

                case GameState.GameOver:

                    break;
            }

            pastKey = presentKey;
            pastMouse = mouse;
            base.Update(gameTime);
        }
Exemplo n.º 4
0
 protected override void Initialize()
 {
     map = new Map();
     map5 = new Map();
     map8 = new Map();
     player = new Character(Content.Load<Texture2D>("Sprites/Player"), new Vector2(388, 130), new Rectangle(260 - 30, 438, 30, 59), new Rectangle(0, 0, 30, 59), 500, 200);
     base.Initialize();
 }