Пример #1
0
 public override Vector2 Avoid(Bloid bloid)
 {
     /*     float a = bloid.getMotion().Y;
      *   float b = -bloid.getMotion().X;
      *   float c = a * bloid.getLocation().X + b * bloid.getLocation().Y;
      *   float d = -b;
      *   float e = a;
      *   float f = d * position.X + e * position.Y;
      *   float x = (f * b - c * e) / (d * b - a * e);
      *   float y = (c - a * x) / b;
      *   Vector2 collision = new Vector2(x, y);
      *   collision -= position;
      *
      *   Vector2 z = new Vector2(0, 0);
      *
      *   Vector2 i = position - bloid.getLocation();
      *   if ((i).X * i.X + i.Y * i.Y < bloid.getAvoidRange() && (collision).X * collision.X + collision.Y * collision.Y < rayon * rayon + 2 && (x - position.X) / bloid.getMotion().X > 0 && (y - position.Y) / bloid.getMotion().Y > 0)
      *   {
      *
      *       if ((collision.Y - position.Y) / (-d) > 0 && (collision.X - position.X) / (e) > 0)
      *       {
      *           z = new Vector2(e, d);
      *       }
      *       else
      *       {
      *           z = new Vector2(e, -d);
      *       }
      *
      *       z.Normalize();
      *
      *   }
      *   return z;*/
     return(new Vector2(0, 0));
 }
Пример #2
0
        public override Vector2 Avoid(Bloid bloid)
        {
            /*     float a = bloid.getMotion().Y;
            float b = -bloid.getMotion().X;
            float c = a * bloid.getLocation().X + b * bloid.getLocation().Y;
            float d = -b;
            float e = a;
            float f = d * position.X + e * position.Y;
            float x = (f * b - c * e) / (d * b - a * e);
            float y = (c - a * x) / b;
            Vector2 collision = new Vector2(x, y);
            collision -= position;

            Vector2 z = new Vector2(0, 0);

            Vector2 i = position - bloid.getLocation();
            if ((i).X * i.X + i.Y * i.Y < bloid.getAvoidRange() && (collision).X * collision.X + collision.Y * collision.Y < rayon * rayon + 2 && (x - position.X) / bloid.getMotion().X > 0 && (y - position.Y) / bloid.getMotion().Y > 0)
            {

                if ((collision.Y - position.Y) / (-d) > 0 && (collision.X - position.X) / (e) > 0)
                {
                    z = new Vector2(e, d);
                }
                else
                {
                    z = new Vector2(e, -d);
                }

                z.Normalize();

            }
            return z;*/
            return new Vector2(0, 0);
        }
Пример #3
0
        public virtual void Collide(Bloid bloid)
        {
            Vector2 d = position-(bloid.getPosition() + bloid.getMotion());
            double dis = d.X * d.X + d.Y * d.Y;
            if (dis < rayon * rayon + 10)
            {

                double j = (d.Y * bloid.getMotion().Y + d.X * bloid.getMotion().X) / (d.X * d.X + d.Y * d.Y);
                if(j>0)
                    bloid.setMotion(bloid.getMotion()-(new Vector2((float)j*d.X,(float)j*d.Y)));

            }
        }
Пример #4
0
        public virtual void Collide(Bloid bloid)
        {
            Vector2 d   = position - (bloid.getPosition() + bloid.getMotion());
            double  dis = d.X * d.X + d.Y * d.Y;

            if (dis < rayon * rayon + 10)
            {
                double j = (d.Y * bloid.getMotion().Y + d.X * bloid.getMotion().X) / (d.X * d.X + d.Y * d.Y);
                if (j > 0)
                {
                    bloid.setMotion(bloid.getMotion() - (new Vector2((float)j * d.X, (float)j * d.Y)));
                }
            }
        }
Пример #5
0
 public override Vector2 Fear(Bloid bloid)
 {
     Vector2 d = bloid.getPosition() - position;
     float dis = d.Length();
     if (dis < rayon*3)
     {
         if (dis < rayon)
         {
             bloid.kill();
         }
         else
         {
             d.Normalize();
             d.X *= 5;
             d.Y *= 5;
         }
     }
     else
     {
         d = new Vector2(0, 0);
     }
     return d;
 }
Пример #6
0
        public override Vector2 Fear(Bloid bloid)
        {
            Vector2 d   = bloid.getPosition() - position;
            float   dis = d.Length();

            if (dis < rayon * 3)
            {
                if (dis < rayon)
                {
                    bloid.kill();
                }
                else
                {
                    d.Normalize();
                    d.X *= 5;
                    d.Y *= 5;
                }
            }
            else
            {
                d = new Vector2(0, 0);
            }
            return(d);
        }
Пример #7
0
        public override void Collide(Bloid bloid)
        {
            int x, y;
            if (bloid.getPosition().X > rect.Left)
            {
                if (bloid.getPosition().X > rect.Right)
                {
                    x = 1;
                }
                else
                {
                    x = 0;
                }

            }
            else
            {
                x = -1;
            }
            if (bloid.getPosition().Y> rect.Top)
            {
                if (bloid.getPosition().Y > rect.Bottom)
                {
                    y = 1;
                }
                else
                {
                    y = 0;
                }

            }
            else
            {
                y = -1;
            }

            switch (x)
            {
                case -1:
                    switch (y)
                    {
                        case -1:
                            break;
                        case 0:
                            if (bloid.getPosition().X + bloid.getMotion().X>rect.Left&&bloid.getMotion().X>0)
                            {
                                bloid.setMotion(new Vector2(0,bloid.getMotion().Y));
                            }
                            break;
                        case 1:
                            break;
                    }
                    break;
                case 0:
                    switch (y)
                    {
                        case -1:
                            if (bloid.getPosition().Y + bloid.getMotion().Y > rect.Top && bloid.getMotion().Y > 0)
                            {
                                bloid.setMotion(new Vector2(bloid.getMotion().X,0));
                            }
                            break;
                        case 0:
                            break;
                        case 1:
                            if (bloid.getPosition().Y + bloid.getMotion().Y < rect.Bottom && bloid.getMotion().Y <0)
                            {
                                bloid.setMotion(new Vector2(bloid.getMotion().X, 0));
                            }
                            break;
                    }
                    break;
                case 1:
                    switch (y)
                    {
                        case -1:
                            break;
                        case 0:
                            if (bloid.getPosition().X + bloid.getMotion().X < rect.Right && bloid.getMotion().X < 0)
                            {
                                bloid.setMotion(new Vector2(0, bloid.getMotion().Y));
                            }
                            break;
                        case 1:
                            break;
                    }
                    break;

            }
        }
Пример #8
0
 public override Vector2 Fear(Bloid bloid)
 {
     return new Vector2 (0,0);
 }
Пример #9
0
        public override void Collide(Bloid bloid)
        {
            int x, y;

            if (bloid.getPosition().X > rect.Left)
            {
                if (bloid.getPosition().X > rect.Right)
                {
                    x = 1;
                }
                else
                {
                    x = 0;
                }
            }
            else
            {
                x = -1;
            }
            if (bloid.getPosition().Y > rect.Top)
            {
                if (bloid.getPosition().Y > rect.Bottom)
                {
                    y = 1;
                }
                else
                {
                    y = 0;
                }
            }
            else
            {
                y = -1;
            }

            switch (x)
            {
            case -1:
                switch (y)
                {
                case -1:
                    break;

                case 0:
                    if (bloid.getPosition().X + bloid.getMotion().X > rect.Left && bloid.getMotion().X > 0)
                    {
                        bloid.setMotion(new Vector2(0, bloid.getMotion().Y));
                    }
                    break;

                case 1:
                    break;
                }
                break;

            case 0:
                switch (y)
                {
                case -1:
                    if (bloid.getPosition().Y + bloid.getMotion().Y > rect.Top && bloid.getMotion().Y > 0)
                    {
                        bloid.setMotion(new Vector2(bloid.getMotion().X, 0));
                    }
                    break;

                case 0:
                    break;

                case 1:
                    if (bloid.getPosition().Y + bloid.getMotion().Y < rect.Bottom && bloid.getMotion().Y < 0)
                    {
                        bloid.setMotion(new Vector2(bloid.getMotion().X, 0));
                    }
                    break;
                }
                break;

            case 1:
                switch (y)
                {
                case -1:
                    break;

                case 0:
                    if (bloid.getPosition().X + bloid.getMotion().X < rect.Right && bloid.getMotion().X < 0)
                    {
                        bloid.setMotion(new Vector2(0, bloid.getMotion().Y));
                    }
                    break;

                case 1:
                    break;
                }
                break;
            }
        }
Пример #10
0
 public override Vector2 Fear(Bloid bloid)
 {
     return(new Vector2(0, 0));
 }
Пример #11
0
 public virtual Vector2 Fear(Bloid bloid)
 {
     return(new Vector2(0, 0));
 }
Пример #12
0
 public virtual Vector2 Fear(Bloid bloid)
 {
     return new Vector2(0, 0);
 }