Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

12.10. Adding a Chase Car

How difficult would it be to add a chase car that chases the car controlled by the keyboard? The chase car will need to automatically steer itself to catch up with the user controlled car. We will use a simple chase algorithm for the chase car. If the lead car is to the left of the chaser, the chase car will turn slightly to the left. If the lead car is to the right, then the chase car will turn to the right.

The only additional element we need is a new controller. Example 12-31 shows the IChaseHandler interface that defines a chase algorithm based on timer events. It also declares a method to set the chase target, which is of type ICar.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial