Example #1
0
        // UPDATE & DRAW

        public void Update(MouseState souris, KeyboardState clavier, List <Wall> walls, List <Bonus> bonus)
        {
            if (Global.Collisions.collision_speed)
            {
                speed = 6;
            }
            else if (Global.Collisions.LowSpeed)
            {
                speed = 2;
            }
            else
            {
                speed = 4;
            }
            GameTime gametime;

            gametime = new GameTime();
            Main.Update(gametime);

            #region Bullets
            if (Keyboard.GetState().IsKeyDown(Keys.Q) && bullets.Count() < 3 && !shot && Global.Handler.ammo_left > 0 && state == "standing")
            {
                shot = true;
                Bullets bullet = new Bullets(Resources.bullet);
                bullet.velocity = 5;
                if (Direction == Direction.Right)
                {
                    bullet.position = new Vector2(Hitbox.X + Hitbox.Width / 2, Hitbox.Y + Hitbox.Height / 3) + new Vector2(bullet.velocity * 5, 0);
                    Old_Dir         = Direction.Right;
                }
                else
                {
                    bullet.position = new Vector2(Hitbox.X, Hitbox.Y + Hitbox.Height / 3) + new Vector2(bullet.velocity * 5, 0);
                    Old_Dir         = Direction.Left;
                }
                bullet.isVisible = true;
                bullets.Add(bullet);
            }
            else
            {
                shot = false;
            }
            foreach (Bullets bullet in bullets)
            {
                if (Old_Dir == Direction.Right)
                {
                    bullet.position.X += bullet.velocity; // va vers la droite
                }
                else
                {
                    bullet.position.X -= bullet.velocity; // va vers la gauche
                }
                // la balle disparait si elle parcourt la distance ou rencontre un obstacle
                if (Vector2.Distance(bullet.position, new Vector2(Hitbox.X, Hitbox.Y)) >= 200)
                {
                    bullet.isVisible = false;
                }
                foreach (Wall wall in walls)
                {
                    if (wall.Hitbox.Intersects(new Rectangle((int)bullet.position.X, (int)bullet.position.Y, 5, 2)))
                    {
                        bullet.isVisible = false;
                    }
                }
            }

            //on retire la balle de la liste si elle disparait
            for (int i = 0; i < bullets.Count; i++)
            {
                if (!bullets[i].isVisible)
                {
                    bullets.RemoveAt(i);
                    i--;
                }
            }

            #endregion

            #region Gravité

            bool gravity = collisions.CollisionDown(Hitbox, walls, this.fallspeed);

            if (!gravity)
            {
                if (collisions.CollisionUp(Hitbox, walls, fallspeed))
                {
                    speedjump = 0;
                }
                if (hasjumped && speedjump > 1)
                {
                    this.Hitbox.Y -= speedjump;
                    speedjump     -= 1;
                }
                else
                {
                    this.Hitbox.Y += this.fallspeed;
                    framecolumn    = 1;
                    state          = "jump";
                }
            }
            else
            {
                if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 4))
                {
                    if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 2))
                    {
                        this.Hitbox.Y += 2;
                    }
                    else
                    {
                        this.Hitbox.Y++;
                    }
                }
                if (state == "jump")
                {
                    state = "standing";
                }
            }

            #endregion

            #region Couteau

            if (clavier.IsKeyDown(Keys.D) && state == "standing")
            {
                SoundEffectInstance couteau_sound_instance = Resources.couteau.CreateInstance();
                couteau_sound_instance.Play();
                framecolumn   = 1;
                compteur      = 1;
                state         = "cut";
                Hitbox.Width  = 50;
                Hitbox.Y     -= 16;
                Hitbox.Height = 55;
            }

            #endregion

            #region Déplacements

            //Le sprite et la hitbox accroupi quand le personnage est baissé ou coincé sous un mur
            if (clavier.IsKeyDown(Keys.Down))
            {
                Hitbox.Width  = 35;
                Hitbox.Height = 25;
                state         = "squat";
            }
            //Celui debout quand on se relève et qu'il y a suffisament de place
            if (clavier.IsKeyUp(Keys.Down) && Hitbox.Height == 25 && !collisions.CollisionUp(new Rectangle(Hitbox.X, Hitbox.Y - 15, Hitbox.Width, Hitbox.Height), walls, speed))
            {
                state         = "standing";
                Hitbox.Width  = 36;
                Hitbox.Height = 40;

                if (collisions.CollisionDown(new Rectangle(Hitbox.X, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                {
                    Hitbox.Y = Hitbox.Y - 15;
                }
            }

            // Tir Marco
            if (clavier.IsKeyDown(Keys.Q) && state == "standing") //On tire avec "Q" et debout uniquement
            {
                if (state != "shoot")
                {
                    framecolumn = 1;
                    compteur    = 1;
                }

                if (Global.Handler.ammo_left > 0)
                {
                    fire_sound_instance.Play();
                    state = "shoot";
                }
                else
                {
                    vide_sound_instance.Play();
                }
            }
            if (state == "cut")
            {
                if (compteur % 2 == 0)
                {
                    if (framecolumn < 8)
                    {
                        framecolumn++;
                        compteur++;
                    }
                    else
                    {
                        framecolumn = 1;
                        if (clavier.IsKeyUp(Keys.D))
                        {
                            state         = "standing";
                            Hitbox.Width  = 36;
                            Hitbox.Height = 40;
                            Hitbox.Y     += 15;
                        }
                    }
                }
                else
                {
                    compteur++;
                }
            }
            else
            if (state == "shoot")
            {
                if (compteur % 4 == 0)
                {
                    if (framecolumn < 10)
                    {
                        Hitbox.Width  = 52;
                        Hitbox.Height = 40;
                        framecolumn++;
                    }
                    else
                    {
                        state         = "standing";
                        Hitbox.Width  = 36;
                        Hitbox.Height = 40;
                        framecolumn   = 1;
                        compteur      = 1;
                    }
                }
                compteur++;
            }
            else
            if (clavier.IsKeyDown(Keys.Right) && state != "squat")                  // Permet de bouger à droite
            {
                // Droite si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionRight(Hitbox, walls, speed))
                {
                    this.Hitbox.X += speed;
                    this.Direction = Direction.Right;
                    if (collisions.CollisionDown(Hitbox, walls, speed))
                    {
                        this.Animate(1, 15, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }

            else if (clavier.IsKeyDown(Keys.Left) && state != "squat")            // Permet de bouger à gauche
            {
                // Gauche si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionLeft(Hitbox, walls, this.speed) && Hitbox.X > 0)
                {
                    this.Hitbox.X -= this.speed;
                    this.Direction = Direction.Left;
                    if (collisions.CollisionDown(Hitbox, walls, this.speed))
                    {
                        this.Animate(1, 15, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }

            if (clavier.IsKeyDown(Keys.Right) && state == "squat")          // Permet de bouger à droite accroupi
            {
                // Droite si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionRight(Hitbox, walls, this.speed))
                {
                    this.Hitbox.X += this.speed - 1;
                    this.Direction = Direction.Right;
                    if (collisions.CollisionDown(Hitbox, walls, this.speed))
                    {
                        this.Animate(2, 8, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }

            else if (clavier.IsKeyDown(Keys.Left) && state == "squat")    // Permet de bouger à gauche accroupi
            {
                // Gauche si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionLeft(Hitbox, walls, this.speed) && Hitbox.X > 0)
                {
                    this.Hitbox.X -= this.speed - 1;
                    this.Direction = Direction.Left;
                    if (collisions.CollisionDown(Hitbox, walls, this.speed))
                    {
                        this.Animate(2, 8, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }
            #endregion

            #region Déplacements test
            else if (clavier.IsKeyDown(Keys.A))
            {
                Hitbox = new Rectangle(50, 370, Hitbox.Width, Hitbox.Height);
            }
            else if (clavier.IsKeyDown(Keys.N))
            {
                Hitbox = new Rectangle(4500, 100, Hitbox.Width, Hitbox.Height);
            }
            #endregion

            #region Saut

            if (clavier.IsKeyDown(Keys.Space))
            {
                if (compteursaut == 1)
                {
                    spaceIsPressed = false;
                }
                else
                {
                    spaceIsPressed = true;
                    compteursaut++;
                }
            }
            else
            {
                compteursaut = 0;
            }

            if (clavier.IsKeyDown(Keys.Space) && spaceIsPressed && !hasjumped && gravity && state == "standing")
            {
                framecolumn = 1;
                if (!collisions.CollisionUp(Hitbox, walls, this.fallspeed))
                {
                    SoundEffectInstance saut_instance = Resources.saut.CreateInstance();
                    saut_instance.Play();
                    this.Hitbox.Y -= 12;
                    speedjump      = 12;
                }
                hasjumped = true;
                state     = "jump";
            }

            if (hasjumped == true && collisions.CollisionDown(Hitbox, walls, this.fallspeed) == true && state != "squat")
            {
                hasjumped = false;
                state     = "standing";
            }

            #endregion

            #region Effets et animation

            if (clavier.IsKeyUp(Keys.Right) && clavier.IsKeyUp(Keys.Left) && state == "standing")              // Ici c'est une partie de l'animation
            {
                framecolumn = 1;
            }

            switch (Direction)
            {
            case Direction.Left:
                effect = SpriteEffects.FlipHorizontally;
                break;

            case Direction.Right:
                effect = SpriteEffects.None;
                break;

            default:
                break;
            }
            #endregion

            #region Chute

            dead = Hitbox.Y > 480;

            if (dead)
            {
                Hitbox = new Rectangle(50, 350, Hitbox.Width, Hitbox.Height);
            }

            #endregion
            if (Global.Collisions.accu > 0)
            {
                change = false;
            }
            if (!change && Global.Collisions.accu > 0)
            {
                if (marco_color.G < 20)
                {
                    up = true;
                }
                if (marco_color.G > 235)
                {
                    up = false;
                }
                if (up)
                {
                    marco_color.G += 15;
                    marco_color.B += 15;
                }
                else
                {
                    marco_color.G -= 15;
                    marco_color.B -= 15;
                }
                Global.Collisions.accu--;
            }
            else
            {
                marco_color = new Color(254, 255, 255, 255);
            }
        }
Example #2
0
        public void Update(List <Wall> walls, int phase)
        {
            if (phase == 1)
            {
                compt++; // Cette petite ligne correspond à l'IA ( WAAAW Gros QI )
                distance2player = Hitbox.X - Global.Player.Hitbox.X;

                #region Mort Boss
                for (int i = 0; i < bullets.Count(); i++)
                {
                    if (!invicibility && Hitbox.Intersects(new Rectangle((int)bullets[i].position.X, (int)bullets[i].position.Y, 30, 30)))
                    {
                        bullets[i].isVisible = false;
                        bullets.RemoveAt(i);
                        i--;
                        if (pv > 1)
                        {
                            pv--;
                        }
                        else
                        {
                            isDead = true;
                        }
                    }
                }

                if (!isDead && Keyboard.GetState().IsKeyDown(Keys.D) && Global.Player.Hitbox.Intersects(Hitbox))
                {
                    if (compteur == 1)
                    {
                        cut = false;
                    }
                    else
                    {
                        cut = true;
                        compteur++;
                    }
                }
                else
                {
                    compteur = 0;
                }

                if (!isDead && cut && Keyboard.GetState().IsKeyDown(Keys.D) && Global.Player.Hitbox.Intersects(Hitbox))
                {
                    if (pv > 1)
                    {
                        pv -= 3;
                    }
                    else
                    {
                        isDead = true;
                    }
                }


                #endregion

                #region Animation
                if (!isDead)
                {
                    if (pv <= 15)
                    {
                        speed += 5;
                    }

                    if (distance2player != 0)
                    {
                        if (framecolumn > 8)
                        {
                            framecolumn = 2;
                        }
                        else if (compt % 5 == 0)
                        {
                            framecolumn++;
                        }
                    }
                    else
                    {
                        framecolumn = 9;
                    }
                }
                #endregion

                #region Gravité
                if (!isDead)
                {
                    bool gravity = collisions.CollisionDown(Hitbox, walls, this.fallspeed);

                    if (!gravity)
                    {
                        if (collisions.CollisionUp(Hitbox, walls, fallspeed))
                        {
                            speedjump = 0;
                        }
                        if (speedjump > 1)
                        {
                            this.Hitbox.Y -= speedjump;
                            speedjump     -= 1;
                        }
                        else
                        {
                            this.Hitbox.Y += this.fallspeed;
                        }
                    }
                    else
                    if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 4))
                    {
                        if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 2))
                        {
                            this.Hitbox.Y += 2;
                        }
                        else
                        {
                            this.Hitbox.Y++;
                        }
                    }
                }
                #endregion

                #region Déplacements
                if (!isDead)
                {
                    if (Math.Abs(distance2player) <= 20)
                    {
                        speed = 0;
                    }
                    else
                    {
                        if (pv > 20)
                        {
                            speed = 1;
                        }
                        else if (pv > 10)
                        {
                            speed = 2;
                        }
                        else
                        {
                            speed = 3;
                        }
                        if (distance2player < 0 && distance2player >= -800)
                        {
                            left = false;
                        }
                        else
                        if (distance2player > 0 && distance2player <= 800)
                        {
                            left = true;
                        }
                        else
                        if (distance2player > 800 || distance2player <= -800)
                        {
                            if (this.Hitbox.X <= origin - 800)
                            {
                                left = false;
                            }
                            else if (this.Hitbox.X >= origin + 800)
                            {
                                left = true;
                            }
                        }
                    }
                    if (left)
                    {
                        if (!collisions.CollisionLeft(Hitbox, walls, speed) && Hitbox.X > 0 && collisions.CollisionDown(new Rectangle(Hitbox.X - Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                        {
                            this.Hitbox.X -= speed;
                            this.Direction = Direction.Left;
                        }
                        else
                        {
                            framecolumn = 2;
                            compt      += 10;
                        }
                    }

                    if (!left)
                    {
                        if (!collisions.CollisionRight(Hitbox, walls, speed) && collisions.CollisionDown(new Rectangle(Hitbox.X + Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                        {
                            this.Hitbox.X += speed;
                            this.Direction = Direction.Right;
                        }
                        else
                        {
                            framecolumn = 2;
                            compt      += 10;
                        }
                    }
                }

                #endregion

                switch (Direction)
                {
                case Direction.Left:
                    effect = SpriteEffects.FlipHorizontally;
                    break;

                case Direction.Right:
                    effect = SpriteEffects.None;
                    break;
                }
                switch (pv)
                {
                case 1:
                    color.A = 20;
                    break;

                case 5:
                    color.A = 40;
                    break;

                case 10:
                    color.A = 80;
                    break;

                case 15:
                    color.A = 120;
                    break;

                case 20:
                    color.A = 160;
                    break;

                case 25:
                    color.A = 200;
                    break;

                case 30:
                    color = Color.White;
                    break;
                }
            }
            if (phase == 2)
            {
                invicibility = true;
                accu++;
                cri_dragon.Play();
                if (accu % 20 == 0)
                {
                    if (framecolumn == 2)
                    {
                        framecolumn = 1;
                    }
                    else
                    {
                        framecolumn = 2;
                    }
                }
            }
            if (phase == 3)
            {
                invicibility = false;
                compt++; // Cette petite ligne correspond à l'IA ( WAAAW Gros QI )
                distance2player = Hitbox.X - Global.Player.Hitbox.X;

                #region Mort Boss
                for (int i = 0; i < bullets.Count(); i++)
                {
                    if (!invicibility && Hitbox.Intersects(new Rectangle((int)bullets[i].position.X, (int)bullets[i].position.Y, 30, 30)))
                    {
                        bullets[i].isVisible = false;
                        bullets.RemoveAt(i);
                        i--;
                        if (pv > 1)
                        {
                            pv--;
                        }
                        else
                        {
                            isDead = true;
                        }
                    }
                }

                if (!isDead && Keyboard.GetState().IsKeyDown(Keys.D) && Global.Player.Hitbox.Intersects(Hitbox))
                {
                    if (compteur == 1)
                    {
                        cut = false;
                    }
                    else
                    {
                        cut = true;
                        compteur++;
                    }
                }
                else
                {
                    compteur = 0;
                }

                if (!isDead && cut && Keyboard.GetState().IsKeyDown(Keys.D) && Global.Player.Hitbox.Intersects(Hitbox))
                {
                    if (pv > 1)
                    {
                        pv -= 3;
                    }
                    else
                    {
                        isDead = true;
                    }
                }


                #endregion

                #region Animation
                if (!isDead)
                {
                    if (pv <= 15)
                    {
                        speed += 5;
                    }

                    if (distance2player != 0)
                    {
                        if (framecolumn > 8)
                        {
                            framecolumn = 2;
                        }
                        else if (compt % 5 == 0)
                        {
                            framecolumn++;
                        }
                    }
                    else
                    {
                        framecolumn = 9;
                    }
                }
                #endregion

                #region Gravité
                if (!isDead)
                {
                    bool gravity = collisions.CollisionDown(Hitbox, walls, this.fallspeed);

                    if (!gravity)
                    {
                        if (collisions.CollisionUp(Hitbox, walls, fallspeed))
                        {
                            speedjump = 0;
                        }
                        if (speedjump > 1)
                        {
                            this.Hitbox.Y -= speedjump;
                            speedjump     -= 1;
                        }
                        else
                        {
                            this.Hitbox.Y += this.fallspeed;
                        }
                    }
                    else
                    if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 4))
                    {
                        if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 2))
                        {
                            this.Hitbox.Y += 2;
                        }
                        else
                        {
                            this.Hitbox.Y++;
                        }
                    }
                }
                #endregion

                #region Déplacements
                if (!isDead)
                {
                    if (Math.Abs(distance2player) <= 20)
                    {
                        speed = 0;
                    }
                    else
                    {
                        if (pv > 20)
                        {
                            speed = 1;
                        }
                        else if (pv > 10)
                        {
                            speed = 2;
                        }
                        else
                        {
                            speed = 3;
                        }
                        if (distance2player < 0 && distance2player >= -800)
                        {
                            left = false;
                        }
                        else
                        if (distance2player > 0 && distance2player <= 800)
                        {
                            left = true;
                        }
                        else
                        if (distance2player > 800 || distance2player <= -800)
                        {
                            if (this.Hitbox.X <= origin - 800)
                            {
                                left = false;
                            }
                            else if (this.Hitbox.X >= origin + 800)
                            {
                                left = true;
                            }
                        }
                    }
                    if (left)
                    {
                        if (!collisions.CollisionLeft(Hitbox, walls, speed) && Hitbox.X > 0 && collisions.CollisionDown(new Rectangle(Hitbox.X - Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                        {
                            this.Hitbox.X -= speed;
                            this.Direction = Direction.Left;
                        }
                        else
                        {
                            framecolumn = 2;
                            compt      += 10;
                        }
                    }

                    if (!left)
                    {
                        if (!collisions.CollisionRight(Hitbox, walls, speed) && collisions.CollisionDown(new Rectangle(Hitbox.X + Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                        {
                            this.Hitbox.X += speed;
                            this.Direction = Direction.Right;
                        }
                        else
                        {
                            framecolumn = 2;
                            compt      += 10;
                        }
                    }
                }

                #endregion

                switch (Direction)
                {
                case Direction.Left:
                    effect = SpriteEffects.FlipHorizontally;
                    break;

                case Direction.Right:
                    effect = SpriteEffects.None;
                    break;
                }
                switch (pv)
                {
                case 1:
                    color.A = 20;
                    break;

                case 5:
                    color.A = 40;
                    break;

                case 10:
                    color.A = 80;
                    break;

                case 15:
                    color.A = 120;
                    break;

                case 20:
                    color.A = 160;
                    break;

                case 25:
                    color.A = 200;
                    break;

                case 30:
                    color = Color.White;
                    break;
                }
            }
        }
Example #3
0
        public void Update(List <Wall> walls, int random)
        {
            compt++; // Cette petite ligne correspond à l'IA ( WAAAW Gros QI )

            playerDistance = Hitbox.X - Global.Player.Hitbox.X;
            playerProche   = Math.Abs(playerDistance) < 200;


            #region Mort Ennemi
            for (int i = 0; i < bullets.Count(); i++)
            {
                if (!isDead & this.Hitbox.Intersects(new Rectangle((int)bullets[i].position.X, (int)bullets[i].position.Y, 30, 30)))
                {
                    isDead = true;
                    bullets[i].isVisible = false;
                    bullets.RemoveAt(i);
                    i--;
                }
            }

            if (!isDead && Keyboard.GetState().IsKeyDown(Keys.D) && Global.Player.Hitbox.Intersects(Hitbox))
            {
                isDead = true;
            }

            #endregion

            #region Animation

            if (framecolumn > 15)
            {
                framecolumn = 1;
            }
            else if (compt % 2 == 0)
            {
                framecolumn++;
            }

            #endregion

            #region Gravité

            bool gravity = collisions.CollisionDown(Hitbox, walls, this.fallspeed);

            if (!gravity)
            {
                if (collisions.CollisionUp(Hitbox, walls, fallspeed))
                {
                    speedjump = 0;
                }
                if (speedjump > 1)
                {
                    this.Hitbox.Y -= speedjump;
                    speedjump     -= 1;
                }
                else
                {
                    this.Hitbox.Y += this.fallspeed;
                }
            }
            else
            if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 4))
            {
                if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 2))
                {
                    this.Hitbox.Y += 2;
                }
                else
                {
                    this.Hitbox.Y++;
                }
            }

            #endregion

            #region Déplacements

            if (!playerProche)
            {
                if (compt > random)
                {
                    if (left)
                    {
                        left = false;
                    }
                    else
                    {
                        left = true;
                    }
                    compt = 1;
                }

                if (left)
                {
                    if (!collisions.CollisionRight(Hitbox, walls, this.speed) && collisions.CollisionDown(new Rectangle(Hitbox.X + Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                    {
                        this.Hitbox.X += speed;
                        this.Direction = Direction.Right;
                    }
                    else
                    {
                        framecolumn = 1;
                        compt      += 10;
                    }
                }

                if (!left)
                {
                    if (!collisions.CollisionLeft(Hitbox, walls, this.speed) && Hitbox.X > 0 && collisions.CollisionDown(new Rectangle(Hitbox.X - Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed) && Hitbox.X < 4600)
                    {
                        this.Hitbox.X -= speed;
                        this.Direction = Direction.Left;
                    }
                    else
                    {
                        framecolumn = 1;
                        compt      += 10;
                    }
                }
            }
            else
            {
                if (playerDistance > 0 && !collisions.CollisionLeft(Hitbox, walls, this.speed))
                {
                    this.Hitbox.X -= speed;
                    this.Direction = Direction.Left;
                }
                else if (playerDistance < 0 && !collisions.CollisionRight(Hitbox, walls, this.speed))
                {
                    this.Hitbox.X += speed;
                    this.Direction = Direction.Right;
                }
            }

            #endregion

            switch (Direction)
            {
            case Direction.Right:
                effect = SpriteEffects.FlipHorizontally;
                break;

            case Direction.Left:
                effect = SpriteEffects.None;
                break;
            }
        }
Example #4
0
        public void Update(List <Wall> walls)
        {
            compt++; // Cette petite ligne correspond à l'IA ( WAAAW Gros QI )
            distance2player = Hitbox.X - Global.Player.Hitbox.X;

            #region Mort Ennemi
            for (int i = 0; i < bullets.Count(); i++)
            {
                if (Hitbox.Intersects(new Rectangle((int)bullets[i].position.X, (int)bullets[i].position.Y, 30, 30)))
                {
                    bullets[i].isVisible = false;
                    bullets.RemoveAt(i);
                    i--;
                    if (pv > 1)
                    {
                        pv--;
                    }
                    else
                    {
                        isDead = true;
                    }
                }
            }

            if (!isDead && Keyboard.GetState().IsKeyDown(Keys.D) && Global.Player.Hitbox.Intersects(Hitbox))
            {
                isDead = true;
            }

            #endregion

            #region Animation
            if (!isDead)
            {
                if (distance2player != 0)
                {
                    if (framecolumn > 8)
                    {
                        framecolumn = 1;
                    }
                    else if (compt % 2 == 0)
                    {
                        framecolumn++;
                    }
                }
                else
                {
                    framecolumn = 9;
                }
            }
            #endregion

            #region Gravité
            if (!isDead)
            {
                bool gravity = collisions.CollisionDown(Hitbox, walls, this.fallspeed);

                if (!gravity)
                {
                    if (collisions.CollisionUp(Hitbox, walls, fallspeed))
                    {
                        speedjump = 0;
                    }
                    if (speedjump > 1)
                    {
                        this.Hitbox.Y -= speedjump;
                        speedjump     -= 1;
                    }
                    else
                    {
                        this.Hitbox.Y += this.fallspeed;
                    }
                }
                else
                if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 4))
                {
                    if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 2))
                    {
                        this.Hitbox.Y += 2;
                    }
                    else
                    {
                        this.Hitbox.Y++;
                    }
                }
            }
            #endregion

            #region Déplacements
            if (!isDead)
            {
                if (distance2player == 0)
                {
                    speed = 0;
                }
                else
                {
                    speed = 1;
                    if (distance2player < 0 && distance2player >= -200)
                    {
                        left  = false;
                        compt = 1;
                    }
                    else
                    if (distance2player > 0 && distance2player <= 200)
                    {
                        left  = true;
                        compt = 1;
                    }
                    else
                    if (distance2player > 200 || distance2player <= -200)
                    {
                        if (this.Hitbox.X <= origin - 200)
                        {
                            left  = false;
                            compt = 1;
                        }
                        else if (this.Hitbox.X >= origin + 200)
                        {
                            left  = true;
                            compt = 1;
                        }
                    }

                    if (left)
                    {
                        if (!collisions.CollisionLeft(Hitbox, walls, speed) && Hitbox.X > 0 && collisions.CollisionDown(new Rectangle(Hitbox.X - Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                        {
                            this.Hitbox.X -= speed;
                            this.Direction = Direction.Left;
                        }
                        else
                        {
                            framecolumn = 1;
                            compt      += 10;
                        }
                    }

                    if (!left)
                    {
                        if (!collisions.CollisionRight(Hitbox, walls, speed) && collisions.CollisionDown(new Rectangle(Hitbox.X + Hitbox.Width, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed) && Hitbox.X < 4600)
                        {
                            this.Hitbox.X += speed;
                            this.Direction = Direction.Right;
                        }
                        else
                        {
                            framecolumn = 1;
                            compt      += 10;
                        }
                    }
                }
            }


            #endregion

            #region Tir

            //enemy_bullets.Capacity = 5;
            if ((distance2player >= -200 && distance2player <= -100) || (distance2player > 100 && distance2player <= 200))
            {
                a_portee = true;
            }
            else
            {
                a_portee = false;
            }

            if (!isDead && Math.Abs(Hitbox.Y - Global.Player.Hitbox.Y) < 20 && a_portee && !shot && enemy_bullets.Count == 0 && Global.Player.health > 0)
            {
                shot_sound_instance.Play();
                shot = true;
                Bullets bullet = new Bullets(Resources.bullet);
                bullet.velocity  = 2;
                bullet.isVisible = true;
                enemy_bullets.Add(bullet);
                if (Direction == Direction.Right)
                {
                    Old_Direction   = Direction.Right;
                    bullet.position = new Vector2(Hitbox.X + Hitbox.Width / 2, Hitbox.Y + Hitbox.Height / 4) + new Vector2(bullet.velocity * 5, 0);
                }
                else
                {
                    Old_Direction   = Direction.Left;
                    bullet.position = new Vector2(Hitbox.X, Hitbox.Y + Hitbox.Height / 4) + new Vector2(bullet.velocity * 5, 0);
                }
            }
            else
            {
                shot = false;
            }

            // la balle disparait si elle parcourt la distance ou rencontre un obstacle


            foreach (Bullets bullet in enemy_bullets)
            {
                if (!isDead)
                {
                    if (Old_Direction == Direction.Right)
                    {
                        bullet.position.X += bullet.velocity; // va vers la droite
                    }
                    else
                    {
                        bullet.position.X -= bullet.velocity; // va vers la gauche
                    }
                    if (Vector2.Distance(bullet.position, new Vector2(Hitbox.X, Hitbox.Y)) >= 200)
                    {
                        bullet.isVisible = false;
                    }
                    else
                    if (Global.Player.Hitbox.Intersects(new Rectangle((int)bullet.position.X, (int)bullet.position.Y, 3, 3)))
                    {
                        Global.Player.health -= 3;
                        bullet.isVisible      = false;
                    }
                }
                foreach (Wall wall in walls)
                {
                    if (wall.Hitbox.Intersects(new Rectangle((int)bullet.position.X, (int)bullet.position.Y, 5, 2)))
                    {
                        bullet.isVisible = false;
                    }
                }
            }

            for (int i = 0; i < enemy_bullets.Count; i++)
            {
                if (!enemy_bullets[i].isVisible)
                {
                    enemy_bullets.RemoveAt(i);
                    i--;
                }
            }

            #endregion

            switch (Direction)
            {
            case Direction.Right:
                effect = SpriteEffects.FlipHorizontally;
                break;

            case Direction.Left:
                effect = SpriteEffects.None;
                break;
            }
            switch (pv)
            {
            case 1:
                color.A = 100;
                break;

            case 2:
                color.A = 200;
                break;

            case 3:
                color = Color.White;
                break;
            }
        }