Blindfold Racer: Creating the track

I thought about how the students were laying out the track, and I needed an easy way to convert that into a virtual track in the game. I also thought that in a future version of the game, we may want game players to create their own tracks and then drive on it.

By searching “open source” (free) projects that other people have created and shared, I found a program that lets you draw on the screen (with your finger), and then tells you the points on the line. Using that program, I could draw the “center line” of the track, and I would simply have to write a program to compute the left and right edges of the track (based on the width of the track). Easy, no?

It took about two weeks of relearning my trigonometry from high school to figure out how to do that – for example, how to rotate a square:

You need to know which direction the car is moving to understand which is the left fence and which is the right fence. For a straight track, it’s easy. For a track in the shape of a vertical “S” or a horizontal “S”, it becomes more difficult.

Essentially, I have to compute the bounding square of the track for every point on the “center line”:

and from that compute the left and right fences, and lay out the fences on a 2000 x 2000 matrix. The app also displayed the road on the screen (for debugging purposes), and that was sufficient to build out levels easily.

Each level would be described in an ordinary document (XML file), where the points of the center track are listed (from the starting line to the finish line), along with the positions of each animal or prize, and the sound that the animal or prize makes.

I also implemented many of the game-controlling gestures that the students came up with:

Now we can coming up with ideas for more levels, and implement them quickly.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s