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


Python Camera.get_bounds方法代码示例

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


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

示例1: CreatureSim

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import get_bounds [as 别名]
class CreatureSim(PyGameBase):
    """Runs the creature sim game"""
    CAMERA_MOVE_SPEED = .5

    GAME_SPEED_INCREMENT = .1
    MAX_GAME_SPEED = 2.0
    MIN_GAME_SPEED = .1
    WORLD_WIDTH = 100000
    WORLD_HEIGHT = 100000
    SELECTED_COLOR = GREEN

    def __init__(self):
        super().__init__()
        self.infoObject = pygame.display.Info()
        self.CAM_HEIGHT = self.infoObject.current_h - 80
        self.CAM_WIDTH = int(self.infoObject.current_w-100)
        self.num_of_creatures = 180
        self.num_of_food = 100
        self.game_bounds = (-5000, 5000)

        self.running = True
        # self.camera = Camera(self.CAM_WIDTH, self.CAM_HEIGHT, x=-(self.CAM_WIDTH / 2), y=-(self.CAM_HEIGHT / 2))
        self.camera = Camera(self.CAM_WIDTH, self.CAM_HEIGHT, x=0, y=0, zoom=1.0)
        self.screen = pygame.display.set_mode((self.CAM_WIDTH, self.CAM_HEIGHT))

        self.fullscreen = False

        # QuadTree for collision detection
        self.quadtree = QuadTree(
            bounds=(
                -self.WORLD_WIDTH/2,
                -self.WORLD_HEIGHT/2,
                self.WORLD_WIDTH,
                self.WORLD_HEIGHT),
            depth=9)
 
        self.ui = UserInterface(self.screen)

        self.dt = 0

        # Will draw the quadtree overlay if true
        self.draw_quadtree = False

        self.paused = False

        # When the user clicks on the screen it's position will be stored here
        self.mouse_screen_position = None
        self.mouse_real_position = None

        # How fast everything moves
        self.game_speed = 1.0

        self.selected_creature = None

        self.follow_creature = False

        self.breeder = Breeder()

        self.population_stats = StatsTracker()

        self.spinner = Background()


    def run(self):
        self.load()
        self.setup_keys()
        self.game_loop()

    def game_loop(self):
        while self.running:
            self.dt = self.clock.tick()
            self.screen.fill(BLACK)

            self.handle_events()
            self.handle_key_presses()

            self.update_creature_positions()
            self.scene_graph.update()

            self.center_camera()

            self.quadtree.update_objects(self.entities)

            self.handle_collisions()
            self.do_obj_events()
            self.render_frame()

    def render_frame(self):
        pygame.display.set_caption(str(self.clock.get_fps()))


        # Find all objects in nodes intersecting the screen
        objects_to_draw = self.quadtree.get_objects_at_bounds(self.camera.get_bounds())

        for scene_object in objects_to_draw:
            scene_object.draw(self.screen, self.camera)

        if self.draw_quadtree:
            self.quadtree.draw_tree(self.screen, self.camera)

#.........这里部分代码省略.........
开发者ID:jpinsonault,项目名称:creature_simulation,代码行数:103,代码来源:CreatureSim.py


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