Ejemplo n.º 1
0
        public int Update(Organism self, float deltaTime)
        {
            if (Game1.Debug == self)
                Debug.WriteLine("[ChaseObject] " + _targetMemoryLocation.ToString("X2"));

            var target = self.Remember<GameObject>(_targetMemoryLocation);

            if (target == null)
                return 0;

            if (target.Removed)
            {
                if (Game1.Debug == self)
                    Debug.WriteLine("[ChaseGameObject][Forget]" + _targetMemoryLocation.ToString("X2"));
                self.Forget(_targetMemoryLocation);
                return 0;
            }

            if (Game1.Debug == self)
                Debug.WriteLine("[ChaseObject][Chasing] " + target.Position);

            var direction = target.Position - self.Position;
            direction.Normalize();
            direction *= _desiredSpeed;

            self.Force = (direction / deltaTime) * self.Mass;

            if (Game1.Debug == self)
                Debug.WriteLine("[ChaseObject][Force] " + self.Force);

            return 1;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public int Update(Organism self, float deltaTime)
        {
            if (Game1.Debug == self)
            {
                Debug.WriteLine("[AvoidObject] " + _targetMemoryLocation.ToString("X2"));
            }

            var target = self.Remember <GameObject>(_targetMemoryLocation);

            if (target == null)
            {
                return(0);
            }

            if (target.Removed)
            {
                if (Game1.Debug == self)
                {
                    Debug.WriteLine("[AvoidObject][Forget]" + _targetMemoryLocation.ToString("X2"));
                }
                self.Forget(_targetMemoryLocation);
                return(0);
            }

            if (Game1.Debug == self)
            {
                Debug.WriteLine("[AvoidObject][Avoiding] " + target.Position);
            }

            var direction = self.Position - target.Position;

            direction.Normalize();
            direction *= _desiredSpeed;

            self.Force = (direction / deltaTime) * self.Mass;

            if (Game1.Debug == self)
            {
                Debug.WriteLine("[AvoidObject][Force] " + self.Force);
            }

            return(1);
        }
Ejemplo n.º 4
0
        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);
        }