GEEK is a festival of Play & Games and they gave me the opportunity to create an attraction that aimed to introduce people to programming.
I decided to run a Minecraft Python Challenge using Raspberry Pi computers that come with a very special version of Minecraft that can be controlled using the Python programming language. Kids in particular love Minecraft and love building with code even more! Write programmes in Python and see them create Minecraft Coolness in an instant instead of clicking literally thousands of times.
This blog should give you enough information for you to recreate this attraction in your own home, a local school, or some other event.
What do you need to run this workshop?
The Raspberry Pi computer uses an operating system called Raspbian. For the technically minded it is a special version of Linux for the Raspberry Pi which is free and has hundreds of powerful applications that can be downloaded. It's special for many reasons especially that it comes with the Minecraft Pi Version and Python programming system. Raspberry Pi computers are often sold with Raspbian (sometimes as part of Noobs - google it!) and is what we used to run our attraction. Nothing special or unusual at all.
Plug these into the Raspberry Pi - the keyboard, mouse and monitor or TV - any display with an HDMI connection.
You may need to connect to the internet on the first use of the Pi to fully install Raspbian but after that you can run it off line. The Pi can do wifi or an ethernet connection to the internet.
Once you've got the Raspberry Pi up and running you need to start two programmes from the 'Raspberry Menu in the top left corner: Under the games menu choose minecraft; under the programming menu choose Python 2 (Idle). Play in Minecraft and code in Python.
The following examples were printed out and laminated for each visitor to use. Each teaches important concepts and together they are enough to build some awesome programmes if you have the imagination.
First launched in February 2012 GEEK is held annually in Margate, Kent. For more information please see http://www.geek-play.com/
I decided to run a Minecraft Python Challenge using Raspberry Pi computers that come with a very special version of Minecraft that can be controlled using the Python programming language. Kids in particular love Minecraft and love building with code even more! Write programmes in Python and see them create Minecraft Coolness in an instant instead of clicking literally thousands of times.
This blog should give you enough information for you to recreate this attraction in your own home, a local school, or some other event.
What is Raspberry Pi?
The Raspberry Pi is a very small, very cheap computer with very large usefulness. You can use it as a standalone computer to surf the internet, check your email and watch videos. It's not as powerful as a laptop, but it is good enough for general use and for just over £30 that's incredible. If that's not enough it is also designed for learning computer science skills and is great for some super cool projects (just google Raspberry Pi projects).What is Minecraft Pi Version?
Minecraft created a special version of their game just for the Raspberry Pi to help everyone learn those computer science skills. In some ways it is a cut-down version - there are no monsters or animals, you can't craft items and most disappointing, TNT does not explode. In other ways it is the best version of Minecraft because you can write a small computer programme to build a house then loop that to build a city of houses in less than a second. There are many cool people out there writing programmes to build other cool stuff too including turning any block into an exploding TNT-style block - cooler than TNT itself!What is Python?
These programmes are all written in a programming language called Python. It has nothing to do with snakes, but it has a lot to do with some serious code used in business and holding the internet together. It is also a really easy language to learn and teaches all the important computer science concepts a future programmer needs to know.What do you need to run this workshop?
- Raspberry Pi Computer (affiliate link to Pi Hut)
- Raspbian Operating System
- Keyboard, Mouse, Monitor/TV
- Example code
- Sense of adventure and persistence
The Raspberry Pi computer uses an operating system called Raspbian. For the technically minded it is a special version of Linux for the Raspberry Pi which is free and has hundreds of powerful applications that can be downloaded. It's special for many reasons especially that it comes with the Minecraft Pi Version and Python programming system. Raspberry Pi computers are often sold with Raspbian (sometimes as part of Noobs - google it!) and is what we used to run our attraction. Nothing special or unusual at all.
Plug these into the Raspberry Pi - the keyboard, mouse and monitor or TV - any display with an HDMI connection.
You may need to connect to the internet on the first use of the Pi to fully install Raspbian but after that you can run it off line. The Pi can do wifi or an ethernet connection to the internet.
Once you've got the Raspberry Pi up and running you need to start two programmes from the 'Raspberry Menu in the top left corner: Under the games menu choose minecraft; under the programming menu choose Python 2 (Idle). Play in Minecraft and code in Python.
The following examples were printed out and laminated for each visitor to use. Each teaches important concepts and together they are enough to build some awesome programmes if you have the imagination.
Hello Minecraft!
import
mcpi.minecraft as minecraft
mc
= minecraft.Minecraft.create()
msg
= “Hello World”
mc.postToChat(msg)
Where Are You?
X is
forward/backwards, Y is up/down, Z is left, right (sort of depends
where you’re looking!)
import
mcpi.minecraft as minecraft
import
time
mc
= minecraft.Minecraft.create()
while
True:
time.sleep(1.0)
pos
= mc.player.getPos()
print
pos.x, pos.y, pos.z #see next example for pro tip
Creating A Block
import
mcpi.minecraft as minecraft
from
mcpi.block import *
mc
= minecraft.Minecraft.create()
x,
y, z = mc.player.getPos() #pro tip - can you explain it?
x
= x+3
mc.setBlock(x,
y, z, GLOWING_OBSIDIAN)
mc.setBlock(x,
y, z+2, 246)
mc.setBlock(x,
y, z+4, WOOL, 16)
Stacking Blocks
import
mcpi.minecraft as minecraft
from
mcpi.block import *
mc
= minecraft.Minecraft.create()
x,
y, z = mc.player.getPos()
blockType1
= MUSHROOM_RED
blockType2
= 103
x
= x+2
mc.setBlock(x,
y, z, blockType1)
y
= y+1
mc.setBlock(x,
y, z, blockType2)
Making a big block of blocks
import
mcpi.minecraft as minecraft
from
mcpi.block import *
mc
= minecraft.Minecraft.create()
blockType
= ICE
x1,
y1, z1 = mc.player.getPos()
x1
= x1+10
x2
= x1 + 20
y2
= y1 + 20
z2
= z1 + 60
mc.setBlocks(x1,
y1, z1, x2, y2, z2, blockType)
Challenge: Now can
you hollow out the block to make a warehouse? Tip: fill the first
block of blocks with a smaller block of blocks of AIR. Does that even
make sense!?
Repeating your build
import
mcpi.minecraft as minecraft
from
mcpi.block import *
mc
= minecraft.Minecraft.create()
blockType
= BEDROCK
numberOfRepeats
= 12
x,
y, z = mc.player.getPos()
x
= x+5
numberOfBlocks
= 1
while
numberOfBlocks <= numberOfRepeats:
mc.setBlock(x,
y, z, blockType)
y
= y+1
numberOfBlocks
= numberOfBlocks + 1 #Pro tip: you could use numberOfBlocks += 1
Challenge: can you
make a square of blocks like a fence around a field?
Block
Names and Numbers
First launched in February 2012 GEEK is held annually in Margate, Kent. For more information please see http://www.geek-play.com/
No comments:
Post a Comment