Posts I've Made
-
In Topic: Bee Simulator - Bees Bouncing
13 November 2012 - 09:44 AM
I figured it out!
because of the way the MoveTowardLocation method works, unless the difference between the two points is divisible by 3 (the MoveRate), the bees will bounce. this is because if say, the destination Y is 266, and the bee is at 265, the next cycle it will jump to 268, and then back to 265, and so on. My solution is as follows:
private bool MoveTowardsLocation(Point destination) { if (Math.Abs(destination.X - location.X) <= MoveRate) { location.X = destination.X; } else { if (destination.X > location.X) location.X += MoveRate; else if (destination.X < location.X) location.X -= MoveRate; } if(Math.Abs(destination.Y - location.Y) <= MoveRate) { location.Y = destination.Y; } else { if (destination.Y > location.Y) location.Y += MoveRate; else if (destination.Y < location.Y) location.Y -= MoveRate; } if ((location.X == destination.X) && (location.Y == destination.Y)) return true; else return false; }
Also, because of the way the bee animation is set up, the forms are being repainted unnecessarily every 3rd cycle, which can slow it down. So if running the Bee Simulator is slowing your computer down, you can take the Invalidate calls out of the AnimateBees method, and you'll get get about a 30 percent decrease in CPU usage (and equivalent increase in overall speed) without effecting the behavior of the program.
Friends
Ziechman hasn't added any friends yet.



Find My Content
Display name history
Nov 13 2012 09:44 AM
Not Telling
Comments
Ziechman has no profile comments yet. Why not say hello?