Exemplo n.º 1
0
 public Vector2 react(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     Vector2 result = me.AnimalSpec.MemberSensitivity * you.Direction;
     float len = result.Length();
     Debug.Assert(0 < len && len < 1e4);
     return result;
 }
Exemplo n.º 2
0
 public IEnumerable<Animal> findNeighbors(Animal cnt)
 {
     IEnumerable<Animal> seq;
     float dst = cnt.AnimalSpec.DetectionDistance;
     seq = Grid.encompassNeighbors(cnt, dst);
     return seq;
 }
Exemplo n.º 3
0
 public override void aimAt(Animal someone, float sdist, ref Animal target, ref float tdist)
 {
     if (sdist < tdist && someone.AnimalType == AnimalType.Fish) {
         target = someone;
         tdist = sdist;
     }
 }
Exemplo n.º 4
0
 public Vector2 react(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     Vector2 result = me.Direction * me.AnimalSpec.InertiaDirectionSensitivity;
     float len = result.Length();
     Debug.Assert(0 < len && len < 1e5);
     return result;
 }
Exemplo n.º 5
0
 public override void aimAt(Animal someone, float sdist, ref Animal target, ref float tdist)
 {
     if (sdist < tdist) {
         target = someone;
         tdist = sdist;
     }
 }
Exemplo n.º 6
0
 public Vector2 react(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     float weight = me.AnimalSpec.MemberSensitivity
         * (1 - dist / me.AnimalSpec.SeparationDistance);
     Vector2 result = dir * -weight;
     float len = result.Length();
     Debug.Assert(0 < len && len < 1e5);
     return result;
 }
Exemplo n.º 7
0
 public Vector2 react(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     float angle = (float)rand.NextDouble() * MathHelper.TwoPi;
     float ratio = me.AnimalSpec.RandomDirectionSensitivity;
     Vector2 result =
         new Vector2(ratio * (float)Math.Cos(angle), ratio * (float)Math.Sin(angle));
     float len = result.Length();
     Debug.Assert(0 < len && len < 1e5);
     return result;
 }
Exemplo n.º 8
0
 public Vector2 react(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     Vector2 result = dir * -me.AnimalSpec.AlienSensitivity;
     float len = result.Length();
     //acclerate radialspeed
     if (me.RadialVelocity - FishSpec.RadialVelocityOriginal < 20)
     {
         me.RadialVelocity *= 10.0f;
     }
     Debug.Assert(0 < len && len < 1e5);
     return result;
 }
Exemplo n.º 9
0
 public virtual void reactTo(Animal you, ref Animal target, ref float tdist, ref Vector2 newDir)
 {
     if (this == you)
         return;
     Vector2 dir = you.Position - Position;
     float dist = dir.Length();
     if (!(0.01f < dist && dist < AnimalSpec.DetectionDistance))
         return;
     aimAt(you, dist, ref target, ref tdist);
     dir.Normalize();
     foreach (Behavior bhv in Behaviors) {
         if (bhv.isReactive(this, you, ref dir, dist))
             newDir += bhv.react(this, you, ref dir, dist);
     }
 }
Exemplo n.º 10
0
 public bool isReactive(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     return (you.AnimalType == AnimalType.Fish)
         && (dist < me.AnimalSpec.DetectionDistance);
 }
Exemplo n.º 11
0
 public abstract void updateColor(Animal nearest, float dist);
Exemplo n.º 12
0
 public void add(Animal newOne)
 {
     int pos = index(newOne.Position);
     Cells[pos].AddFirst(newOne);
 }
Exemplo n.º 13
0
 public override void updateColor(Animal nearest, float dist)
 {
     float weight = dist / AnimalSpec.SeparationDistance;
     Color = new Color(1f, weight, weight);
 }
Exemplo n.º 14
0
 public bool isReactive(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     return (me.AnimalType == you.AnimalType);
 }
Exemplo n.º 15
0
        public IEnumerable<Animal> encompassNeighbors(Animal cnt, float dist)
        {
            List<Animal> ngh = new List<Animal>();
            Vector2 offset = new Vector2(dist, dist);
            int minx, miny;
            resolve(cnt.Position - offset, out minx, out miny);
            int maxx, maxy;
            resolve(cnt.Position + offset, out maxx, out maxy);

            for (int y = miny; y <= maxy; y++) {
                for (int x = minx; x <= maxx; x++) {
                    if (isCollide(cnt.Position, dist, x, y) == false)
                        continue;
                    int pos = index(x,y);
                    ngh.AddRange(Cells[pos]);
                }
            }

            return ngh;
        }
Exemplo n.º 16
0
 public void move(Animal anm, Vector2 newPos)
 {
     Grid.remove(anm);
     anm.Position = newPos;
     Grid.add(anm);
 }
Exemplo n.º 17
0
 public void remove(Animal oldone)
 {
     AnimalList.Remove(oldone);
     Grid.remove(oldone);
 }
Exemplo n.º 18
0
 public bool remove(Animal oldOne)
 {
     int pos = index(oldOne.Position);
     return Cells[pos].Remove(oldOne);
 }
Exemplo n.º 19
0
 public Compass(Animal a, int q)
 {
     this.anm = a;
     this.quad = q;
 }
Exemplo n.º 20
0
 public abstract void aimAt(Animal someone, float sdist, ref Animal target, ref float tdist);
Exemplo n.º 21
0
 public bool isReactive(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     return true;
 }
Exemplo n.º 22
0
 public bool isReactive(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     return (me.AnimalType == you.AnimalType)
         && (dist > me.AnimalSpec.SeparationDistance);
 }
Exemplo n.º 23
0
 public void add(Animal newone)
 {
     AnimalList.Add(newone);
     Grid.add(newone);
 }
Exemplo n.º 24
0
 public bool isReactive(Animal me, Animal you, ref Vector2 dir, float dist)
 {
     return (you.AnimalType == AnimalType.Whale) && you.bActive == true
         && (dist < me.AnimalSpec.AlienSeparationDistance);
 }