Raspberry_Pi_Education_Manual

Notes:

Create these two sprites using some paint software. Save them as “skier.png” and “block.png” (the tree).

Games are essentially real-time simulations of a system of rules that have a starting condition that is modified over time due to external input. Other than the external influences, the simulation is entirely predictable and deterministic. Here is a simulation of ski slalom, where a skier makes his or her way through gaps in rows of trees. The game uses a random number generator to define where to put the gap in the trees. Rather than truly race the player down a slope, this game keeps the player still and races all the trees towards him or her. This is a much more complicated system and the explanation of the simulation is in two parts. Firstly, how the program moves the skier on screen. Secondly, how to draw trees that the skier races passed. Before the main loop is started, the game world needs to be created, or initialised. Game worlds are made up of objects and, in our case, these are the little sprites you created. At the top of the program, a “worldSprite” class is created, which defines what a sprite is and what we can do to it. Then, we create a skier and enable it to move horizontally by a distance when it is updated. Lastly, we define the world, which is just a skier and some information about keys on the keyboard that have been pressed.

Even though we have defined these things, we haven’t actually created them. This happens when we create the skiWorld.

Experiments in Python

101

Made with FlippingBook flipbook maker