MCPcopy Index your code
hub / github.com/fogleman/Minecraft / _initialize

Method _initialize

main.py:158–193  ·  view source on GitHub ↗

Initialize the world by placing all the blocks.

(self)

Source from the content-addressed store, hash-verified

156 self._initialize()
157
158 def _initialize(self):
159 """ Initialize the world by placing all the blocks.
160
161 """
162 n = 80 # 1/2 width and height of world
163 s = 1 # step size
164 y = 0 # initial y height
165 for x in xrange(-n, n + 1, s):
166 for z in xrange(-n, n + 1, s):
167 # create a layer stone an grass everywhere.
168 self.add_block((x, y - 2, z), GRASS, immediate=False)
169 self.add_block((x, y - 3, z), STONE, immediate=False)
170 if x in (-n, n) or z in (-n, n):
171 # create outer walls.
172 for dy in xrange(-2, 3):
173 self.add_block((x, y + dy, z), STONE, immediate=False)
174
175 # generate the hills randomly
176 o = n - 10
177 for _ in xrange(120):
178 a = random.randint(-o, o) # x position of the hill
179 b = random.randint(-o, o) # z position of the hill
180 c = -1 # base of the hill
181 h = random.randint(1, 6) # height of the hill
182 s = random.randint(4, 8) # 2 * s is the side length of the hill
183 d = 1 # how quickly to taper off the hills
184 t = random.choice([GRASS, SAND, BRICK])
185 for y in xrange(c, c + h):
186 for x in xrange(a - s, a + s + 1):
187 for z in xrange(b - s, b + s + 1):
188 if (x - a) ** 2 + (z - b) ** 2 > (s + 1) ** 2:
189 continue
190 if (x - 0) ** 2 + (z - 0) ** 2 < 5 ** 2:
191 continue
192 self.add_block((x, y, z), t, immediate=False)
193 s -= d # decrement side length so hills taper off
194
195 def hit_test(self, position, vector, max_distance=8):
196 """ Line of sight search from current position. If a block is

Callers 1

__init__Method · 0.95

Calls 1

add_blockMethod · 0.95

Tested by

no test coverage detected