Beispiel #1
0
        public void updateAcceleration(List<Bloid>[] neighbours, Obstacle[] o)
        {
            acceleration.X = 0;
            acceleration.Y = 0;
            Vector2 f = Flock(neighbours);
            Vector2 i = Interract(o);
            Vector2 a = AttactMouse();

            acceleration += i;
            acceleration += f;
            acceleration += a;
        }
Beispiel #2
0
 public void updateMotion(Obstacle[] o)
 {
     motion += acceleration;
     foreach (Obstacle obs in o)
     {
         obs.Collide(this);
     }
     if (motion.X*motion.X+motion.Y*motion.Y > maxSpeed)
     {
         motion.Normalize();
         motion.X *= maxSpeed;
         motion.Y *= maxSpeed;
     }
 }
Beispiel #3
0
        public Vector2 Interract(Obstacle[] o)
        {
            int count = 0;
            Vector2 sum = new Vector2(0, 0);

            foreach (Obstacle obs in o)
            {
                Vector2 z = obs.Avoid(this);

                if (z.X != 0 && z.Y != 0)
                {
                    sum += z*avoidWeight;
                    count++;
                }
                Vector2 d = obs.Fear(this);

                if (d.X != 0 && d.Y != 0)
                {
                    sum += d*fearWeight;
                    count++;
                }
            }

            if (count > 0)
            {
                sum.X /= count;
                sum.Y /= count;
            }

            return sum;
        }