コード例 #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 60.0f);

            foreach (Map map in maps)
            {
                if (map.topHitBox.Intersects(perso.getPersoHitBox()) && perso.getPersoPos().Y > limiteSaut)
                {
                    // Si le personnage touche la map ET que sa position est plus basse que sa limite de saut c'est qu'il a touché le sol ALORS
                    // Il marche
                    // Il peut à nouveau sauter
                    perso.walking = true;
                    perso.canJump = true;
                    b             = false;
                    break;
                }



                if (perso.getPersoPos().Y <= limiteSaut || map.topHitBox.Intersects(perso.getPersoHitBox()) || vitChutte == 2)
                {
                    // Si le perso atteint pu dépasse sa limite de saut OU si il touche la map, il ne saute plus. (ou si on presse s)
                    perso.jump(false);
                }
            }

            if (!perso.isJumpingOrNot())
            {
                for (int i = 0; i < 10 * vitChutte; i++)
                {
                    foreach (Map map in maps)
                    {
                        if (!map.topHitBox.Intersects(perso.getPersoHitBox()))
                        {
                            b = true;
                        }
                        else
                        {
                            b = false;
                            break;
                        }
                    }
                    if (b)
                    {
                        if (refreshImages)
                        {
                            perso.movePerso(new Vector2(perso.getPersoPos().X, perso.getPersoPos().Y + 1));
                        }
                    }
                }
            }

            if (perso.isJumpingOrNot())
            {
                for (int i = 0; i < 6; i++)
                {
                    foreach (Map map in maps)
                    {
                        if (!map.botHitBox.Intersects(perso.getPersoHitBox()))
                        {
                            t = true;
                        }
                        else
                        {
                            t = false;
                            b = true;
                            break;
                        }
                    }
                    if (t)
                    {
                        if (refreshImages)
                        {
                            perso.movePerso(new Vector2(perso.getPersoPos().X, perso.getPersoPos().Y - 1));
                        }
                    }
                }
            }
            uInput();
            base.Update(gameTime);
        }