0% found this document useful (0 votes)
78 views

CodeCraft - Raspberry Pi Projects

This document provides instructions for a coding project that involves improving a 2D Minecraft clone. [1] Students will learn about graphics and game design by creating new resources and crafting rules. [2] They can add items like wood, sand, and glass and specify how items can be crafted, such as crafting planks from wood. [3] The goal is for students to design and code their own versions of the game.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

CodeCraft - Raspberry Pi Projects

This document provides instructions for a coding project that involves improving a 2D Minecraft clone. [1] Students will learn about graphics and game design by creating new resources and crafting rules. [2] They can add items like wood, sand, and glass and specify how items can be crafted, such as crafting planks from wood. [3] The goal is for students to design and code their own versions of the game.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Projects

CodeCraft
Design and code improvements to a 2D version of
Minecraft.

Step 1 Introduction

In this project, you’ll design and code improvements to a 2D version of Minecraft.

Additional information for club leaders


If you need to print this project, please use the Printer friendly version (https://projects.raspberrypi.org/en/projec
ts/codecraft/print).
Club leader notes
Introduction:
In this project, children will learn aspects of graphics and game design by making improvements to a basic 2D
Minecraft clone. Children will create new resources, as well as crafting rules for combining resources to make new
ones. This will be achieved by understanding and manipulating variables, lists and dictionaries.
Online Resources
This project uses Python 3. We recommend using trinket (https://trinket.io/) to write Python online. This project
contains the following Trinkets:
‘CodeCraft’ starter project – rpf.io/codecraft-on (http://rpf.io/codecraft-on)
There is also a trinket containing the completed project:
‘CodeCraft’ Finished – trinket.io/python/ebc5b0148b (https://trinket.io/python/ebc5b0148b)
Offline Resources
This project can be completed offline (https://www.codeclubprojects.org/en-GB/resources/python-working-
offline/) if preferred. You can access the project resources by clicking the ‘Project Materials’ link for this project.
This link contains a ‘Project Resources’ section, which includes resources that children will need to complete this
project offline. Make sure that each child has access to a copy of these resources. This section includes the
following files:
codecraft/codecraft.py
codecraft/variables.py
codecraft/brick.gif
codecraft/dirt.gif
codecraft/glass.gif
codecraft/grass.gif
codecraft/plank.gif
codecraft/player.gif
codecraft/sand.gif
codecraft/water.gif
codecraft/wood.gif
You can also find a completed version of this project in the ‘Volunteer Resources’ section, which contains:
codecraft-finished/codecraft.py
codecraft-finished/variables.py
codecraft-finished/brick.gif
codecraft-finished/dirt.gif
codecraft-finished/glass.gif
codecraft-finished/grass.gif
codecraft-finished/plank.gif
codecraft-finished/player.gif
codecraft-finished/sand.gif
codecraft-finished/water.gif
codecraft-finished/wood.gif
(All of the resources above are also downloadable as .zip files.)
Learning Objectives
Creating and editing graphics;
Game design;
Editing:
Variables;
Lists;
Dictionaries.
This project covers elements from the following strands of the Raspberry Pi Digital Making Curriculum (http://rp
f.io/curriculum):
Design basic 2D and 3D assets. (https://www.raspberrypi.org/curriculum/design/creator)
Combine programming constructs to solve a problem. (https://www.raspberrypi.org/curriculum/progra
mming/builder)
Challenges
“Build your world” - Playing the game, placing and crafting existing blocks;
“Change your world size” - editing the MAPWIDTH and MAPHEIGHT variables to change the world size;
“Creating sand” - Creating a new sand resource, along with associated game data.
“Crafting glass from sand” - Creating a new craftable glass resource.
“Create more resources” - Use what’s been learnt to create more blocks and crafting rules.
Frequently Asked Questions
Children may need reminding that elements of a dictionary/list are separated by a comma. For example, when
adding inventory items, graphics and crafting rules to the game.

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

Open this trinket: rpf.io/codecraft-on (http://rpf.io/codecraft-on).


Use the WASD keys to move your player around the world, which is full of different resources (dirt, grass and water).

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

Let’s modify some variables to change how your game works.


Click the variables.py file to see some variables that can be changed.

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.

Notice the comma , at the end of the line above.


Your resource will also need an image. The project already includes an image called wood.gif, which you should
add to the textures dictionary.

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

Let’s create a new plank resource that be crafted from wood.


First, add a new PLANK variable to your game.

Add a new PLANK variable to your game.

Name the resource 'plank'.

Give your PLANK resource an image. The project already contains a plank.gif image, but you can create your
own if you prefer.

Add planks to your inventory.


Set a key for placing planks.

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.

Finally, you need to set a key for crafting new planks.

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?

Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons license (ht


tps://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/codecraft)

You might also like