CodeCraft - Raspberry Pi Projects
CodeCraft - Raspberry Pi Projects
CodeCraft
Design and code improvements to a 2D version of
Minecraft.
Step 1 Introduction
Project materials
Project resources
.zip file containing all project resources (http://rpf.io/p/en/codecraft-go)
Online Trinket containing all ‘CodeCraft’ project resources (http://rpf.io/codecraft-on)
Club leader resources
.zip file containing all completed project resources (http://rpf.io/p/en/codecraft-get)
Online completed Trinket project (https://trinket.io/python/ebc5b0148b)
Step 2 Playing the game
You can press the spacebar to collect resources. Pick up a few of each type of resource, and you’ll see them added
to your inventory.
Press the number keys (1 to 3) to place a resource on the map. For example, press 3 to place some water on the
map. This will only work if you have some water in your inventory.
You can craft an item by pressing the key displayed in the menu. Crafting means combining items you already
have in your inventory to create new ones. Try pressing the ‘r’ key to craft a new brick (as long as you have 2 dirt
and 1 water in your inventory).
You can then press they ‘4’ key to place your crafted bricks.
Step 3 Challenge: Build your world
Can you build a house, with a garden and a swimming pool? What else can you create?
Step 4 Customising your game
Change the value of your BACKGROUNDCOLOUR variable, and click ‘Run’ to see the change to your game.
The variable MAXTILES is the amount of each resource that can be held in your inventory. Change this variable if
you want to store more (or less) than 20 of each resource.
Step 5 Challenge: Change your world size
Can you change the values of your MAPWIDTH and MAPHEIGHT variables to change the size of the world?
Step 6 Creating a new wood resource
Let’s create a new wood resource. To do this, you’ll need to add to some variables in your variables.py file.
First, you need to give your new resource a number. You’ll then be able to use the word WOOD in your code instead
of the number 4.
You should add your new WOOD resource to your list of resources.
You should also give your resource a name, which will be displayed in the inventory.
Add the number of your resource that should be in your inventory to start with.
Finally, add the key that you’ll press to place wood in the world.
Run your project to test it. You’ll see that you now have a new ‘wood’ resource in your inventory.
There’s no wood in your world! To fix this, click on your main.py file and find the function called
generateRandomWorld().
This code generates a random number between 0 and 10, and uses the number to decide which resource to place:
1 or 2 = water
3 or 4 = grass
anything else = DIRT
Add this code to add wood to your world whenever the randomNumber is 5.
Test your project again. This time, you should see some wood appear in your world.
Step 7 Challenge: Creating sand
Can you add a SAND resource to your game? You can use the steps above to help you.
The project already includes a sand.gif image, but you can create and upload your own if you prefer.
Step 8 Crafting planks from wood
Give your PLANK resource an image. The project already contains a plank.gif image, but you can create your
own if you prefer.
As this resource can be crafted, you need to create a crafting rule, which is that a plank can be made from 3 wood
tiles. Add this code to the crafting dictionary.
To test your new plank resource, gather up a few wood tiles and then craft some planks from your wood. You can
then place your new planks in your world.
Step 9 Challenge: Crafting glass from sand
Can you create a new glass resource, that can be crafted from sand? You can follow the steps above to help you.
The project already contains a glass.gif image that you can use, or you can create your own image if you prefer.
Step 10 Challenge: Create more resources
Can you add more resources and crafting rules to your game?