1 / 12

Moveable Objects Program

Moveable Objects Program. Creating objects that know where they’re going. Moveable Objects. This program demonstrates how to create objects which know where they’re going and have some idea of how to get there. Allow me to demonstrate:. So what happens when I click a button?.

duc
Download Presentation

Moveable Objects Program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Moveable Objects Program Creating objects that know where they’re going

  2. Moveable Objects • This program demonstrates how to create objects which know where they’re going and have some idea of how to get there. • Allow me to demonstrate:

  3. So what happens when I click a button? • All that changes is that the Destination property of the object called “Cust” is changed. • So how does Cust start moving towards the new destination? Well, there’s a timer: • Obviously, there’s some serious encapsulation going on here!

  4. A Simple Motion Algorithm • For this program, I used a simple model for the motion of the objects: • Each object has a MaxSpeed property, which is really the maximum number of pixels it can move in a tick of the timer. • If the object is farther than MaxSpeed away from its Destination (property), it will move MaxSpeed pixels towards the Destination. • If it is less than or equal to MaxSpeed away, it will move directly to Destination and remain there until Destination is changed.

  5. Doing the Math

  6. The Algorithm in Code • Calling this procedure for every object every time in the Timer_Tick sub will cause all objects to move smoothly towards their destinations.

  7. The Stalker • The Stalker works because its Destination is changed to the other object’s location every tick of the clock:

More Related