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


Python World.get_tile_pos方法代码示例

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


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

示例1: run

# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import get_tile_pos [as 别名]

#.........这里部分代码省略.........
            world.background_pos.y += 500 * time_passed_seconds

            if world.background_pos.y > 0:
                world.background_pos.y = 0

        elif int(pos.y) >= screen_height - 16:

            if not bool_full:
                pygame.mouse.set_pos((pos.x, screen_height - 16))

            world.background_pos.y -= 500 * time_passed_seconds

            if world.background_pos.y < -1 * (world.h - screen_height):
                world.background_pos.y = -1 * (world.h - screen_height)

        if pygame.mouse.get_pressed()[0]:
            if pos.x > world.clipper.minimap_rect.x and pos.y > world.clipper.minimap_rect.y:
                """ If the player clicked on the mini map,
                    go to that location with the view centered on the event position"""
                draw = False
                if not held:
                    # E712 comparison to True should be 'if cond is not True:' or 'if not cond:'
                    world.background_pos.x = (-1 * (pos.x - world.clipper.minimap_rect.x) * world.clipper.a) + (
                        world.clipper.rect_view_w * world.clipper.a) / 2

                    world.background_pos.y = (-1 * (pos.y - world.clipper.minimap_rect.y) * world.clipper.b) + (
                        world.clipper.rect_view_h * world.clipper.b) / 2

        # --------------Mouse Above---------------------------------------
        # --------------Process below-------------------------------------

        world.process(time_passed_seconds)

        if selected_building == "House":
            selected_img = placing_house_img
        elif selected_building == "LumberYard":
            selected_img = placing_lumberyard_img
        elif selected_building == "Dock":
            selected_img = placing_dock_img
        elif selected_building == "Manor":
            selected_img = placing_manor_img

        # --------------Process above-------------------------------------
        # --------------Render Below------------------------

        screen.fill((0, 0, 0))
        world.render_all(screen, time_passed_seconds, pos)

        world.grow_trees(world.baby_tree_locations)

        if selected_building is not None:
            if (pos.x > world.clipper.minimap_rect.x and pos.y > world.clipper.minimap_rect.y) or (
                    pos.x < world.clipper.side.w + 32):
                pass
            else:
                if not world.test_buildable(selected_building, 0, pos):
                    selected_img = bad_lumberyard_img
                blit_pos = world.get_tile_pos(pos - world.background_pos) * 32
                screen.blit(selected_img, ((blit_pos.x - (selected_img.get_width() - 32)) + world.background_pos.x,
                                           (blit_pos.y - (selected_img.get_height() - 32)) + world.background_pos.y))

        # This is for selecting-------------
        if draw and selected_building is None:
            # E712 comparison to True should be 'if cond is True:' or 'if cond:'
            # E711 comparison to None should be 'if cond is None:'
            current_mouse_pos = Vector2(*pygame.mouse.get_pos())

            lst = world.get_tile_array(start, ((current_mouse_pos.x - start.x) / 32, (current_mouse_pos.x - start.x) / 32))
            for i in lst:
                for j in i:
                    j.selected = 1

            select_surface = pygame.Surface((abs(current_mouse_pos.x - start.x), abs(current_mouse_pos.y - start.y)))
            select_surface.set_alpha(25)
            select_surface.fill((255, 255, 255))

            if current_mouse_pos.x - \
                    start.x <= 0 and current_mouse_pos.y < start.y and current_mouse_pos.x > start.x:
                newa = (current_mouse_pos.x - (current_mouse_pos.x - start.x), current_mouse_pos.y)
                screen.blit(select_surface, (newa))
            if current_mouse_pos.x - \
                    start.x <= 0 and current_mouse_pos.y > start.y and current_mouse_pos.x < start.x:
                newa = (current_mouse_pos.x, current_mouse_pos.y - (current_mouse_pos.y - start.y))
                screen.blit(select_surface, (newa))
            if current_mouse_pos.x - \
                    start.x > 0 and current_mouse_pos.y - start.y > 0:
                screen.blit(select_surface, (start))
            if current_mouse_pos.x - \
                    start.x < 0 and current_mouse_pos.y - start.y < 0:
                screen.blit(select_surface, (current_mouse_pos))
            pygame.draw.rect(
                screen, (255, 255, 255), (start, (current_mouse_pos.x - start.x, current_mouse_pos.y - start.y)), 1)
        # Selecting Above------------------

        # --------------Render Above------------------------

        pygame.display.flip()
        pygame.display.set_caption("VillagerSim! Have fun!")

    pygame.quit()
开发者ID:DaxHacker,项目名称:DealershipSimulation,代码行数:104,代码来源:NewVillagerSim.py


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