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)));

            }
        }
Exemple #2
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)));
                }
            }
        }
 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;
 }
Exemple #4
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);
        }
        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;

            }
        }
Exemple #6
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;
            }
        }