Question: The following program should read a track in from a file called 'track.txt'. 0 should indicate grass, 1 should indicate the track and 2 should

The following program should read a track in from a file called 'track.txt'. 0 should indicate grass, 1 should indicate the track and 2 should indicate the start/finish line.  These should be images drawn in to represent the tiles as these components, it is recommended that these are loaded in as sprites. Each 'tile' should have dimensions controlled by variables, and be positioned according to the input file. If the input file is 10x10 numbers, you should draw this many tiles. The track is static, so this could be drawn in the setup phase, but you will need access to this data for detecting the car leaving the track. 

The program should draw a car as a sprite on the start finish line, facing one of the adjacent road tiles. You could draw or find a suitable image to use. The car size should be controlled by a variable (but always smaller than the tile size) and be placed in the middle of the road.

The program should allow for 4 inputs - up/down and left/right on the keyboard. Up and down should modify the velocity of the car (you should impose limits so it cannot go too fast or backwards). Left and right should rotate the angle it is facing and moving. This should be done in a smooth way so the car cannot execute instant 90 degree turns.

If the car leaves the track and hits the grass, the game should reset to the start position (simply move the car back to its initial position)

Track.txt

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 1 1 0 0 0 0
0 0 0 1 0 0 0 0 0 0 1 1 0 0 0
0 0 1 1 0 0 0 0 0 0 0 1 0 0 0
0 1 1 0 0 0 0 0 0 0 0 1 0 0 0
0 1 0 0 1 1 1 0 0 1 1 1 0 0 0
0 1 0 0 1 0 1 0 0 1 0 0 0 0 0
0 1 0 0 1 0 1 0 0 1 1 1 1 1 0
0 2 0 0 1 0 1 1 0 0 0 0 1 1 0
0 1 0 0 1 0 0 1 1 0 0 0 0 1 0
0 1 0 0 1 0 0 0 1 0 0 0 0 1 0
0 1 1 1 1 0 0 0 1 0 0 0 1 1 0
0 0 1 1 0 0 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Step by Step Solution

3.52 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a Python program that should do what youre looking for It reads the track from a file called tracktxt draws the track and car and allows the user to control the car using the up down left and ri... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!