Cueballs in code and text replace below with cueballs

If the dog is entering anything but the Moving state we set its velocity to zero (#1) and set the time to wait based on the game's current Delay value (#2). Otherwise the dog is entering the Moving state and we need to figure out where it is moving to and how long it will take to get there. This is done by calling the SetNextTarget method(#3).

I don't think we have one of those yet.

That's right so let's vreate it now. Here is the body of our SetNextTarget method:

Random rand = new Random();

void SetNextTarget() {

double speed = game.Speed; double targetX = 0; double distance = 0; double delta = 0;

targetX = rand.Next(

(int)BoundingRect.Left, (int)BoundingRect.Right) ; delta = targetX - X; distance = Math.Abs(delta);

Velocity.X = speed * (delta / distance); duration = distance / speed;

+2 -1

Average user rating: 3.7 stars out of 3 votes

Post a comment

  • Receive news updates via email from this site