In this project, we'll build a simple house in the Minecraft world at the touch of a button.
For this project, we just need a single button, wired to GPIO24:
The code for this project should look very familiar. It is very similar to the Minecraft project, where we drew an animation of our character using blocks. In that project, we were also drawing the sprite on our LED Matrix, so we used 0 to denote LED off and 1-8 and A-F to denote intensity of the LED display.
Because we're not using the LED Matrix in this project, we don't need to include the LED intensity in our sprite design. Instead, we will simply use 0 and 1 to denote our block types — 0 will indicate no block (block type AIR) and 1 will indicate a stone block. We implement this using a list, and the 0 and 1 are simply indexes in that list.
The magic happens in a function we've created called create_house()
.
Similar to the sprite_in_minecraft()
function in the
project, we go through a set of nested loops to
draw blocks in the Minecraft world. In that project, we drew the animation in
2 dimensions (X and Y), and therefore we used two nested loops. In this project,
we'll draw the house in 3 dimensions, which means we'll need three nested loops.
The corner of the house is drawn relative to Steve's position, plus an offset. An offset is just a small change in position. We chose a small offset so that the house is close to Steve, but not right on top of him.
Here is what the full code for this project should look like:
Give it a try. You'll need to fly up and into the house to see the inside.
Assuming you still have your controller wired up, add this house making code to the Minecraft controller code ( project) so that you can build a house while using the CREATOR Kit as a controller.
The house is made of AIR and STONE. Try swapping those materials to get a strange inverted house.
Adjust the offset
passed into create_house()
so
that when the house is built, Steve is just outside of it.
Let's be honest — it's not much of a house. Make it a little better by adding a hole for a door and a flat roof.