O'Reilly logo

Adventures in Python by Craig Richardson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ch10-pag223

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, while loops, for loops, lists and comparators. You’ve also been introduced to different Python libraries including the turtle module, Tkinter and PyGame.

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.

FIGURE 10-1 In the finished game, two players compete to collect coins. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required