+ All Categories
Transcript
Page 1: Moveable Objects Program

Moveable Objects Program

Creating objects that know where they’re going

Page 2: Moveable Objects Program

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:

Page 3: Moveable Objects Program

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!

Page 4: Moveable Objects Program

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.

Page 5: Moveable Objects Program

Doing the Math

Page 6: Moveable Objects Program
Page 7: Moveable Objects Program
Page 8: Moveable Objects Program
Page 9: Moveable Objects Program
Page 10: Moveable Objects Program
Page 11: Moveable Objects Program

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.

Page 12: Moveable Objects Program

The Stalker

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


Top Related