Пример #1
0
        public void MoveGamePad(GamePadEvent manette, int height, int width, List<Zombie> zombies)
        {
            direction.X = manette.GetLeftStick().X;
            direction.Y = -manette.GetLeftStick().Y;

            // sprint
            if (manette.IsPressed(Buttons.A))
                SetSpeed(4);
            else
                SetSpeed(2);

            //colission avec zombies
            foreach (Zombie z in zombies)
            {
                if (!z.GetDead())
                {
                    if (target.Intersects(z.GetRectangle()))
                    {
                        //a gauche
                        if (target.X >= (z.GetRectangle().X - target.Width) && target.X <= (z.GetRectangle().X - target.Width + 5) && direction.X > 0)
                        {
                            direction.X = 0;
                        }
                        //a droite
                        if (target.X <= z.GetRectangle().X + z.GetRectangle().Width && target.X >= z.GetRectangle().X + z.GetRectangle().Width - 5 && direction.X < 0)
                        {
                            direction.X = 0;
                        }
                        //en haut
                        if (target.Y >= (z.GetRectangle().Y - target.Height) && target.Y <= (z.GetRectangle().Y - target.Height + 5) && direction.Y > 0)
                        {
                            direction.Y = 0;
                        }
                        //en bas
                        if (target.Y <= z.GetRectangle().Y + z.GetRectangle().Height && target.Y >= z.GetRectangle().Y + z.GetRectangle().Height - 5 && direction.Y < 0)
                        {
                            direction.Y = 0;
                        }
                    }
                }
            }

            //SetPosition(position + (direction * speed));

            if (position.Y + rectangle.Height >= height)
                position.Y = height - rectangle.Height;
            else
                if (position.Y <= 0)
                    position.Y = 0;

            if (position.X + rectangle.Width >= width)
                position.X = width - rectangle.Width;
            else
                if (position.X <= 0)
                    position.X = 0;
            SetRectangle();
            SetTarget();
        }