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


Python Window.close方法代码示例

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


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

示例1: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class Gameloop(object):

    def __init__(self):
        self.window = None

    def init(self):
        self.world = World()
        self.world.init()
        populate(self.world)

        bitmaps = Bitmaps()
        bitmaps.load()
        self.render = Render(bitmaps)
        self.camera = Camera(zoom=10.0)

        self.window = Window(fullscreen=False, visible=False)
        self.window.set_exclusive_mouse(True)
        self.window.on_draw = self.draw
        self.window.on_resize = self.render.resize

        self.controls = Controls(self.world.bat)
        self.window.set_handlers(self.controls)

        self.render.init()
        clock.schedule(self.update)
        self.hud_fps = clock.ClockDisplay()

        self.window.set_visible()


    def update(self, dt):
        # scale dt such that the 'standard' framerate of 60fps gives dt=1.0
        dt *= 60.0
        # don't attempt to compensate for framerate of less than 30fps. This
        # guards against huge explosion when game is paused for any reason
        # and then restarted
        dt = min(dt, 2)
        self.controls.update()
        self.world.update()
        self.window.invalid = True

    def draw(self):
        self.window.clear()
        self.camera.world_projection(self.window.width, self.window.height)
        self.camera.look_at()
        self.render.draw(self.world)

        self.hud_fps.draw()

        return EVENT_HANDLED

    def stop(self):
        if self.window:
            self.window.close()
开发者ID:tartley,项目名称:pyong,代码行数:56,代码来源:gameloop.py

示例2: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class Gameloop(object):
    def __init__(self):
        self.camera = None
        self.projection = None
        self.render = None
        self.window = None
        self.world = None
        self.fpss = []

    def prepare(self, options):
        self.window = Window(fullscreen=options.fullscreen, vsync=False, visible=False, resizable=True)
        self.window.on_draw = self.draw
        self.projection = Projection(self.window.width, self.window.height)
        self.window.on_resize = self.projection.resize

        self.world = World()

        self.camera = Camera()
        self.world.add(GameItem(camera=self.camera, position=Origin, move=WobblyOrbit(32, 1, speed=-0.5)))

        self.render = Render(self.world)
        self.render.init()
        pyglet.clock.schedule(self.update)
        self.clock_display = pyglet.clock.ClockDisplay()

        vs = VertexShader(join("flyinghigh", "shaders", "lighting.vert"))
        fs = FragmentShader(join("flyinghigh", "shaders", "lighting.frag"))
        shader = ShaderProgram(vs, fs)
        shader.use()

    def update(self, dt):
        # self.fpss.append(1/max(1e-3, dt))
        dt = min(dt, 1 / 30)
        self.world.update(dt)
        self.window.invalid = True

    def draw(self):
        self.window.clear()

        self.projection.set_perspective(45)
        self.camera.look_at(Origin)
        self.render.draw()

        self.projection.set_screen()
        self.camera.reset()
        self.render.draw_hud(self.clock_display)

        return EVENT_HANDLED

    def stop(self):
        if self.window:
            self.window.close()
开发者ID:tartley,项目名称:flyinghigh-opengl-from-python,代码行数:54,代码来源:gameloop.py

示例3: PygletApp

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class PygletApp(object):

    def __init__(self):
        self.window = Window(visible=False, fullscreen=False)
        self.window.on_resize = self.on_resize
        self.window.on_draw = self.on_draw
        self.window.on_key_press = self.on_key_press

        self.files = SvgFiles()

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(
            0.0, -0.0, 1.0,  # eye
            0.0, -0.0, -1.0, # lookAt
            0.0, 1.0, 0.0)  # up


    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT)
        self.files.draw()
        return EVENT_HANDLED


    def on_resize(self, width, height):
        # scale is distance from screen centre to top or bottom, in world coords
        scale = 110
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        aspect = width / height
        gluOrtho2D(
            -scale * aspect,
            +scale * aspect,
            -scale,
            +scale)
        return EVENT_HANDLED


    def on_key_press(self, symbol, modifiers):
        if symbol == key.ESCAPE:
            self.window.close()
            return
        self.files.next()


    def run(self):
        self.window.set_visible()
        app.run()
开发者ID:msarch,项目名称:py,代码行数:50,代码来源:demo.py

示例4: App

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class App(object):

    def __init__(self, pmap):
        self.world = World(pmap)
        self.win = Window(width=pmap['bounds'][2], height=pmap['bounds'][3])
#        pyglet.clock.set_fps_limit(10)
#        pyglet.clock.set_fps_limit(60)
        self.win.push_handlers(self.on_key_press)
        self.fullscreen = False

    def main_loop(self):
        self.world.annealing.kickoff()
        while not (self.win.has_exit or self.world.finished):
            self.win.dispatch_events()
            if (not self.world.finished) and (not self.world.pause):
                self.world.update()
                if (self.world.showvisuals):
                    self.world.draw()
            pyglet.clock.tick()
            self.win.flip()
        self.win.close()

    def on_key_press(self, symbol, modifiers):        
        # IDEA more key toggles, make it a dictionary
        if symbol == key.D:
            self.world.showdebug = not self.world.showdebug
        elif symbol == key.F:
            self.fullscreen = not self.fullscreen
            self.win.set_fullscreen(fullscreen=self.fullscreen)
            self.world.draw()
        elif symbol == key.G:
            self.world.showgrid = not self.world.showgrid
        elif symbol == key.S:
            self.world.pause = not self.world.pause
        elif symbol == key.U:
            self.world.showUI = not self.world.showUI
        elif symbol == key.V:
            self.world.showvisuals = not self.world.showvisuals
开发者ID:ajhalme,项目名称:maplabel,代码行数:40,代码来源:Maplabel.py

示例5: SpriteModelTest

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class SpriteModelTest(unittest.TestCase):

    def setUp(self):
        self.w = Window(width=1, height=1, visible=False)
        self.s = Sprite(10, 10, 10, 10,
                        Image2d.from_image(SolidColorImagePattern((0, 0, 0,
                                                                   0)).create_image(
                            1, 1)))
        assert (self.s.x, self.s.y) == (10, 10)

    def tearDown(self):
        self.w.close()

    def test_top(self):
        assert self.s.top == 20
        self.s.top = 10
        assert (self.s.x, self.s.y) == (10, 0)

    def test_bottom(self):
        assert self.s.bottom == 10
        self.s.bottom = 0
        assert (self.s.x, self.s.y) == (10, 0)

    def test_right(self):
        assert self.s.right == 20
        self.s.right = 10
        assert (self.s.x, self.s.y) == (0, 10)

    def test_left(self):
        assert self.s.left == 10
        self.s.left = 0
        assert (self.s.x, self.s.y) == (0, 10)

    def test_center(self):
        assert self.s.center == (15, 15)
        self.s.center = (5, 5)
        assert (self.s.x, self.s.y) == (0, 0)

    def test_midtop(self):
        assert self.s.midtop == (15, 20)
        self.s.midtop = (5, 5)
        assert (self.s.x, self.s.y) == (0, -5)

    def test_midbottom(self):
        assert self.s.midbottom == (15, 10)
        self.s.midbottom = (5, 5)
        assert (self.s.x, self.s.y) == (0, 5)

    def test_midleft(self):
        assert self.s.midleft == (10, 15)
        self.s.midleft = (5, 5)
        assert (self.s.x, self.s.y) == (5, 0)

    def test_midright(self):
        assert self.s.midright == (20, 15)
        self.s.midright = (5, 5)
        assert (self.s.x, self.s.y) == (-5, 0)

    def test_topleft(self):
        assert self.s.topleft == (10, 20)
        self.s.topleft = (5, 5)
        assert (self.s.x, self.s.y) == (5, -5)

    def test_topright(self):
        assert self.s.topright == (20, 20)
        self.s.topright = (5, 5)
        assert (self.s.x, self.s.y) == (-5, -5)

    def test_bottomright(self):
        assert self.s.bottomright == (20, 10)
        self.s.bottomright = (5, 5)
        assert (self.s.x, self.s.y) == (-5, 5)

    def test_bottomleft(self):
        assert self.s.bottomleft == (10, 10)
        self.s.bottomleft = (5, 5)
        assert (self.s.x, self.s.y) == (5, 5)

    unittest.main()
开发者ID:bitcraft,项目名称:pyglet,代码行数:81,代码来源:SPRITE_MODEL.py

示例6: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]

#.........这里部分代码省略.........
        self.level = None


    def prepare(self, options):
        self.window = Window(
            fullscreen=options.fullscreen,
            vsync=options.vsync,
            visible=False,
            resizable=True)
        self.window.on_draw = self.draw_window

        self.world = World()
        self.player = Player(self.world)
        self.camera = GameItem(
            position=origin,
            update=CameraMan(self.player, (3, 2, 0)),
        )
        self.level_loader = Level(self)
        success = self.start_level(1)
        if not success:
            logging.error("ERROR, can't load level 1")
            sys.exit(1)

        self.update(1/60)

        self.window.push_handlers(KeyHandler(self.player))

        self.render = Render(self.world, self.window, self.camera)
        self.render.init()

        self.music = Music()
        self.music.load()
        self.music.play()


    def run(self):
        pyglet.clock.schedule(self.update)
        self.window.set_visible()
        self.window.invalid = False
        pyglet.app.run()


    def update(self, dt):
        if self.options.print_fps:
            self.fpss.append(1/max(1e-6, dt))
        dt = min(dt, 1 / 30)
        self.time += dt

        for item in self.world:
            if hasattr(item, 'update'):
                item.update(item, dt, self.time)

        if self.player_at_exit():
            self.world.remove(self.player)
            pyglet.clock.schedule_once(
                lambda *_: self.start_level(self.level + 1),
                1.0
            )

        self.window.invalid = True


    def start_level(self, n):
        success = self.level_loader.load(self.world, n)
        if not success:
            logging.info('No level %d' % (n,))
            self.stop()
            return False
               
        self.level = n
        pyglet.clock.schedule_once(
            lambda *_: self.world.add(self.player),
            2.0,
        )
        return True


    def player_at_exit(self):
        items = self.world.collision.get_items(self.player.position)
        if any(hasattr(item, 'exit') for item in items):
            dist2_to_exit = dist2_from_int_ords(self.player.position)
            if dist2_to_exit < EPSILON2:
                return True
        return False


    def draw_window(self):
        self.window.clear()
        self.render.draw_world()
        if self.options.display_fps:
            self.render.draw_hud()
        self.window.invalid = False
        return EVENT_HANDLED


    def stop(self):
        if self.window:
            self.window.close()
        if self.options.print_fps:
            print '  '.join("%6.1f" % (dt, ) for dt in self.fpss)
开发者ID:mjs,项目名称:pyweek11-cube,代码行数:104,代码来源:gameloop.py

示例7: glPopMatrix

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
        glPopMatrix()

    camera.hud_mode(win.width, win.height)
    clockDisplay.draw()

def update(dt):
    for idx, entity in enumerate(entities):
        entity.angle += ((entity.x) + abs(entity.y)) / 10000
        entity.x += sin(entity.angle) / (1+idx) * 10
        entity.y -= cos(entity.angle) / (1+idx) * 10
    camera.zoom(1.008)

clock.schedule(update) # triggers on_draw event when done

key_handlers = {
    key.ESCAPE: lambda: win.close(),
    key.PAGEUP: lambda: camera.zoom(2),
    key.PAGEDOWN: lambda: camera.zoom(0.5),
    key.LEFT: lambda: camera.pan(camera.scale, -pi/2),
    key.RIGHT: lambda: camera.pan(camera.scale, +pi/2),
    key.DOWN: lambda: camera.pan(camera.scale, pi),
    key.UP: lambda: camera.pan(camera.scale, 0),
    key.COMMA: lambda: camera.tilt(-1),
    key.PERIOD: lambda: camera.tilt(+1),
}

@win.event
def on_key_press(symbol, modifiers):
    handler = key_handlers.get(symbol, lambda: None)
    handler()
开发者ID:msarch,项目名称:py,代码行数:32,代码来源:run.py

示例8: int

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
numsprites = int(sys.argv[1])
for i in range(numsprites):
    x = random.randint(0, w.width-img.width)
    y = random.randint(0, w.height-img.height)
    s = BouncySprite(x, y, img.width, img.height, img)
    s.dx = random.randint(-10, 10)
    s.dy = random.randint(-10, 10)
    sprites.append(s)

view = FlatView.from_window(w, sprites=sprites)
view.fx, view.fy = w.width/2, w.height/2

t = 0
numframes = 0
while 1:
    if w.has_exit:
        print 'FPS:', clock.get_fps()
        print 'us per sprite:', float(t) / (numsprites * numframes) * 1000000

        break
    t += clock.tick()
    w.dispatch_events()
    for s in sprites: s.update()
    view.clear()
    view.draw()
    w.flip()
    numframes += 1
w.close()


开发者ID:DatRollingStone,项目名称:nwidget,代码行数:30,代码来源:los.py

示例9: MapModelTest

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class MapModelTest(unittest.TestCase):
    def setUp(self):
        self.w = Window(width=1, height=1, visible=False)

    def tearDown(self):
        self.w.close()

    def test_rect_neighbor(self):
        # test rectangular tile map
        #    +---+---+---+
        #    | d | e | f |
        #    +---+---+---+
        #    | a | b | c |
        #    +---+---+---+
        m = gen_rect_map(rmd, 10, 16)
        t = m.get_cell(0,0)
        assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
        assert m.get_neighbor(t, m.DOWN) is None
        assert m.get_neighbor(t, m.UP).properties['meta'] == 'd'
        assert m.get_neighbor(t, m.LEFT) is None
        assert m.get_neighbor(t, m.RIGHT).properties['meta'] == 'b'
        t = m.get_neighbor(t, m.UP)
        assert (t.x, t.y) == (0, 1) and t.properties['meta'] == 'd'
        assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'a'
        assert m.get_neighbor(t, m.UP) is None
        assert m.get_neighbor(t, m.LEFT) is None
        assert m.get_neighbor(t, m.RIGHT).properties['meta'] == 'e'
        t = m.get_neighbor(t, m.RIGHT)
        assert (t.x, t.y) == (1, 1) and t.properties['meta'] == 'e'
        assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'b'
        assert m.get_neighbor(t, m.UP) is None
        assert m.get_neighbor(t, m.RIGHT).properties['meta'] == 'f'
        assert m.get_neighbor(t, m.LEFT).properties['meta'] == 'd'
        t = m.get_neighbor(t, m.RIGHT)
        assert (t.x, t.y) == (2, 1) and t.properties['meta'] == 'f'
        assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'c'
        assert m.get_neighbor(t, m.UP) is None
        assert m.get_neighbor(t, m.RIGHT) is None
        assert m.get_neighbor(t, m.LEFT).properties['meta'] == 'e'
        t = m.get_neighbor(t, m.DOWN)
        assert (t.x, t.y) == (2, 0) and t.properties['meta'] == 'c'
        assert m.get_neighbor(t, m.DOWN) is None
        assert m.get_neighbor(t, m.UP).properties['meta'] == 'f'
        assert m.get_neighbor(t, m.RIGHT) is None
        assert m.get_neighbor(t, m.LEFT).properties['meta'] == 'b'

    def test_rect_coords(self):
        # test rectangular tile map
        #    +---+---+---+
        #    | d | e | f |
        #    +---+---+---+
        #    | a | b | c |
        #    +---+---+---+
        m = gen_rect_map(rmd, 10, 16)

        # test tile sides / corners
        t = m.get_cell(0,0)
        assert t.top == 16
        assert t.bottom == 0
        assert t.left == 0
        assert t.right == 10
        assert t.topleft == (0, 16)
        assert t.topright == (10, 16)
        assert t.bottomleft == (0, 0)
        assert t.bottomright == (10, 0)
        assert t.midtop == (5, 16)
        assert t.midleft == (0, 8)
        assert t.midright == (10, 8)
        assert t.midbottom == (5, 0)

    def test_rect_pixel(self):
        # test rectangular tile map
        #    +---+---+---+
        #    | d | e | f |
        #    +---+---+---+
        #    | a | b | c |
        #    +---+---+---+
        m = gen_rect_map(rmd, 10, 16)
        t = m.get(0,0)
        assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
        t = m.get(9,15)
        assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
        t = m.get(10,15)
        assert (t.x, t.y) == (1, 0) and t.properties['meta'] == 'b'
        t = m.get(9,16)
        assert (t.x, t.y) == (0, 1) and t.properties['meta'] == 'd'
        t = m.get(10,16)
        assert (t.x, t.y) == (1, 1) and t.properties['meta'] == 'e'

    def test_hex_neighbor(self):
        # test hexagonal tile map
        # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
        #   /d\ /h\
        # /b\_/f\_/
        # \_/c\_/g\
        # /a\_/e\_/
        # \_/ \_/ 
        m = gen_hex_map(hmd, 32)
        t = m.get_cell(0,0)
        assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
#.........这里部分代码省略.........
开发者ID:DatRollingStone,项目名称:nwidget,代码行数:103,代码来源:MAP_MODEL.py

示例10: Game

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class Game(object):

    INITIAL_UPDATE_INTERVAL = UPDATE_INTERVAL

    def __init__(self):
        impl.funcs.load_resources()
        self.gameInfo = GameInfo()
        self.win = Window(FIELD_WIDTH, FIELD_HEIGHT)
        self.win.set_caption("snake")
        impl.funcs.setup_background_color()
        impl.funcs.setup_opengl_blend_func()
        self.gameField = GameField(self.gameInfo, self.win)
        self.menu = Menu(FIELD_WIDTH//2, FIELD_HEIGHT//2, self.game_start_callback, self.game_exit_callback, self.win)
        self._overlay = None
        self._update_interval = Game.INITIAL_UPDATE_INTERVAL

        @self.gameField.event
        def on_restart_snake():
             unschedule(func=self.update)
             self._setup_overlay("restart")
             schedule_once(func=self.run_snake, delay=DELAY_FOR_NEW_RUN)

        @self.gameField.event
        def on_rerun_menu():
            unschedule(func=self.update)

            #reset current handler
            self.win.pop_handlers()
            #and setup update handler
            self.win.push_handlers(self.menu)
            self.menu.start_bgrn_animation()

        @self.gameField.event
        def on_game_over():
            unschedule(func=self.update)
            self._setup_overlay('game over...')
            schedule_once(func=self.game_exit_callback, delay=DELAY_FOR_EXIT)

        @self.gameField.event
        def on_score_up():
            if self._update_interval > MAX_UPDATE_SPEED_INTERVAL:
                self._update_interval -= UPDATE_INTERVAL_SPEED_DX
                unschedule(func=self.update)
                schedule_interval(func=self.update,interval=self._update_interval)

    def _setup_overlay(self, text):
        self._overlay = BouncingLabel(FIELD_WIDTH//2,FIELD_HEIGHT//2,text,DEFAULT_OVERLAY_COLOR)
        self.win.pop_handlers()
        def on_draw():
            self.win.clear()
            self._overlay.draw()
        self.win.push_handlers(on_draw)

        schedule_interval(func=self._overlay.update, interval=OVERLAY_UPDATE_INTERVAL)

    def game_start_callback(self):
        self._setup_overlay("start")
        schedule_once(func=self.run_snake, delay=DELAY_FOR_NEW_RUN)

    def game_exit_callback(self, *args):
        if self._overlay:
            unschedule(self._overlay.update)
            self._overlay = None

        self.win.pop_handlers()
        self.win.close()

    def start(self):
         self.win.push_handlers(self.menu)
         pyglet.app.run()

    def update(self, dt):
        if not self.gameInfo.pause:
            self.gameField.update(dt)

    def run_snake(self, *args):
        if self._overlay:
            unschedule(self._overlay.update)
            self._overlay = None

        #reset current handlers
        self.win.pop_handlers()

        self.gameInfo.pause = False
        self.gameField.reset()

        #setup new handlers
        self.win.push_handlers(self.gameField)

        #and setup update handler
        self._update_interval = Game.INITIAL_UPDATE_INTERVAL
        schedule_interval(func=self.update,interval=self._update_interval)
开发者ID:varnie,项目名称:snake,代码行数:94,代码来源:Game.py

示例11: Camera_test

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class Camera_test(MyTestCase):

    def setUp(self):
        self.window = Window(
            width=200, height=100, visible=False, caption="Camera_test setup")
        self.window.dispatch_events()
        glClearColor(0, 0, 0, 1)
        self.window.clear()
        self.world = World()
        self.camera = Camera((0, 0), 1)


    def tearDown(self):
        self.window.close()


    def test_constructor(self):
        camera = Camera((1, 2), 3, 4)
        self.assertEquals(camera.x, 1, "should init x")
        self.assertEquals(camera.y, 2, "should init y")
        self.assertEquals(camera.scale, 3, "should init scale")
        self.assertEquals(camera.angle, 4, "should init angle")


    def test_constructor_defaults_angle(self):
        camera = Camera((10, 20), 30)
        self.assertEquals(camera.angle, 0.0, "should init angle")


    def _draw_rect(self, backColor, polyColor, left, bottom, right, top):
        glClearColor(
            backColor[0]/255,
            backColor[1]/255,
            backColor[2]/255,
            1.0)
        self.window.clear()

        verts = [
            (left, bottom),
            (right, bottom),
            (right, top),
            (left, top),
        ]
        glColor3ub(*polyColor)
        glBegin(GL_TRIANGLE_FAN)
        for vert in verts:
            glVertex2f(*vert)
        glEnd()


    def test_world_projection_default(self):
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (90, 10, 129, 69)
        self.assert_world_projection(rect, expectedRect)


    def test_defect_pyglet_get_color_buffer_for_resized_windows(self):
        self.window.set_size(111, 222)
        self.window.dispatch_events()
        mgr = get_buffer_manager()
        col_buf = mgr.get_color_buffer()
        col_buf_size = col_buf.width, col_buf.height
        self.assertEquals(col_buf_size, (111, 222), "pyglet bug regression")


    def test_world_projection_strange_aspect(self):
        # create a new window, since
        # resizing the existing window doesn't work for some reason
        # even if we dispatch events. Default handlers?
        self.window.close()
        self.window = Window(
            width=100, height=200, visible=False,
            caption="world.test_projection_strange_aspect")
        self.window.dispatch_events()
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (40, 60, 79, 119)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_offset(self):
        self.camera.x, self.camera.y = (+0.5, +0.3)
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (65, 25, 104, 84)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_scale(self):
        self.camera.scale = 10
        rect = (-1, -2, +3, +4)
        expectedRect = (95, 30, 114, 59)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_angle(self):
        self.camera.angle = pi/2
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (60, 20, 119, 59)
        self.assert_world_projection(rect, expectedRect)


#.........这里部分代码省略.........
开发者ID:tartley,项目名称:sole-scion,代码行数:103,代码来源:camera_test.py

示例12: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import close [as 别名]
class Gameloop(object):

    instance = None

    def __init__(self):
        Gameloop.instance = self
        self.window = None
        self.camera = None
        self.world = None
        self.renderer = None
        self.paused = False
        self.fps_display = None
        Keyboard.handlers.update({
            key.PAGEUP: lambda: self.camera.zoom(2.0),
            key.PAGEDOWN: lambda: self.camera.zoom(0.5),
            key.ESCAPE: self.quit_game,
            key.PAUSE: self.toggle_pause,
            key.F12: lambda: save_screenshot(self.window),
        })


    def init(self, name, version):
        clock.set_fps_limit(FPS_LIMIT)
        self.fps_display = clock.ClockDisplay()

        self.camera = Camera((0, 0), 800)
        self.renderer = Renderer(self.camera)
        caption = '%s v%s' % (name, version)
        self.window = Window(
            caption=caption, fullscreen=True, visible=False)
        self.window.on_key_press = on_key_press
        self.window.push_handlers(Keyboard.keystate)

        graphics = load_graphics()

        self.world = World()
        builder = LevelBuilder()
        seed(1)
        builder.build(self.world, 75, graphics)

        self.world.player = Player()
        self.world.player.add_to_space(self.world.space, (0, 200), 0)
        self.world.chunks.update(self.world.player.chunks)


    def dispose(self):
        if self.window:
            self.window.close()


    def run(self):
        try:
            self.window.set_visible()
            while not self.window.has_exit:
                self.window.dispatch_events()
                clock.tick()
                if self.world and not self.paused:
                    self.world.tick(1/FPS_LIMIT)
                if self.world and hasattr(self.world, 'player'):
                    player_position = self.world.player.chunks[0].body.position
                    self.camera.x, self.camera.y = player_position
                    self.camera.angle = atan2(
                        player_position.x,
                        player_position.y)

                self.camera.update()
                if self.renderer:
                    aspect = (
                        self.window.width / self.window.height)
                    self.renderer.draw(self.world, aspect)
                self.camera.hud_projection(
                    (self.window.width, self.window.height))
                self.fps_display.draw()
                self.window.flip()
        finally:
            self.dispose()


    def toggle_pause(self):
        self.paused = not self.paused


    def quit_game(self):
        self.window.has_exit = True
开发者ID:tartley,项目名称:sole-scion,代码行数:86,代码来源:gameloop.py


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