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