Example #1
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     fantome = new Fantome(Content);
     decors = new Decors(Content);
     back_ground = new Back_Ground(Content);
     startMenu_text = Content.Load<Texture2D>("Menu/Menu");
     playButton_text = Content.Load<Texture2D>("Menu/Bouton_Play");
     optionsButton_text = Content.Load<Texture2D>("Menu/Bouton_Option");
     exitButton_text = Content.Load<Texture2D>("Menu/Bouton_Exit");
     music = Content.Load<Song>("SoundFX/Ambiance");
     MediaPlayer.Play(music);                              // Musique de fond, dès que le jeu est lancé, a changer => créer une classe?
     MediaPlayer.IsRepeating = true;
 }
Example #2
0
 protected override void UnloadContent()
 {
     decors = null;
     fantome = null;
     back_ground = null;
     music = null;
 }
Example #3
0
        public void Update(MouseState mouseState, KeyboardState keyboardState, GraphicsDevice graphicsDevice, Decors decors, GameTime gameTime)
        {
            CurrentHitbox = Hitbox; // To save the last position.
            int isGoingDown = Hitbox.Y;
            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            timer2 += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            timecounter += (int)timer;

            timerjump += (int)timer2;
            if (timecounter > 10000)
            {
                timer = 0;
                timecounter = 0;
            }

            /// <control>

            if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
            {
                Hitbox.X += 5;
                if (timecounter < 1500)
                {
                    fantomeIniTexture = fantomeD1Texture;
                }
                else if (timecounter < 5000)
                {
                    fantomeIniTexture = fantomeD2Texture;
                }
                else if (timecounter < 7500)
                {
                    fantomeIniTexture = fantomeD3Texture;
                }
                else
                {
                    fantomeIniTexture = fantomeD4Texture;
                }

                foreach (Rectangle g in decors.porteHitbox)
                {
                    if (Hitbox.Intersects(g))
                        Null = porteFinish;
                    foreach (Rectangle h in decors.groundHitbox)
                    {
                        if (Hitbox.Intersects(h))
                            Hitbox = CurrentHitbox;
                    }
                }

                CurrentHitbox = Hitbox;
            }

            if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
            {
                Hitbox.X -= 5;
                if (timecounter < 1500)
                {
                    fantomeIniTexture = fantomeG1Texture;
                }
                else if (timecounter < 5000)
                {
                    fantomeIniTexture = fantomeG2Texture;
                }
                else if (timecounter < 7500)
                {
                    fantomeIniTexture = fantomeG3Texture;
                }
                else
                {
                    fantomeIniTexture = fantomeG4Texture;
                }

                foreach (Rectangle g in decors.porteHitbox)
                {
                    if (Hitbox.Intersects(g))
                        Null = porteFinish;
                    foreach (Rectangle h in decors.groundHitbox)
                    {
                        if (Hitbox.Intersects(h))
                            Hitbox = CurrentHitbox;
                    }
                }

                CurrentHitbox = Hitbox;
            }

            if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S))
            {
                Hitbox.Y += 5;
                fantomeIniTexture = fantomeFallTexture;
                if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
                {
                    fantomeIniTexture = fantomeFallTexture;
                }
                if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
                {
                    fantomeIniTexture = fantomeFallTexture;
                }

                foreach (Rectangle g in decors.porteHitbox)
                {
                    if (Hitbox.Intersects(g))
                        Null = porteFinish;
                    foreach (Rectangle h in decors.groundHitbox)
                    {
                        if (Hitbox.Intersects(h))
                            Hitbox = CurrentHitbox;
                    }
                }
            }

            if (keyboardState.IsKeyDown(Keys.Up) && previousKeyboardState.IsKeyUp(Keys.Up)) //|| keyboardState.IsKeyDown(Keys.W))
            {
                if (IsTouching(decors.groundHitbox))
                {
                    timerjump = 0;
                    timer2 = 0;
                }
                timerjump = 0;
                timer2 = 0;
            }
            previousKeyboardState = keyboardState;
            if (timerjump < 3800)
            {
                Hitbox.Y -= 8;
                fantomeIniTexture = fantomeSTexture;
                if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
                {
                    fantomeIniTexture = fantomeGSTexture;
                }
                if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
                {
                    fantomeIniTexture = fantomeDSTexture;
                }
            }
            else
            {
                Hitbox.Y += 4;
                foreach (Rectangle g in decors.porteHitbox)
                {
                    if (Hitbox.Intersects(g))
                        Null = porteFinish;
                    foreach (Rectangle h in decors.groundHitbox)
                    {
                        if (Hitbox.Intersects(h))
                            Hitbox = CurrentHitbox;
                    }
                }

                Hitbox.Y++;

                if (keyboardState.IsKeyUp(Keys.Up) && keyboardState.IsKeyUp(Keys.Down) && keyboardState.IsKeyUp(Keys.Right) && keyboardState.IsKeyUp(Keys.Left) && keyboardState.IsKeyUp(Keys.W) && keyboardState.IsKeyUp(Keys.S) && keyboardState.IsKeyUp(Keys.D) && keyboardState.IsKeyUp(Keys.A))
                {
                    fantomeIniTexture = fantomeFallTexture;
                    foreach (Rectangle g in decors.porteHitbox)
                    {
                        if (Hitbox.Intersects(g))
                            Null = porteFinish;
                        foreach (Rectangle h in decors.groundHitbox)
                        {
                            if (Hitbox.Intersects(h))
                                fantomeIniTexture = fantomeStopTexture;
                        }
                    }
                }
            }
            /// </control>

            /// <ToStayInWindow>
            if (Hitbox.X < 0)
            {
                Hitbox.X = 0;
            }
            if (Hitbox.Y < 0)
            {
                Hitbox.Y = 0;
            }
            if (Hitbox.X + Hitbox.Width > graphicsDevice.Viewport.Width)
            {
                Hitbox.X = graphicsDevice.Viewport.Width - Hitbox.Width;
            }
            if (Hitbox.Y + Hitbox.Height > graphicsDevice.Viewport.Height)
            {
                Hitbox.Y = graphicsDevice.Viewport.Height - Hitbox.Height;
            }
            /// </ToStayInWindow>

            foreach (Rectangle g in decors.porteHitbox)
            {
                if (Hitbox.Intersects(g))
                    Null = porteFinish;
                foreach (Rectangle h in decors.groundHitbox)
                {
                    if (Hitbox.Intersects(h))
                        Hitbox = CurrentHitbox;
                }
            }
        }