File main.py changed (mode: 100644) (index df276de..cab27a3) |
... |
... |
class Model(object): |
125 |
125 |
# Mapping from sector to a list of positions inside that sector. |
# Mapping from sector to a list of positions inside that sector. |
126 |
126 |
self.sectors = {} |
self.sectors = {} |
127 |
127 |
|
|
128 |
|
# Simple function queue implementation. |
|
|
128 |
|
# Simple function queue implementation. The queue is populated with |
|
129 |
|
# _show_block() and _hide_block() calls |
129 |
130 |
self.queue = [] |
self.queue = [] |
130 |
131 |
|
|
131 |
132 |
self._initialize() |
self._initialize() |
|
... |
... |
class Model(object): |
150 |
151 |
# generate the hills randomly |
# generate the hills randomly |
151 |
152 |
o = n - 10 |
o = n - 10 |
152 |
153 |
for _ in xrange(120): |
for _ in xrange(120): |
153 |
|
a = random.randint(-o, o) |
|
154 |
|
b = random.randint(-o, o) |
|
155 |
|
c = -1 |
|
156 |
|
h = random.randint(1, 6) |
|
157 |
|
s = random.randint(4, 8) |
|
|
154 |
|
a = random.randint(-o, o) # x position of the hill |
|
155 |
|
b = random.randint(-o, o) # z position of the hill |
|
156 |
|
c = -1 # base of the hill |
|
157 |
|
h = random.randint(1, 6) # height of the hill |
|
158 |
|
h = 60 |
|
159 |
|
s = random.randint(4, 8) # 2 * s is the side length of the hill |
|
160 |
|
s = 30 |
158 |
161 |
d = 1 |
d = 1 |
159 |
162 |
t = random.choice([GRASS, SAND, BRICK]) |
t = random.choice([GRASS, SAND, BRICK]) |
160 |
163 |
for y in xrange(c, c + h): |
for y in xrange(c, c + h): |
|
... |
... |
class Model(object): |
165 |
168 |
if (x - 0) ** 2 + (z - 0) ** 2 < 5 ** 2: |
if (x - 0) ** 2 + (z - 0) ** 2 < 5 ** 2: |
166 |
169 |
continue |
continue |
167 |
170 |
self.init_block((x, y, z), t) |
self.init_block((x, y, z), t) |
168 |
|
s -= d |
|
|
171 |
|
s -= d # decrement side lenth so hills taper off |
169 |
172 |
|
|
170 |
173 |
def hit_test(self, position, vector, max_distance=8): |
def hit_test(self, position, vector, max_distance=8): |
171 |
174 |
""" Line of sight search from current position. If a block is |
""" Line of sight search from current position. If a block is |
|
... |
... |
class Model(object): |
290 |
293 |
self.show_block(position) |
self.show_block(position) |
291 |
294 |
|
|
292 |
295 |
def show_block(self, position, immediate=True): |
def show_block(self, position, immediate=True): |
293 |
|
""" Show the block at the given `position`. |
|
|
296 |
|
""" Show the block at the given `position`. This method assumes the |
|
297 |
|
block has already been added with add_block() |
294 |
298 |
|
|
295 |
299 |
Parameters |
Parameters |
296 |
300 |
---------- |
---------- |
|
... |
... |
class Model(object): |
336 |
340 |
else: |
else: |
337 |
341 |
index += 1 |
index += 1 |
338 |
342 |
# create vertex list |
# create vertex list |
|
343 |
|
# FIXME Maybe `add_indexed()` should be used instead |
339 |
344 |
self._shown[position] = self.batch.add(count, GL_QUADS, self.group, |
self._shown[position] = self.batch.add(count, GL_QUADS, self.group, |
340 |
345 |
('v3f/static', vertex_data), |
('v3f/static', vertex_data), |
341 |
346 |
('t2f/static', texture_data)) |
('t2f/static', texture_data)) |
|
... |
... |
class Model(object): |
423 |
428 |
func(*args) |
func(*args) |
424 |
429 |
|
|
425 |
430 |
def process_queue(self): |
def process_queue(self): |
426 |
|
""" Process the entire queue while taking periodic breaks. |
|
|
431 |
|
""" Process the entire queue while taking periodic breaks. This allows |
|
432 |
|
the game loop to run smoothly. The queue contains calls to |
|
433 |
|
_show_block() and _hide_block() so this method should be called if |
|
434 |
|
add_block() or remove_block() was called with sync=False |
427 |
435 |
|
|
428 |
436 |
""" |
""" |
429 |
437 |
start = time.clock() |
start = time.clock() |