O'Reilly Forums: Ziechman - Viewing Profile - O'Reilly Forums

Jump to content

User Rating: -----

Reputation: 0 Neutral
Group:
Members
Active Posts:
2 (0.01 per day)
Most Active In:
Head First C# (2 posts)
Joined:
12-November 12
Profile Views:
703
Last Active:
User is offline Nov 13 2012 09:44 AM
Currently:
Offline

My Information

Member Title:
New Member
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Not Telling Not Telling

Contact Information

E-mail:
Click here to e-mail me

Posts I've Made

  1. 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.

Comments

Ziechman has no profile comments yet. Why not say hello?