Exemplo n.º 1
0
        public void Move()
        {
            double dx = 0.0;
            double dy = 0.0;

            obstacles.ForEach(delegate(Source obstacle) {
                ForceVector forceVector = new ForceVector(obstacle.x, x, obstacle.y, y);

                double squaredLength = forceVector.width * forceVector.width;

                // This multiplication 'smooths' a robot movement
                if (obstacle is Pendulum)
                {
                    squaredLength *= 2.0;
                }

                dx += ((obstacle.x - x) * obstacle.charge) / squaredLength;
                dy += ((obstacle.y - y) * obstacle.charge) / squaredLength;
            });


            double dLength = Math.Sqrt(dx * dx + dy * dy);

            dx /= dLength;
            dy /= dLength;

            dx *= this.velocity;
            dy *= this.velocity;

            if (dx < 1 && dx >= -1)
            {
                dx = Math.Sign(dx);
            }

            if (dy < 1 && dy >= -1)
            {
                dy = Math.Sign(dy);
            }

            this.x += (int)dx;
            this.y += (int)dy;

            this.currentDx = dx;
            this.currentDy = dy;
        }
Exemplo n.º 2
0
        public new ForceVector calculateForceVector(Robot robot)
        {
            ForceVector forceVector = new ForceVector(this.x, robot.x, this.y, robot.y);

            forceVector.width -= this.radius;

            if (forceVector.width < 0)
            {
                forceVector.width = 0;
            }

            forceVector.dx *= this.charge;
            forceVector.dy *= this.charge;

            double vectorWidthSquare = forceVector.width * forceVector.width;

            forceVector.dx /= vectorWidthSquare;
            forceVector.dy /= vectorWidthSquare;

            return(forceVector);
        }