Hardware Reference
In-Depth Information
GAP = block.AIR.id
WALL = block.GOLD_BLOCK.id
FLOOR = block.GRASS.id
Don't use
SAND
for the floor layer. If you do, depending on where the maze is
built, the floor might start to fall away under your player's feet!
5.
Open the file containing your maze data. The
FILENAME
constant is used so that
it is easy for you to change the filename later to read in different maze files:
FILENAME = "maze1.csv"
f = open(FILENAME, "r")
6.
Get the player position and work out the coordinates of the bottom corner of the
maze. Adding 1 to the x and z will make sure that the maze doesn't get built on
top of your player's head. You could vary the y coordinate to build the maze in
the sky if you wanted to:
pos = mc.player.getTilePos()
ORIGIN_X = pos.x+1
ORIGIN_Y = pos.y
ORIGIN_Z = pos.z+1
7.
The z coordinate will vary at the end of each line of data, so start it of at the
origin of the maze. It will vary a little later on in the program:
z = ORIGIN_Z
8.
Loop around every line of the file. See Digging into the Code, which explains
what the
f.readlines():
function does. The
for
loop is actually looping through
every line in the file, one by one. Each time round the loop, the
line
variable
holds the next line that has been read from the file:
for line in f.readlines():
9.
Split the line into parts, wherever there is a comma. See Digging into the Code,
which explains what the
split()
function does. Remember that all of the lines
that are part of the body of the
for
loop have to be indented one level:
data = line.split(",")