CONGRATULATIONS—YOU’VE REACHED your final adventure! You’ve come a very long way and learned a lot about Python. You’ve learned about Python programming concepts including variables,
if statements, functions,
for loops, lists and comparators. You’ve also been introduced to different Python libraries including the
In this final adventure, you will combine lots of the things you learned about Python in your previous adventures to create a fantastic two-player game. So, what does this program do? It’s a game in which two players compete to collect coins. The coins’ locations are randomly generated and change every time a coin is collected. The players’ scores are displayed next to the player sprites.
Players can move in eight directions (up, down, left, right and diagonally in four ways). If players collide, they bounce in opposite directions. There are walls around the edge of the game that stop the players walking off the edge of the window. There are four doors in the walls, through which players can move. Leaving through one door makes them reappear in the opposite door.
You control the players using a single keyboard. The w, a, s and d keys control player 1, and the up, down, left and right keys control player 2.
You can see the finished game in Figure 10-1.