Beispiel #1
0
        public void Update(KeyboardState clavier, GameWindow window, PersonnageJouable perso)
        {
            #region miseajourdonnees
            ///////////////////Joueur//////////////////////////////////////
            Rectangle positionjoueur = perso._rectangle;
            ///////////////////Taille fenetre//////////////////////////////
            int largeur = window.ClientBounds.Width;
            int hauteur = window.ClientBounds.Height;
            ///////////////////Touche clavier//////////////////////////////
            bool toucheup = clavier.IsKeyDown(Keys.Up) && !(clavier.IsKeyDown(Keys.Down) && clavier.IsKeyDown(Keys.Left) && clavier.IsKeyDown(Keys.Right));
            bool touchedown = clavier.IsKeyDown(Keys.Down) && !(clavier.IsKeyDown(Keys.Up) && clavier.IsKeyDown(Keys.Left) && clavier.IsKeyDown(Keys.Right));
            bool toucheleft = clavier.IsKeyDown(Keys.Left) && !(clavier.IsKeyDown(Keys.Down) && clavier.IsKeyDown(Keys.Up) && clavier.IsKeyDown(Keys.Right));
            bool toucheright = clavier.IsKeyDown(Keys.Right) && !(clavier.IsKeyDown(Keys.Down) && clavier.IsKeyDown(Keys.Left) && clavier.IsKeyDown(Keys.Up));
            ///////////////////////////////////////////////////////////////
            #endregion

            courseactive = clavier.IsKeyDown(Keys.LeftShift);

            #region Valeur de deplacement
                int deplacement;

                if (courseactive)
                {
                    deplacement = 4;
                }

                else
                {
                    deplacement = 2;
                }
            #endregion

            #region Haut
            if (toucheup)
                {
                    if (ymap < 0 && !perso.dplcmtbas && !perso.blochaut)
                    {
                        ymap += deplacement;
                        limitehaute = false;
                    }
                }

                if (ymap >= 0)
                {
                    limitehaute = true;
                }
                #endregion

            #region Bas
                if (-ymap >= -hauteur + ymax || (ymax < hauteur))
                {
                    limitebasse = true;
                }

                if (touchedown)
                {
                    if (-hauteur + ymax > -ymap && !(ymax < hauteur) && !perso.dplcmthaut && !perso.blocbas)
                    {
                        ymap -= deplacement;
                        limitebasse = false;
                    }
                }

                #endregion

            #region Gauche
                if (toucheleft)
                {
                    if (xmap < 0 && !perso.dplcmtdroite && !perso.blocgauche)
                    {
                        xmap += deplacement;
                        limitegauche = false;
                    }
                }

                if (xmap >= 0)
                {
                    limitegauche = true;
                }
                #endregion

            #region Droite
                if (toucheright)
                {
                    if (xmap > largeur - xmax + 40 && !(xmax < largeur) && !perso.dplcmtgauche && !perso.blocdroit)
                    {
                        xmap -= deplacement;
                        limitedroite = false;
                    }
                }

                if (xmap <= largeur - xmax + 40 || xmax < largeur)
                {
                    limitedroite = true;
                }
                #endregion

            #region affichage collision
            if (clavier.IsKeyDown(Keys.C))
            {
                touchecol = true;
            }

            if(clavier.IsKeyUp(Keys.C) && touchecol)
            {
                touchecol = false;
                affichecol = !affichecol;
            }
            #endregion

            perso.Deplacement(limitehaute, limitebasse, limitegauche, limitedroite, clavier, window);
        }