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


Python Convert.world_to_chunk方法代码示例

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


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

示例1: tentative_move

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def tentative_move(self, world, old_pos, index):
     self.pos[index] += self.vel[index]
     if index == 0:
         self.bounding_box.x = Convert.world_to_pixel(self.pos[index])
     else:
         self.bounding_box.y = Convert.world_to_pixel(self.pos[index])
     block_left = int(Convert.world_to_chunk(self.pos[0])[0])
     chunk_left = Convert.world_to_chunk(self.pos[0])[1]
     block_right = math.ceil(Convert.world_to_chunk(self.pos[0] + self.width)[0])
     chunk_right = Convert.world_to_chunk(self.pos[0] + self.width)[1]
     block_top = int(self.pos[1])
     block_bottom = math.ceil(self.pos[1] + self.height)
     col1 = col2 = col3 = col4 = False
     if chunk_left == chunk_right:
         chunk = world.loaded_chunks.get(chunk_left)
         col1 = self.check_collision(chunk, block_left, block_right, block_top, block_bottom, old_pos, index)
     else:
         #need to check from block_left in chunk_left to block_right in chunk_right and all the blocks in any chunks between them
         chunk = world.loaded_chunks.get(chunk_left)
         col2 = self.check_collision(chunk, block_left, Chunk.WIDTH, block_top, block_bottom, old_pos, index)
         for c in range(chunk_left + 1, chunk_right):
             chunk = world.loaded_chunks.get(c)
             col3 = self.check_collision(chunk, 0, Chunk.WIDTH, block_top, block_bottom, old_pos, index)
         chunk = world.loaded_chunks.get(chunk_right)
         col4 = self.check_collision(chunk, 0, block_right, block_top, block_bottom, old_pos, index)
     if col1 or col2 or col3 or col4:
         self.vel[index] = 0 #reset acceleration?
     if index == 0:
         self.bounding_box.x = Convert.world_to_pixel(self.pos[index])
     else:
         self.bounding_box.y = Convert.world_to_pixel(self.pos[index])
开发者ID:rystills,项目名称:Oceania,代码行数:33,代码来源:Entity.py

示例2: break_block

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def break_block(self, player, mouse_pos, viewport):
     angle = self.find_angle(player, mouse_pos, viewport)
     block_pos = Convert.pixels_to_world(self.find_pos(angle, player.pixel_pos(True), Convert.viewport_to_pixels(mouse_pos, viewport), player.get_break_distance())) #it aint right
     chunk = self.loaded_chunks.get(Convert.world_to_chunk(block_pos[0])[1])
     block = self.get_block(block_pos)
     if block["breakable"]:
         chunk.blocks[block_pos[1]][Convert.world_to_chunk(block_pos[0])[0]] = get_block("water")
         chunk.entities.append(BlockDrop.BlockDrop(block_pos, block["name"]))
开发者ID:rystills,项目名称:Oceania,代码行数:10,代码来源:World.py

示例3: update

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def update(self):
     for x in range(self.loaded_chunks.first, self.loaded_chunks.end):
         chunk = self.loaded_chunks.get(x)
         for entity in chunk.entities:
             entity.update(self)
             if Convert.world_to_chunk(entity.pos[0])[1] != chunk.x:
                 print("Moving", entity, entity.pos)
                 chunk.entities.remove(entity)
                 self.loaded_chunks.get(Convert.world_to_chunk(entity.pos[0])[1]).entities.append(entity)
开发者ID:rystills,项目名称:Oceania,代码行数:11,代码来源:World.py

示例4: render

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
def render():
    if gamemode == MENU:
        menu.render(screen)
    elif gamemode == PLAYING:
        screen.fill(SKY)
        world.render(screen, viewport)
        if DEBUG:
            #render debug text
            h = 10
            fpsimg = font.render("fps: " + str(clock.get_fps()), 0, WHITE)
            screen.blit(fpsimg, (10, h))
            h += fpsimg.get_height()
            posimg = font.render("pos: [{0:.2f}".format(player.pos[0]) + ", {0:.2f}]".format(player.pos[1]), 0, WHITE)
            screen.blit(posimg, (10, h))
            h += posimg.get_height()
            chunk = world.loaded_chunks.get(Convert.world_to_chunk(player.pos[0])[1])
            chunkimg = font.render("chunk: " + str(chunk.x), 0, WHITE)
            screen.blit(chunkimg, (10, h))
            h += chunkimg.get_height()
            biomeimg = font.render("biome: " + str(chunk.biome["name"]), 0, WHITE)
            screen.blit(biomeimg, (10, h))
            h += biomeimg.get_height()
        player.render(screen, Convert.world_to_viewport(player.pos, viewport))
        if gui is None:
            target_pos = world.find_pos(world.find_angle(player, pygame.mouse.get_pos(), viewport), 
                                        Convert.pixels_to_viewport(player.pixel_pos(True), viewport), 
                                        pygame.mouse.get_pos(),
                                        player.get_break_distance())
            screen.blit(img_target, [x - y for x, y in zip(target_pos, [dim / 2 for dim in img_target.get_size()])]) #zoo-wee mama!
        else:
            gui.render(screen)
    pygame.display.flip()
开发者ID:rystills,项目名称:Oceania,代码行数:34,代码来源:Game.py

示例5: generate_structure

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [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

示例6: generate_structure

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [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

示例7: update

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def update(self, world):
     old_chunk = Convert.world_to_chunk(self.pos[0])[1]
     hspeed = min(abs(self.vel[0] + self.acceleration * self.dir[0]), self.max_speed) * self.dir[0]
     vspeed = min(abs(self.vel[1] + self.acceleration * self.dir[1]), self.max_speed) * self.dir[1]
     self.vel = [hspeed, vspeed]
     super(Player, self).update(world)
     new_chunk = Convert.world_to_chunk(self.pos[0])[1]
     if new_chunk != old_chunk:
         world.load_chunks(new_chunk)
     
     entities = world.loaded_chunks.get(Convert.world_to_chunk(self.pos[0])[1]).entities
     for entity in entities:
         if(self.bounding_box.colliderect(entity.bounding_box)):
             if type(entity) is BlockDrop:
                 if self.pickup(entity.blockname):
                     entities.remove(entity)
                 print(self.inventory)
开发者ID:rystills,项目名称:Oceania,代码行数:19,代码来源:Player.py

示例8: update

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def update(self):
     for x in range(self.loaded_chunks.first, self.loaded_chunks.end):
         chunk = self.loaded_chunks.get(x)
         for entity in chunk.entities:
             entity.update(self)
             if Convert.world_to_chunk(entity.pos[0])[1] != chunk.x \
                     and self.loaded_chunks.contains_index(Convert.world_to_chunk(entity.pos[0])[1]) \
                     and entity in chunk.entities:
                 chunk.entities.remove(entity)
                 self.create_entity(entity)
     for layer in [True, False]:
         blocks_to_remove = []
         for breaking_block in self.breaking_blocks[layer]:
             breaking_block["progress"] -= 1
             if breaking_block["progress"] <= 0:
                 blocks_to_remove.append(breaking_block)
         for b in blocks_to_remove:
             self.breaking_blocks[layer].remove(b)
开发者ID:kaikue,项目名称:Oceania,代码行数:20,代码来源:World.py

示例9: render_break_preview

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def render_break_preview(self, background, world, block, block_pos, screen, viewport):
     chunk = world.loaded_chunks.get(Convert.world_to_chunk(block_pos[0])[1])
     blockimg = world.get_block_render(World.get_block_id(block["name"]), block_pos, block["connectedTexture"], background, chunk, background).copy()
     mask = pygame.mask.from_surface(blockimg)
     olist = mask.outline()
     polysurface = pygame.Surface((Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE), pygame.SRCALPHA)
     color = self.get_color(background)
     pygame.draw.polygon(polysurface, color, olist, 0)
     screen.blit(polysurface, Convert.world_to_viewport(block_pos, viewport))
开发者ID:kaikue,项目名称:Oceania,代码行数:11,代码来源:Player.py

示例10: is_clear

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [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

示例11: break_block

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [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

示例12: load_state

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def load_state(self, path):
     savefile = open(path, "rb")
     save_data = pickle.load(savefile)
     savefile.close()
     self.player = save_data["player"]
     self.seed = save_data["seed"]
     Generate.setup(self.seed)
     player_chunk = Convert.world_to_chunk(self.player.pos[0])[1]
     self.loaded_chunks = TwoWayList.TwoWayList()
     self.load_chunks(player_chunk)
     self.player.load_image()
     for row in self.player.inventory:
         for item in row:
             if item is not None:
                 item.load_image()
开发者ID:kaikue,项目名称:Oceania,代码行数:17,代码来源:World.py

示例13: render

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
def render():
    if gamemode == MAINMENU or gamemode == PAUSEMENU:
        menu.render_background(screen)
        menu.render(screen)
        
    elif gamemode in (PLAYING, OPENGUI):
        player = world.player
        shift = pygame.key.get_pressed()[pygame.K_LSHIFT] or pygame.key.get_pressed()[pygame.K_RSHIFT]
        screen.fill(SKY)
        
        #background
        world.render(screen, viewport, True)
        if shift:
            player.draw_block_highlight(world, pygame.mouse.get_pos(), viewport, screen, shift)
        world.render_breaks(screen, viewport, True)
        
        #foreground
        world.render(screen, viewport, False)
        if not shift:
            player.draw_block_highlight(world, pygame.mouse.get_pos(), viewport, screen, shift)
        world.render_breaks(screen, viewport, False)
        player.render(screen, Convert.world_to_viewport(player.pos, viewport))
        
        #add blue overlay- not completely sure this is good
        overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
        overlay.set_alpha(64)
        overlay.fill(BLUE)
        screen.blit(overlay, (0, 0))
        
        if gamemode == PLAYING:
            hotbarGui.render(screen)
        else:
            gui.render(screen)
        
        if DEBUG:
            #render debug text
            chunk = world.loaded_chunks.get(Convert.world_to_chunk(player.pos[0])[1])
            debugtext = ["fps: {0:.2f}".format(clock.get_fps()),
                        "pos: [{0:.2f}".format(player.pos[0]) + ", {0:.2f}]".format(player.pos[1]),
                        "chunk: " + str(chunk.x),
                        "biome: " + str(chunk.biome["name"])]
            debugimg = GUI.render_string_array(debugtext, font, 0, WHITE)
            h = SCREEN_HEIGHT - debugimg.get_height()
            screen.blit(debugimg, (2 * SCALE, h))
    pygame.display.flip()
开发者ID:kaikue,项目名称:Oceania,代码行数:47,代码来源:Game.py

示例14: render_block_preview

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def render_block_preview(self, background, held_item, world, block_pos, screen, viewport):
     held_block = World.get_block(held_item.name)
     chunk = world.loaded_chunks.get(Convert.world_to_chunk(block_pos[0])[1])
     blockimg = world.get_block_render(World.get_block_id(held_block["name"]), block_pos, held_block["connectedTexture"], background, chunk, background).copy()
     mask = pygame.mask.from_surface(blockimg)
     olist = mask.outline()
     polysurface = pygame.Surface((Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE), pygame.SRCALPHA)
     screen.blit(polysurface, Convert.world_to_viewport(block_pos, viewport))
     collides = False
     entities = world.get_nearby_entities(self.get_chunk())
     entities.append(self)
     for entity in entities:
         if entity.collides(block_pos) and entity.background == background:
             collides = True
     color = self.get_color(background)
     if collides and World.get_block(held_block["name"])["solid"]:
         color = (color[0], 0, 0, color[3])
     pygame.draw.polygon(polysurface, color, olist, 0)
     blockimg.blit(polysurface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
     screen.blit(blockimg, Convert.world_to_viewport(block_pos, viewport))
开发者ID:kaikue,项目名称:Oceania,代码行数:22,代码来源:Player.py

示例15: get_block

# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_chunk [as 别名]
 def get_block(self, world_pos):
     chunk = self.loaded_chunks.get(Convert.world_to_chunk(world_pos[0])[1])
     x_in_chunk = Convert.world_to_chunk(world_pos[0])[0]
     return chunk.blocks[world_pos[1]][x_in_chunk]
开发者ID:rystills,项目名称:Oceania,代码行数:6,代码来源:World.py


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