First Block

Now we are ready to build things in CodeCraft world.

Let's add a new line at the end of the file and print out the variable materials:

print(materials)

Note: if you click the 'run' button, this instruction window will switch to CodeCraft game window. To come back to this book, click the 'book' button.

Now run the code, and the console window should display:

{'box_black': 1, 'box_blue': 2, ..., 'stonebrick_carved': 87, 'tnt': 88}

These are the names of all the blocks you can use, each paired with an integer.

Add one more line of code to the end of the file:

p = Position(0, 2, -10)

Notice that Position is capitalized. Again, make sure you start at the beginning of the line, without spaces.

An object of the type Position is created and assigned to variable p, indicating a point in CodeCraft 3D game world. You will learn more about 3D coordinates in next chapter.

Now let's call a function of game, use point p as the first input value. The second input, integer 1, is the number corresponding to the string 'brick' in materials that you printed earlier.

game.set_block(p, 17)

Are you ready?

Run the program. The book window will disappear and you will see the CodeCraft game world with a brick block in front of you.

Congratulations! You have just placed your first block in the CodeCraft game world.

results matching ""

    No results matching ""