当前位置: 首页>>代码示例>>Python>>正文


Python World.get_block方法代码示例

本文整理汇总了Python中World.get_block方法的典型用法代码示例。如果您正苦于以下问题:Python World.get_block方法的具体用法?Python World.get_block怎么用?Python World.get_block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在World的用法示例。


在下文中一共展示了World.get_block方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_structure

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [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
开发者ID:rystills,项目名称:Oceania,代码行数:29,代码来源:Chunk.py

示例2: generate_structure

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [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)
开发者ID:kaikue,项目名称:Oceania,代码行数:36,代码来源:Chunk.py

示例3: set_blocks_from_noise

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def set_blocks_from_noise(self, x, y, noise, background):
     #TODO: variable thresholds from biome
     if noise > -0.4:
         self.set_block_at(x, y, World.get_block(self.biome["base"]), background)
     elif noise > -0.5:
         self.set_block_at(x, y, World.get_block(self.biome["surface"]), background)
     else:
         self.set_block_at(x, y, World.get_block("water"), background)
开发者ID:kaikue,项目名称:Oceania,代码行数:10,代码来源:Chunk.py

示例4: use_discrete

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def use_discrete(self, world, player, mouse_pos, viewport):
     pos = player.find_angle_pos(mouse_pos, viewport)
     block = world.get_block_at(pos, False)
     if block == "flint":
         Game.play_sound("sfx/rock/hit.wav")
         world.set_block_at(pos, World.get_block("flint_knapped_1"), False)
     elif block == "flint_knapped_1":
         Game.play_sound("sfx/rock/hit.wav")
         world.set_block_at(pos, World.get_block("flint_knapped_2"), False)
     elif block == "flint_knapped_2":
         Game.play_sound("sfx/rock/hit.wav")
         world.set_block_at(pos, World.get_block("flint_knapped_3"), False)
     elif block == "flint_knapped_3":
         Game.play_sound("sfx/rock/hit.wav")
         world.set_block_at(pos, World.get_block("flint_knapped_4"), False)
开发者ID:kaikue,项目名称:Oceania,代码行数:17,代码来源:ItemFlint.py

示例5: populate

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def populate(self):
     #Fill in blocks based on heights
     for y in range(len(self.blocks)):
         for x in range(len(self.blocks[y])):
             surface_depth = self.heights[x] + 2 + random.randrange(4)
             if y < World.SEA_LEVEL:
                 self.blocks[y][x] = World.get_block("air")
             elif y < self.heights[x]:
                 self.blocks[y][x] = World.get_block("water")
             elif y < surface_depth:
                 #for some reason this sometimes makes base blocks above surface blocks, but it looks cool so I'll probably leave it
                 self.blocks[y][x] = World.get_block(self.biome["surface"])
             else:
                 self.blocks[y][x] = World.get_block(self.biome["base"])
     self.decorate()
开发者ID:rystills,项目名称:Oceania,代码行数:17,代码来源:Chunk.py

示例6: right_click_continuous

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def right_click_continuous(self, world, mouse_pos, viewport, background):
     item = self.get_held_item()
     block_pos = self.find_angle_pos(mouse_pos, viewport)
     
     if item is None:
         return
     
     item.use_continuous(world, self, mouse_pos, viewport)
     
     if item.can_place:
         #try to place the block
         
         #don't want to place a solid block over an entity
         if not background:
             entities = world.get_nearby_entities(self.get_chunk())
             entities.append(self) #check against player too
             for entity in entities:
                 if entity.collides(block_pos) and entity.background == background and World.get_block(item.name)["solid"]:
                     return
         
         if world.get_block_at(block_pos, False) == "water" and \
             (not background or world.get_block_at(block_pos, True) == "water"):
             world.set_block_at(block_pos, World.get_block(item.name), background)
             blockentity = item.data
             if blockentity is not None:
                 blockentity.load_image()
                 blockentity.set_pos(block_pos)
                 blockentity.background = background
                 world.create_entity(blockentity)
             self.remove_held_item()
开发者ID:kaikue,项目名称:Oceania,代码行数:32,代码来源:Player.py

示例7: draw_block_highlight

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def draw_block_highlight(self, world, mouse_pos, viewport, screen, shift):
     #if player can break the block at the position, highlight it
     #if player is holding a block and can place it, render a preview
     block_pos = self.find_angle_pos(mouse_pos, viewport)
     held_item = self.get_held_item()
     if held_item is None:
         harvest_level = 0
     else:
         harvest_level = held_item.get_harvest_level()
     
     block = World.get_block(world.get_block_at(block_pos, shift))
     samewater = block["name"] == "water"
     fgwater = World.get_block(world.get_block_at(block_pos, False))["name"] == "water"
     if block["breakable"] and block["harvestlevel"] <= harvest_level and (not shift or fgwater):
         self.render_break_preview(shift, world, block, block_pos, screen, viewport)
     elif held_item is not None and held_item.can_place and samewater:
         self.render_block_preview(shift, held_item, world, block_pos, screen, viewport)
开发者ID:kaikue,项目名称:Oceania,代码行数:19,代码来源:Player.py

示例8: is_clear

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def is_clear(self, world, pos):
     for x in range(int(pos[0]), int(pos[0] + self.width)):
         for y in range(int(pos[1]), int(pos[1] + self.height)):
             if not world.is_loaded_chunk(Convert.world_to_chunk(x)[1]):
                 return False
             if y >= World.HEIGHT:
                 return False
             block = World.get_block(world.get_block_at((x, y), False))
             if block["solid"]:
                 return False
     return True
开发者ID:kaikue,项目名称:Oceania,代码行数:13,代码来源:EntityEnemy.py

示例9: populate

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [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()
开发者ID:kaikue,项目名称:Oceania,代码行数:21,代码来源:Chunk.py

示例10: break_block

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def break_block(self, world, mouse_pos, viewport, background):
     block_pos = self.find_angle_pos(mouse_pos, viewport)
     chunk = world.loaded_chunks.get(Convert.world_to_chunk(block_pos[0])[1])
     #if there's a foreground block covering the background, don't break anything
     if background and world.get_block_at(block_pos, False) != "water":
         return
     block = World.get_block(world.get_block_at(block_pos, background))
     held_item = self.get_held_item()
     if held_item is None:
         harvest_level = 0
         break_speed = 1
     else:
         harvest_level = held_item.get_harvest_level()
         break_speed = held_item.get_break_speed()
     if (not block["breakable"]) or (block["harvestlevel"] > harvest_level):
         return
     block_to_break = None
     breaking_blocks = world.breaking_blocks[background]
     for breaking_block in breaking_blocks:
         if breaking_block["pos"] == block_pos:
             block_to_break = breaking_block
     if block_to_break is None:
         block_to_break = {"pos": block_pos, "name": block["name"], "progress": 0, "breaktime": block["breaktime"]}
         breaking_blocks.append(block_to_break)
     block_to_break["progress"] += 2 * break_speed
     if block_to_break["progress"] >= block_to_break["breaktime"]:
         #remove the block
         breaking_blocks.remove(block_to_break)
         chunk.set_block_at(Convert.world_to_chunk(block_pos[0])[0], block_pos[1], World.get_block("water"), background)
         blockentity = None
         if block["entity"] != "":
             #remove the associated entity
             for entity in chunk.entities:
                 if type(entity).__name__ == block["entity"] and [int(entity.pos[0]), int(entity.pos[1])] == block_pos:
                     chunk.entities.remove(entity)
                     blockentity = entity
                     break
         chunk.entities.append(ItemDrop(block_pos, block["name"], blockentity))
开发者ID:kaikue,项目名称:Oceania,代码行数:40,代码来源:Player.py

示例11: __init__

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def __init__(self, pos, blockname):
     self.blockname = blockname
     pos = [pos[0] + 0.25, pos[1] + 0.25]
     Entity.Entity.__init__(self, pos, World.get_block(blockname)["image"], (Game.BLOCK_SIZE * Game.SCALE // 2, Game.BLOCK_SIZE * Game.SCALE // 2))
开发者ID:rystills,项目名称:Oceania,代码行数:6,代码来源:BlockDrop.py

示例12: die

# 需要导入模块: import World [as 别名]
# 或者: from World import get_block [as 别名]
 def die(self, world):
     self.health = self.max_health
     #TODO: only create grave at nearest empty foreground space
     world.set_block_at([int(self.pos[0]), int(self.pos[1])], World.get_block("grave"), False)
     #TODO: fill it up with items and clear inventory
     #TODO: respawn
开发者ID:kaikue,项目名称:Oceania,代码行数:8,代码来源:Player.py


注:本文中的World.get_block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。