Moveable Objects Program - PowerPoint PPT Presentation

duc
moveable objects program n.
Skip this Video
Loading SlideShow in 5 Seconds..
Moveable Objects Program PowerPoint Presentation
Download Presentation
Moveable Objects Program

play fullscreen
1 / 12
Download Presentation
Moveable Objects Program
124 Views
Download Presentation

Moveable Objects Program

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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: