コード例 #1
0
ファイル: CollisionHandler.cs プロジェクト: skasti/Cells
        public virtual void HandleCollision(Organism self, GameObject other, float deltaTime)
        {
            if (Game1.Debug == self)
                Debug.WriteLine("[HandleCollision] " + StartIndex);

            for (int i = StartIndex; i < _updates.Count; i++)
            {
                i += _updates[i].Update(self, deltaTime);
            }

            if (Game1.Debug == self)
                Debug.WriteLine("[HandleCollision][FINISHED]");
        }
コード例 #2
0
ファイル: EatOrganisms.cs プロジェクト: skasti/Cells
        public override void HandleCollision(Organism self, GameObject other, float deltaTime)
        {
            StartIndex = 0;

            var prey = other as Organism;

            if (prey.Radius < self.Radius)
            {
                var distance = (self.Position - other.Position).Length();

                if (distance > self.Radius)
                {
                    StartIndex = _tooFarGoto;
                    self.Remember(_targetMemoryLocation, prey);
                }
                else
                {
                    var relativism = self.DNA.RelatedPercent(prey.DNA, _dnaSampleSize);

                    if (relativism < _relationThreshold)
                    {
                        if (Game1.Debug == self)
                            Debug.WriteLine("[EatOrganisms][CloseEnough] " + relativism);
                    }
                    else
                    {
                        if (Game1.Debug == self)
                            Debug.WriteLine("[EatOrganisms][IEatYou] " + relativism);
                        self.GiveEnergy(prey.TakeEnergy(self.Energy*deltaTime));
                    }
                }
            }
            else
            {
                StartIndex = _biggerGoto;
                self.Forget(_targetMemoryLocation);
            }

            base.HandleCollision(self, other, deltaTime);
        }
コード例 #3
0
ファイル: EatFood.cs プロジェクト: skasti/Cells
        public override void HandleCollision(Organism self, GameObject other, float deltaTime)
        {
            if (Game1.Debug == self)
                Debug.WriteLine("[EatFood][Collision] " + other.Position);

            StartIndex = 0;
            var food = other as Food;

            if (other.Alive)
            {
                var distance = (self.Position - other.Position).Length();

                if (distance < self.Radius + other.Bounds.Width*0.5f)
                {
                    if (Game1.Debug == self)
                        Debug.WriteLine("[EatFood][Eating]");
                    self.GiveEnergy(food.Energy);
                    other.Die(true);
                }
                else
                {
                    if (Game1.Debug == self)
                        Debug.WriteLine("[EatFood][TooFar]");
                    self.Remember(_targetMemoryLocation, food);

                    StartIndex = _tooFarGoto;
                }
            }
            else
            {
                if (Game1.Debug == self)
                    Debug.WriteLine("[EatFood][WasDead]");

                StartIndex = _deadGoto;
            }

            base.HandleCollision(self, other, deltaTime);
        }
コード例 #4
0
ファイル: GameObject.cs プロジェクト: skasti/Cells
 public virtual void HandleCollision(GameObject other, float deltaTime)
 {
 }