本文整理汇总了Python中Convert.chunk_to_world方法的典型用法代码示例。如果您正苦于以下问题:Python Convert.chunk_to_world方法的具体用法?Python Convert.chunk_to_world怎么用?Python Convert.chunk_to_world使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Convert
的用法示例。
在下文中一共展示了Convert.chunk_to_world方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_structure
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import chunk_to_world [as 别名]
def generate_structure(self, structure, x):
#TODO: add background blocks defined separately
if structure["type"] == "column":
height = random.randint(structure["minheight"], structure["maxheight"])
for y in range(self.heights[x] - height, self.heights[x]):
self.set_block_at(x, y, World.get_block(structure["block"]), False)
elif structure["type"] == "json":
structure_file = open(structure["location"])
structure_json = json.load(structure_file)
curr_y = self.heights[x] - len(structure_json["shape"])
for line in structure_json["shape"]:
curr_world_x = Convert.chunk_to_world(x, self)
for char in line:
#find the right chunk
chunk = self #world.chunks[Convert.world_to_chunk(x)[1]]- can't really do this...
curr_chunk_x = Convert.world_to_chunk(curr_world_x)[0]
if curr_chunk_x < WIDTH:
if char == " ":
block_name = "water"
else:
block_name = structure_json["blocks"][char]
block = World.get_block(block_name)
#TODO: add background
chunk.set_block_at(curr_chunk_x, curr_y, block, False)
if block["entity"] != "":
#generate the block entity
EntityClass = getattr(importlib.import_module("ent." + block["entity"]), block["entity"])
instance = EntityClass([curr_world_x, curr_y], self)
self.entities.append(instance)
curr_world_x += 1
curr_y += 1
structure_file.close()
elif structure["type"] == "singleblock":
self.set_block_at(x, self.heights[x] - 1, World.get_block(structure["block"]), False)
示例2: generate_structure
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import chunk_to_world [as 别名]
def generate_structure(self, structure, x):
if structure["type"] == "column":
height = random.randint(structure["minheight"], structure["maxheight"])
for y in range(self.heights[x] - height, self.heights[x]):
self.blocks[y][x] = World.get_block(structure["block"])
elif structure["type"] == "json":
structure_file = open(structure["location"])
structure_json = json.load(structure_file)
curr_y = self.heights[x] - len(structure_json["shape"])
for line in structure_json["shape"]:
curr_world_x = Convert.chunk_to_world(x, self)
for char in line:
#find the right chunk
chunk = self #world.chunks[Convert.world_to_chunk(x)[1]]- can't really do this...
curr_chunk_x = Convert.world_to_chunk(curr_world_x)[0]
if curr_chunk_x < WIDTH:
if char == " ":
block = "water"
else:
block = structure_json["blocks"][char]
chunk.blocks[curr_y][curr_chunk_x] = World.get_block(block)
curr_world_x += 1
curr_y += 1
structure_file.close()
elif structure["type"] == "other":
#why did I write this?
pass
示例3: render_block
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import chunk_to_world [as 别名]
def render_block(self, x, y, screen, viewport, background):
#don't render air
if background:
block = World.get_block_from_id(self.background_blocks[y][x])
else:
block = World.get_block_from_id(self.foreground_blocks[y][x])
if block["name"] != "air":
Game.get_world().render_block(block["id"], [Convert.chunk_to_world(x, self), y], block["connectedTexture"], screen, viewport, background, self)
示例4: check_collision
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import chunk_to_world [as 别名]
def check_collision(self, chunk, left, right, top, bottom, old_pos, index):
for block_x in range(left, right):
for block_y in range(top, bottom):
check_block = chunk.blocks[block_y][block_x]
#if check_block.is_solid() and self.collides([Convert.chunk_to_world(block_x, chunk), block_y]):
if check_block["solid"] and self.collides([Convert.chunk_to_world(block_x, chunk), block_y]):
#found a collision!
self.pos[index] = old_pos[index]
return True
return False
示例5: render_block
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import chunk_to_world [as 别名]
def render_block(self, block, pos, screen, viewport):
"""#fast render water
if block["name"] == "water":
screen.blit(World.block_images[block["id"]],
Convert.world_to_viewport([Convert.chunk_to_world(pos[0], self), pos[1]], viewport))"""
#don't render air
if block["name"] != "air":
#print(block["name"] + " " + str(block["id"]))
Game.get_world().render_block(block["id"], [Convert.chunk_to_world(pos[0], self), pos[1]], block["connectedTexture"], screen, viewport)
if Game.DEBUG:
#draw bounding box
pygame.draw.rect(screen, Game.BLACK, pygame.Rect(Convert.chunk_to_viewport(pos, self, viewport), (Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE)), 1)
示例6: populate
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import chunk_to_world [as 别名]
def populate(self):
#Fill in blocks of this chunk
for y in range(len(self.foreground_blocks)):
for x in range(len(self.foreground_blocks[y])):
#surface_depth = self.heights[x] + 2 + random.randrange(4)
if y < World.SEA_LEVEL:
self.set_blocks_at(x, y, World.get_block("air"))
else:
world_x = Convert.chunk_to_world(x, self)
noise = Generate.terrain((world_x, y), (self.biome["maxelevation"], self.biome["minelevation"]))
self.set_blocks_from_noise(x, y, noise[0], False)
self.set_blocks_from_noise(x, y, noise[1], True)
"""elif y < self.heights[x]:
self.set_blocks_at(x, y, World.get_block("water"))
elif y < surface_depth:
self.set_blocks_at(x, y, World.get_block(self.biome["surface"]))
else:
self.set_blocks_at(x, y, World.get_block(self.biome["base"]))"""
self.decorate()