Exemple #1
0
        public int moveForward(Organism target, int index)
        {
            double cost = 0.25 * energyMod;

            Point proposedPosition = new Point();

            proposedPosition.X = target.getPosition().X + (Math.Sin(target.getAngle()) * target.getSpeed() * moveMod);
            proposedPosition.Y = target.getPosition().Y + (Math.Cos(target.getAngle()) * target.getSpeed() * moveMod);

            if(proposedPosition.X < world.getWorldSize().X & proposedPosition.X > 0)
            {
                if(proposedPosition.Y < world.getWorldSize().Y & proposedPosition.Y > 0)
                {
                    target.modifyPosition(proposedPosition);

                    target.drainEnergy(cost * calculateSpeedCost(target.getSpeed()));
                }
            }

            target.drainEnergy(cost * calculateSpeedCost(target.getSpeed()) + 0.25);

            return index + 1;
        }