Пример #1
0
def run(window_size):
    pygame.init()
    cells = {}
    camera = Camera(window_size, cells)
    Cell.static_init(camera, cells)
    simulation = Simulation(camera, cells)
    clock = pygame.time.Clock()
    debug_mode = False

    while True:
        dt = clock.tick(FPS) / 1000
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    return
                elif event.key == pygame.K_F1:
                    debug_mode = not debug_mode
            camera.process_event(event)
            simulation.process_event(event)
        camera.update(dt)
        simulation.update(dt)
        camera.draw()
        if debug_mode:
            show_debug_info(camera, simulation, clock.get_fps())
        pygame.display.flip()
Пример #2
0
class Window(pyglet.window.Window):
    def __init__(self, map_file, config_file):
        super().__init__(resizable=True,
                         caption='Tourism Simulation',
                         visible=False)
        self.set_minimum_size(640, 480)
        self.set_maximum_size(2260, 3540)
        self.frame_rate = 1 / 60.0  # Target frame-rate, usually can't keep up

        self.icon1 = pyglet.image.load('./graphics/Icon1.png')
        self.icon2 = pyglet.image.load('./graphics/Icon2.png')
        self.set_icon(self.icon1, self.icon2)

        self.map = Map(self.width, self.height, map_file)
        self.set_visible(True)

        self.x = 800
        self.y = -800

        self.simulation = Simulation(2260, 3540, self.width, self.height,
                                     config_file)

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if (buttons & mouse.LEFT) or (buttons & mouse.MIDDLE):
            self.x = self.x + dx
            self.y = self.y + dy
            if self.x > 1120:
                self.x = 1120
                pass

            if self.x < self.width - 1120:
                self.x = self.width - 1120
                pass

            if self.y > 1760:
                self.y = 1760
                pass
            pass

        if self.y < self.height - 1760:
            self.y = self.height - 1760
            pass

    def update(self, dt):
        self.simulation.update(dt)

    def on_draw(self):
        self.clear()
        self.map.draw(self.width, self.height, self.x, self.y)
        self.simulation.draw(self.x, self.y, self.width, self.height)