Example #1
0
        public Player()
        {
            // image de départ
            direction = Direction.RIGHT;
            framesIndex frameIndex = framesIndex.RIGHT_1;

            Source = new Rectangle((int)frameIndex * frameWidth, 0, frameWidth, frameHeight);

            // déterminer à quel indice d'image correspond le frameIndex et nous ajustons la valeur en fonction du résultat
            switch (direction)
            {
            case Direction.TOP:
                if (frameIndex == framesIndex.TOP_1)
                {
                    frameIndex = framesIndex.TOP_2;
                }
                else
                {
                    frameIndex = framesIndex.TOP_1;
                }
                break;

            case Direction.LEFT:
                if (frameIndex == framesIndex.LEFT_1)
                {
                    frameIndex = framesIndex.LEFT_2;
                }
                else
                {
                    frameIndex = framesIndex.LEFT_1;
                }
                break;

            case Direction.BOTTOM:
                if (frameIndex == framesIndex.BOTTOM_1)
                {
                    frameIndex = framesIndex.BOTTOM_2;
                }
                else
                {
                    frameIndex = framesIndex.BOTTOM_1;
                }
                break;

            case Direction.RIGHT:
                if (frameIndex == framesIndex.RIGHT_1)
                {
                    frameIndex = framesIndex.RIGHT_2;
                }
                else
                {
                    frameIndex = framesIndex.RIGHT_1;
                }
                break;
            }
        }
Example #2
0
        //Update !
        public void UpdateFrame(GameTime gameTime)
        {
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;

            while (time > frameTime)
            {
                if (movement)
                {
                    if (frameIndexWidth == framesIndex.Marche_1)
                    {
                        frameIndexWidth = framesIndex.Marche_2;
                    }
                    else if (frameIndexWidth == framesIndex.Marche_2)
                    {
                        frameIndexWidth = framesIndex.Marche_3;
                    }
                    else
                    {
                        frameIndexWidth = framesIndex.Marche_1;
                    }
                }
                else
                {
                    frameIndexWidth = framesIndex.Marche_2;
                }

                switch (direction)
                {
                case Direction.TOP:
                    frameIndexHeight = Direction.TOP;
                    break;

                case Direction.LEFT:
                    frameIndexHeight = Direction.LEFT;
                    break;

                case Direction.BOTTOM:
                    frameIndexHeight = Direction.BOTTOM;
                    break;

                case Direction.RIGHT:
                    frameIndexHeight = Direction.RIGHT;
                    break;
                }

                time = 0f;
            }

            Source = new Rectangle(
                (int)frameIndexWidth * frameWidth + 32 * startX * 3,
                (int)frameIndexHeight * frameHeight + 32 * startX * 4,
                frameWidth,
                frameHeight);
        }
Example #3
0
        //calcul du temps passé pour savoir quand changer d'animation
        public void UpdateFrame(GameTime gameTime)
        {
            switch (direction)
            {
            case Direction.TOP:
                if (frameIndex == framesIndex.TOP_1)
                {
                    frameIndex = framesIndex.TOP_2;
                }
                else
                {
                    frameIndex = framesIndex.TOP_1;
                }
                break;

            case Direction.LEFT:
                if (frameIndex == framesIndex.LEFT_1)
                {
                    frameIndex = framesIndex.LEFT_2;
                }
                else
                {
                    frameIndex = framesIndex.LEFT_1;
                }
                break;

            case Direction.BOTTOM:
                if (frameIndex == framesIndex.BOTTOM_1)
                {
                    frameIndex = framesIndex.BOTTOM_2;
                }
                else
                {
                    frameIndex = framesIndex.BOTTOM_1;
                }
                break;

            case Direction.RIGHT:
                if (frameIndex == framesIndex.RIGHT_1)
                {
                    frameIndex = framesIndex.RIGHT_2;
                }
                else
                {
                    frameIndex = framesIndex.RIGHT_1;
                }
                break;
            }
            //selon tuto
            Source = new Rectangle((int)frameIndex * frameWidth, 0, frameWidth, frameHeight);
        }
Example #4
0
        public void UpdateFrame(GameTime gameTime)
        {
            //permet de calculer le temps passé depuis notre dernière mise à jour de l'affichage de notre sprite
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;

            // prochain indice de l'image si nous avons dépassé le temps d'affichage puis, on remet à zéro
            // la variable time pour la réutiliser correctement pour la prochaine mise à jour.
            while (time > frameTime)
            {
                switch (direction)
                {
                case Collision.Direction.TOP:
                    if (frameIndex == framesIndex.TOP_1)
                    {
                        frameIndex = framesIndex.TOP_2;
                    }
                    else
                    {
                        frameIndex = framesIndex.TOP_1;
                    }
                    break;

                case Collision.Direction.LEFT:
                    if (frameIndex == framesIndex.LEFT_1)
                    {
                        frameIndex = framesIndex.LEFT_2;
                    }
                    else
                    {
                        frameIndex = framesIndex.LEFT_1;
                    }
                    break;

                case Collision.Direction.BOTTOM:
                    if (frameIndex == framesIndex.BOTTOM_1)
                    {
                        frameIndex = framesIndex.BOTTOM_2;
                    }
                    else
                    {
                        frameIndex = framesIndex.BOTTOM_1;
                    }
                    break;

                case Collision.Direction.RIGHT:
                    if (frameIndex == framesIndex.RIGHT_1)
                    {
                        frameIndex = framesIndex.RIGHT_2;
                    }
                    else
                    {
                        frameIndex = framesIndex.RIGHT_1;
                    }
                    break;
                }
                time = 0f;
            }
            // Si l'indice dépasse le nombre de sprites dans notre collection, on repasse au premier.

            //calcul de la position du nouveau sprite à afficher en déterminant sa position par rapport à l'indice en cours
            Source = new Rectangle((int)frameIndex * frameWidth, 0, frameWidth, frameHeight);
        }
Example #5
0
 //calcul du temps passé pour savoir quand changer d'animation
 public void UpdateFrame(GameTime gameTime)
 {
     switch (direction)
     {
         case Direction.TOP:
             if (frameIndex == framesIndex.TOP_1)
                 frameIndex = framesIndex.TOP_2;
             else
                 frameIndex = framesIndex.TOP_1;
             break;
         case Direction.LEFT:
             if (frameIndex == framesIndex.LEFT_1)
                 frameIndex = framesIndex.LEFT_2;
             else
                 frameIndex = framesIndex.LEFT_1;
             break;
         case Direction.BOTTOM:
             if (frameIndex == framesIndex.BOTTOM_1)
                 frameIndex = framesIndex.BOTTOM_2;
             else
                 frameIndex = framesIndex.BOTTOM_1;
             break;
         case Direction.RIGHT:
             if (frameIndex == framesIndex.RIGHT_1)
                 frameIndex = framesIndex.RIGHT_2;
             else
                 frameIndex = framesIndex.RIGHT_1;
             break;
     }
     //selon tuto
     Source = new Rectangle((int)frameIndex * frameWidth, 0, frameWidth, frameHeight);
 }