public void UpdateCreaturePhysics() { float[] previousOutput = brain.GetOutput(); HSBColor bodyTileColor = map.GetColor((int)base.position.x, (int)base.position.y); HSBColor leftTileColor = map.GetColor((int)leftPos.x, (int)leftPos.y); HSBColor rightTileColor = map.GetColor((int)rightPos.x, (int)rightPos.y); bool spikeTargetFound = false; float spikeValue = -1; Creature_V2 spikeCreature = null; List <Creature_V2> creatureListAtTile = map.ExistCreaturesNearTile((int)base.position.x, (int)base.position.y); float[] sensorDistance = new float[4]; for (int i = 0; i < sensorPos.Length; i++) { sensorValue[i] = -1f; sensorDistance[i] = -1f; if (creatureListAtTile != null) { for (int j = 0; j < creatureListAtTile.Count; j++) { Creature_V2 creature = creatureListAtTile[j]; if (!creature.Equals(this)) { float distance; if (spikeTargetFound == false) { distance = creature.IsLineIntersectingWithCircle(base.position, spikePos); if (distance != -1f) { spikeCreature = creature; spikeValue = spikeCreature.bodyColor.h; spikeTargetFound = true; } } distance = creature.IsLineIntersectingWithCircle(base.position, sensorPos[i]); if (distance != -1f) { sensorValue[i] = creature.bodyColor.h; sensorDistance[i] = distance; break; } } } } } List <Creature_V2> creatureListAtBodyTile = map.ExistCreaturesNearPrecisionTile(base.position.x, base.position.y, base.radius); List <Creature_V2> creaturesInBirthRange = new List <Creature_V2>(); float hueAverage = -1f; float isCollision = -1f; //check for left sensor collision if (creatureListAtBodyTile != null) { for (int i = 0; i < creatureListAtBodyTile.Count; i++) { Creature_V2 creature = creatureListAtBodyTile[i]; if (!creature.Equals(this)) { if (creature.CollisionCheckWithCircle(radius, base.position) == true) { hueAverage += creature.bodyColor.h; isCollision++; creaturesInBirthRange.Add(creature); } else if (creature.CollisionCheckWithCircle(radius * 2f, base.position)) { creaturesInBirthRange.Add(creature); } } } } if (isCollision >= 0) { isCollision++; hueAverage = hueAverage / isCollision; isCollision = 1f; } float[] output = brain.Feedforward(new float[] { sensorDistance[0], sensorDistance[1], sensorDistance[2], sensorDistance[3], sensorValue[0], sensorValue[1], sensorValue[2], sensorValue[3], spikeValue, isCollision, hueAverage, bodyTileColor.h, bodyTileColor.s, leftTileColor.h, leftTileColor.s, rightTileColor.h, rightTileColor.s, base.radius /*energy.GetLife()/2f, energy.GetEnergy()/25f*/, previousOutput[7], previousOutput[8] }); float accelForward = output[0]; float accelAngular = output[1]; float bodyHue = output[2]; float mouthHue = output[3]; if (output[6] >= 0) { spikeLength = output[6]; } else { spikeLength = 0; } if (bodyHue >= 0) { this.bodyColor.h = bodyHue; } if (mouthHue >= 0) { this.mouthColor.h = mouthHue; } map.RemoveCreatureFromTileList(tileDetail[0], tileDetail[1], this); base.UpdateColliderPhysics(accelForward, accelAngular); UpdateSensors(); //copy tile detail tileDetail[0] = (int)base.position.x; tileDetail[1] = (int)base.position.y; map.AddCreatureToTileList(tileDetail[0], tileDetail[1], this); energy.UpdateCreatureEnergy(tileDetail[0], tileDetail[1], output, bodyTileColor.h, mouthColor.h, spikeCreature); if (energy.GetEnergy() < 1f) { base.radius = initialRadius - ((1f - energy.GetEnergy()) * (initialRadius / 2)); } else { base.radius = initialRadius + (energy.GetEnergy() * 0.0025f); } // Creature is dead ;( D: :( -_- ;_; if (energy.IsAlive() == false) { Kill(); } else if (energy.GiveBirth() == true) { energy.DoneBirth(); world.CreateCreature(this); } else if (energy.IsAbleToGiveBirth() == true) { for (int i = 0; i < creaturesInBirthRange.Count; i++) { Creature_V2 creature = creaturesInBirthRange[i]; if (creature.energy.IsAbleToGiveBirth()) { energy.RemoveEnergy(1f); creature.energy.RemoveEnergy(1f); energy.DoneBirth(); creature.energy.DoneBirth(); world.CreateCreature(this, creature); break; } else { energy.RemoveEnergy(1.25f); creature.energy.RemoveEnergy(0.25f); energy.DoneBirth(); creature.energy.DoneBirth(); world.CreateCreature(this, creature); break; } } } timeLived += worldDeltaTime; }