コード例 #1
0
        public void Move(Joueur joueur, List<Zombie> zombies, int elapsed_time, int height, int width)
        {
            direction = (new Vector2(joueur.GetRectangle().X, joueur.GetRectangle().Y) - position) / ((new Vector2(joueur.GetRectangle().X, joueur.GetRectangle().Y) - position).Length()) + (Game1.map.GetDirection() * Game1.map.GetSpeed());

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

            if (!target.Intersects(joueur.GetTarget()))
            {
                SetPosition(position + (direction * speed));
            }
            else
            {
                if (attack_cooldown == 0 || attack_cooldown >= 1000)
                {
                    Attack(joueur);
                    attack_cooldown = 0;
                }
            }
            attack_cooldown += elapsed_time;

            SetRectangle();
            SetTarget();
        }