First Block

Now we are ready to build things in CodeCraft world.

Let's start a new line at the end of the file and print out the variable 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:

let p = new Position(0, 2, -10);

Note: Position is capitalized.

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 coordinates in the 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.setBlock(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 world.

results matching ""

    No results matching ""