Пример #1
0
 public void UpdateSong(ContentManager content, Character hero, Ennemy ennemy)
 {
     if (ennemy.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y) && compteur < 1) //attente de réglage <-- LOL
     {
         if (numberOfSong == 2)
             numberOfSong = 0;
         else
             numberOfSong++;
         MediaPlayer.Play(songs[numberOfSong]);
         compteur++;
     }
       /*      if (!hero.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y) && compteur > 0)
     {
         if (numberOfSong == 2)
             numberOfSong = 0;
         else
             numberOfSong++;
         MediaPlayer.Play(songs[numberOfSong]);
         compteur++;
     } */
 }
Пример #2
0
        public void updatePosition(PlayerType type, KeyboardState kbState, ref Background backG, Vector2[] posTreeTab, Vector2[] posWaterTab, Vector2[] posStoneTab, Vector2[] posGateTab, Texture2D spriteExample, Texture2D[] listOfTextures, int MaxWidth, int MaxHeight, int initPosX, int initPosY, int direc, Character hero, Ennemy ennemy)
        {
            if (type == PlayerType.Hero)
            {
                if (kbState.IsKeyDown(Keys.Up) && kbState.IsKeyDown(Keys.Left)      // flèches haut et gauche appuyées
            && Collisions.libreHeroUp(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
            && Collisions.libreHeroLeft(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.UpLeft;
                    this.Hitbox.X -= this.Speed;
                    this.Hitbox.Y -= this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Up) && kbState.IsKeyDown(Keys.Right)          // flèches haut et droite appuyées
                    && Collisions.libreHeroUp(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                    && Collisions.libreHeroRight(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.UpRight;
                    this.Hitbox.X += this.Speed;
                    this.Hitbox.Y -= this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Down) && kbState.IsKeyDown(Keys.Left)          // flèches bas et gauche appuyées
                    && Collisions.libreHeroDown(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                    && Collisions.libreHeroLeft(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.DownLeft;
                    this.Hitbox.X -= this.Speed;
                    this.Hitbox.Y += this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Down) && kbState.IsKeyDown(Keys.Right)          // flèches bas et droite appuyées
                    && Collisions.libreHeroDown(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                    && Collisions.libreHeroRight(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.DownRight;
                    this.Hitbox.X += this.Speed;
                    this.Hitbox.Y += this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Up)               // flèche haut appuyée
                    && Collisions.libreHeroUp(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))    //test collisions avec dessus du héros
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.Up;
                    this.Hitbox.Y -= this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Down)        // flèche bas appuyée
                    && Collisions.libreHeroDown(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))  //test collisions avec dessous du héros
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.Down;
                    this.Hitbox.Y += this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Left)        // flèche gauche appuyée
                    && Collisions.libreHeroLeft(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))  //test collisions avec gauche du héros
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.Left;
                    this.Hitbox.X -= this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyDown(Keys.Right)       // flèche droite appuyée
                    && Collisions.libreHeroRight(this.Hitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)) //test collisions avec droite du héros
                {
                    this.Direction = TLN_The_Last_Ninja.Direction.Right;
                    this.Hitbox.X += this.Speed;
                    this.Animate();
                }
                else if (kbState.IsKeyUp(Keys.Up) && (kbState.IsKeyUp(Keys.Down) && (kbState.IsKeyUp(Keys.Left) && (kbState.IsKeyUp(Keys.Right))))) // ici on empeche le sprite de moonwalk quand on n'appuie sur aucune touche !
                {
                    this.FrameColumn = 1; // faut remplacer par la colonne de notre sprite!
                    this.Timer = 0;
                }

                switch (this.Direction) // switch = plusieurs if ici on donne l'effet inverse au sprite.
                {
                    case Direction.Up: this.FrameLine = 3; // remplacer par les bons chiffres !
                        this.Effects = SpriteEffects.None;
                        break;
                    case Direction.Down: this.FrameLine = 1;
                        this.Effects = SpriteEffects.None;
                        break;
                    case Direction.Left: this.FrameLine = 2;
                        this.Effects = SpriteEffects.None;
                        break;
                    case Direction.Right: this.FrameLine = 2;
                        this.Effects = SpriteEffects.FlipHorizontally;
                        break;
                    case Direction.DownLeft: this.FrameLine = 4;
                        this.Effects = SpriteEffects.None;
                        break;
                    case Direction.UpRight: this.FrameLine = 5;
                        this.Effects = SpriteEffects.None;
                        break;
                    case Direction.UpLeft: this.FrameLine = 7;
                        this.Effects = SpriteEffects.None;
                        break;
                    case Direction.DownRight: this.FrameLine = 6;
                        this.Effects = SpriteEffects.None;
                        break;
                }
            }

            if (type == PlayerType.Ennemy)
            {
                if (ennemy.is_in_bound(hero.Hitbox.X, hero.Hitbox.Y))
                {
                    if (ennemy.IAHitbox.X > hero.Hitbox.X + hero.Hitbox.Width && ennemy.IAHitbox.Y > hero.Hitbox.Y
                        && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                        && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.X -= ennemy.PlayerSpeed;
                        ennemy.IAHitbox.Y -= ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.UpLeft;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.X < hero.Hitbox.X - hero.Hitbox.Width && ennemy.IAHitbox.Y > hero.Hitbox.Y
                        && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                        && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.X += ennemy.PlayerSpeed;
                        ennemy.IAHitbox.Y -= ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.UpRight;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.X > hero.Hitbox.X && ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height
                        && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                        && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.X -= ennemy.PlayerSpeed;
                        ennemy.IAHitbox.Y += ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.DownLeft;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.X < hero.Hitbox.X && ennemy.IAHitbox.Y < hero.Hitbox.Y - hero.Hitbox.Height
                        && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight)
                        && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.X += ennemy.PlayerSpeed;
                        ennemy.IAHitbox.Y += ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.DownRight;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.X > hero.Hitbox.X + hero.Hitbox.Width
                        && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.X -= ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.Left;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.X < hero.Hitbox.X - hero.Hitbox.Width
                        && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.X += ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.Right;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.Y > hero.Hitbox.Y /*+ hero.Hitbox.Height*/
                        && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.Y -= ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.Up;
                        ennemy.Animate();
                    }
                    else if (ennemy.IAHitbox.Y < hero.Hitbox.Y /*- hero.Hitbox.Height*/
                        && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        ennemy.IAHitbox.Y += ennemy.PlayerSpeed;
                        ennemy.Direction = Direction.Down;
                        ennemy.Animate();
                    }
                }
                else
                {
                    if (direc == 0 && Collisions.libreHeroRight(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        this.IAHitbox.X += this.Speed;
                        this.Direction = TLN_The_Last_Ninja.Direction.Right;
                        this.Animate();
                    }
                    if (direc == 1 && Collisions.libreHeroDown(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        this.IAHitbox.Y += this.Speed;
                        this.Direction = TLN_The_Last_Ninja.Direction.Down;
                        this.Animate();
                    }
                    if (direc == 2 && Collisions.libreHeroLeft(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        this.IAHitbox.X -= this.Speed;
                        this.Direction = TLN_The_Last_Ninja.Direction.Left;
                        this.Animate();
                    }
                    else if (direc == 3 && Collisions.libreHeroUp(this.IAHitbox, posTreeTab, posWaterTab, posStoneTab, posGateTab, spriteExample, listOfTextures, MaxWidth, MaxHeight))
                    {
                        this.IAHitbox.Y -= this.Speed;
                        this.Direction = TLN_The_Last_Ninja.Direction.Up;
                        this.Animate();
                    }
                }
            }
            switch (this.Direction) // switch = plusieurs if ici on donne l'effet inverse au sprite.
            {
                case Direction.Up: this.FrameLine = 3; // remplacer par les bons chiffres !
                    this.Effects = SpriteEffects.None;
                    break;
                case Direction.Down: this.FrameLine = 1;
                    this.Effects = SpriteEffects.None;
                    break;
                case Direction.Left: this.FrameLine = 2;
                    this.Effects = SpriteEffects.None;
                    break;
                case Direction.Right: this.FrameLine = 2;
                    this.Effects = SpriteEffects.FlipHorizontally;
                    break;
            }

            if (type == PlayerType.Munition)
            {
            }
        }