コード例 #1
0
ファイル: Element_Manager.cs プロジェクト: Jh87S/TLN
        /*public static Rectangle[] getrectTorcheTab(Vector2[] posTorcheTab, Texture2D _torche)
        {
            List<Rectangle> nouvList = new List<Rectangle>();
            foreach (Vector2 vect in posTorcheTab)
                nouvList.Add(new Rectangle((int)vect.X, (int)vect.Y, _torche.Width, _torche.Height));
            return nouvList.ToArray();
        }
           /*public static Rectangle[] getrectGargouilleTab(Vector2[] posGargouilleTab, Texture2D _gargouille)
        {
            List<Rectangle> nouvList = new List<Rectangle>();
            foreach (Vector2 vect in posGargouilleTab)
                nouvList.Add(new Rectangle((int)vect.X, (int)vect.Y, _gargouille.Width, _gargouille.Height));
            return nouvList.ToArray();
        }*/
        public static Element createElement(Element.ElementType type, Texture2D[] listOfTextures, Vector2 loc, Texture2D _waterExample, Rectangle[] waterRectTab, Texture2D _bridge, Background background)
        {
            Element nouvEl = new Element();
            nouvEl.Type = type;

            if (type == Element.ElementType.Null)
                nouvEl.Texture = listOfTextures[0];
            else if (type == Element.ElementType.Tree)
                nouvEl.Texture = listOfTextures[1];
            else if (type == Element.ElementType.Water)
                nouvEl.Texture = _waterExample;
            else if (type == Element.ElementType.Bridge)
                nouvEl.Texture = listOfTextures[3];
            /*else if (type == Element.ElementType.Gargouille)
                nouvEl.Texture = listOfTextures[5];*/
            else if (type == Element.ElementType.Torche)
                nouvEl.Texture = listOfTextures[6];
            else //if (type == Game1.ElementType.Stone)
                nouvEl.Texture = listOfTextures[4];

            if (nouvEl.Type == Element.ElementType.Tree)
                nouvEl.BeginningLocation = new Vector2(loc.X * Game1.caseWidth, + loc.Y * Game1.caseHeight - Game1.caseHeight);
            else if (nouvEl.Type == Element.ElementType.Stone)
                nouvEl.BeginningLocation = new Vector2(loc.X * Game1.caseWidth + Game1.caseWidth / 2 - nouvEl.Texture.Height / 2, loc.Y * Game1.caseHeight + Game1.caseHeight / 2 - nouvEl.Texture.Width / 2);
            else
                nouvEl.BeginningLocation = new Vector2(loc.X * Game1.caseWidth, loc.Y * Game1.caseHeight);

            return nouvEl;
        }
コード例 #2
0
ファイル: Map_Manager.cs プロジェクト: Jh87S/TLN
        public static Element[,] charMapToElementMap(char[,] charTab, Texture2D[] listOfTextures, Rectangle[] waterRectTab, Texture2D _bridge, Background background, Texture2D _waterExample)
        {
            Element[,] elementTab = new Element[charTab.GetLength(0), charTab.GetLength(1)];

            for (int x = 0; x < charTab.GetLength(0); x++)    //lignes
            {
                for (int y = 0; y < charTab.GetLength(1); y++)    //colonnes
                {
                    if (charTab[x, y] == '_')
                        elementTab[x, y] = Element_Manager.createElement(Element.ElementType.Null, listOfTextures, new Vector2(y, x), _waterExample, waterRectTab, _bridge, background);
                    else if (charTab[x, y] == 't')
                        elementTab[x, y] = Element_Manager.createElement(Element.ElementType.Tree, listOfTextures, new Vector2(y, x), _waterExample, waterRectTab, _bridge, background);
                    else if (charTab[x, y] == 's')
                        elementTab[x, y] = Element_Manager.createElement(Element.ElementType.Stone, listOfTextures, new Vector2(y, x), _waterExample, waterRectTab, _bridge, background);
                    else if (charTab[x, y] == 'w')
                        elementTab[x, y] = Element_Manager.createElement(Element.ElementType.Water, listOfTextures, new Vector2(y, x), _waterExample, waterRectTab, _bridge, background);
                    else if (charTab[x, y] == 'b')
                        elementTab[x, y] = Element_Manager.createElement(Element.ElementType.Bridge, listOfTextures, new Vector2(y, x), _waterExample, waterRectTab, _bridge, background);
                    else
                        throw new Exception();
                }
            }
            return elementTab;
        }
コード例 #3
0
ファイル: Background.cs プロジェクト: Jh87S/TLN
 //Functions:
 public static void draw(SpriteBatch spBatch, Background backG)
 {
     spBatch.Draw(backG.Texture, new Rectangle((int)backG.Location.X, (int)backG.Location.Y, backG.Texture.Width, backG.Texture.Height), Color.White);
 }
コード例 #4
0
ファイル: Map_Manager.cs プロジェクト: Jh87S/TLN
 public static Element[,] updateElementTab(Element[,] elementTab, Background backG)
 {
     foreach (Element elem in elementTab)
     {
         elem.UpdatedLocation = new Vector2(backG.Location.X + elem.BeginningLocation.X, backG.Location.Y + elem.BeginningLocation.Y);
     }
     return elementTab;
 }
コード例 #5
0
ファイル: Water_Texture_Manager.cs プロジェクト: Jh87S/TLN
 public static void setEveryWaterElementRectangle(ref Map map, Rectangle[] waterRectTab, Texture2D[] listOfTextures, Background backG)
 {
     foreach(Element elem in map.ElementTab)
             if (elem.Type == Element.ElementType.Water)
                 elem.SourceRectangle = Water_Texture_Manager.getWaterRectangle(elem.UpdatedLocation, waterRectTab, listOfTextures[2], map, listOfTextures[3]);
 }
コード例 #6
0
ファイル: Player.cs プロジェクト: Jh87S/TLN
        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)
            {
            }
        }