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


Python Picture.draw_centered方法代码示例

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


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

示例1: run_title

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import draw_centered [as 别名]
def run_title():
    class Title: pass
    run.quit = False
    game = run.game

    title = Picture("title.png")
    subtitle = Picture("subtitle.png")
    menu = Picture("menu.png")
    menu2 = Picture("menu2.png")
    menu3 = Picture("menu3.png")
    menu3hl = Picture("menu3hl.png")

    cursor = Picture("mouse.png")

    if not run.config.nomusic:
        pygame.mixer.music.load(data.filepath("loop/menu.ogg"))
        pygame.mixer.music.play(-1)

    def button_ng():
        run.run_game()
        if not run.config.nomusic:
            pygame.mixer.music.load(data.filepath("loop/menu.ogg"))
            pygame.mixer.music.play(-1)
        title.next = pygame.time.get_ticks() + 1000.0 / run.FPS

    def button_next():
        if run.last_level < run.config.level: run.last_level += 1

    def button_prev():
        if run.last_level > 1: run.last_level -= 1

    def button_fs():
        run.config.fullscreen = not run.config.fullscreen
        run.config.save()
        main.main()

    def button_nm():
        run.config.nomusic = not run.config.nomusic
        if not run.config.nomusic:
            pygame.mixer.music.load(data.filepath("loop/menu.ogg"))
            pygame.mixer.music.play(-1)
        else:
            pygame.mixer.music.stop()
        run.config.save()

    def button_q():
        run.quit = True

    rects = (
        (220, 274, 417, 323, button_ng),
        (170, 344, 320, 400, button_fs),
        (340, 344, 470, 400, button_nm),
        (283, 417, 358, 466, button_q),
        (130, 260, 210, 286, button_next),
        (130, 301, 210, 326, button_prev),
        )

    selected = None
    t = 0
    title.next = pygame.time.get_ticks() + 1000 / run.FPS
    while not run.quit:

        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                run.quit = True
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    rects[3][4]()
                if e.key == pygame.K_RETURN:
                    rects[0][4]()
            elif e.type == pygame.MOUSEBUTTONUP:
                x, y = e.pos
                if e.button == 1:
                    if selected != None:
                        selected[4]()

        mx, my = pygame.mouse.get_pos()

        glClearColor(1, 0.6, 0.4, 1)
        glClear(GL_COLOR_BUFFER_BIT)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glEnable(GL_TEXTURE_2D)
        glEnable(GL_BLEND)
        glBlendFunc(GL_ONE, GL_ONE)

        t += 1
        tt = (t * 4) % (480 + 512)

        game.background1.draw_centered(0, 0)
        game.background1.draw_centered(640, 480)
        game.background1.draw_centered(320, tt)
        game.background1.draw_centered(320, tt - 512 - 480)

        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        selected = None
        black = {"red" : 0, "green" : 0, "blue" : 0}
#.........这里部分代码省略.........
开发者ID:allefant,项目名称:allefant5,代码行数:103,代码来源:title.py

示例2: __init__

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import draw_centered [as 别名]

#.........这里部分代码省略.........
                game.remove(orb)
            elif orb.__class__ == Wall:
                a = orb.angle * math.pi / 180.0
                x = orb.x
                y = orb.y
                ax = math.sin(a)
                ay = -math.cos(a)
                game.place(x + 42 * ax, y + 42 * ay, 19, a, Orb)
                game.place(x - 42 * ax, y - 42 * ay, 19, a, Orb)
                game.place(x + 21 * ax, y + 21 * ay, 19, a, Orb)
                game.place(x - 21 * ax, y - 21 * ay, 19, a, Orb)
            elif orb.__class__ == Block1:
                a = orb.angle * math.pi / 180.0
                x = orb.x
                y = orb.y
                ax = math.cos(a)
                ay = math.sin(a)
                game.place(x + 42 * ax, y + 42 * ay, 19, a, Orb)
                game.place(x - 42 * ax, y - 42 * ay, 19, a, Orb)
                game.place(x + 21 * ax, y + 21 * ay, 19, a, Orb)
                game.place(x - 21 * ax, y - 21 * ay, 19, a, Orb)

    def colliders(self, x, y, r):
        orb = Orb(x, y, r)
        orb.hash = self.spatialhash
        return [x for x in orb.colliders() if not x.__class__ == InverseOrb]

    def render(self):
        px = (self.player.x - self.x) * 0.25
        py = (self.player.y - self.y) * 0.25
        glPushMatrix()
        glScalef(1 + 0.01 * math.cos(self.twist * math.pi * 2 / 120.0),
            1 + 0.01 * math.sin(self.twist * math.pi * 2 / 120.0), 1)
        self.background1.draw_centered(self.view.x - px, self.view.y - py)
        glPopMatrix()

        drawn = 0
        diagonal = (self.vw ** 2 + self.vh ** 2) ** 0.5
        x, y = self.player.x, self.player.y
        pvs = self.decohash.get_in_circle(x, y, diagonal / 2)
        for orb in pvs:
            orb.draw()
            drawn += 1

        pvs = self.spatialhash.get_in_circle(x, y, diagonal / 2)
        for layer in [-1, 0, 1]:
            for orb in pvs:
                if orb.layer() == layer:
                    orb.draw()
                    drawn += 1

        if run.run.debugging:
            for layer in [-1, 0, 1]:
                for orb in pvs:
                    if orb.layer() == layer:
                        orb.draw_debug()

        glLoadIdentity()
        run.run.font.write(0, 443, "Level %d/6" % self.level, alpha = 0.8)

        run.run.font.write(320, 443, "Health %.f" % self.player.health,
            red = 1, green = 0, blue = 0, alpha = 0.8, center = True)

        run.run.font.write(640, 443, "Coins %d/%d" % (self.player.coins, self.coins),
            red = 1, green = 0.8, blue = 0.1, alpha = 0.8, right = True)
开发者ID:allefant,项目名称:allefant5,代码行数:69,代码来源:game.py

示例3: run_game

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import draw_centered [as 别名]

#.........这里部分代码省略.........
        game.rightx = rightx
        game.righty = righty

        if run.paused:
            pass
        elif run.message:
            run.message.tick()
        elif run.game_over:
            run.game_over = False
            quit = True
        elif run.level_done:
            run.level_done = False
            run.last_level += 1
            game = run.game = game.load_level(run.last_level)
            if run.last_level > run.config.level:
                run.config.level = run.last_level
                run.config.save()
            continue
        else:
            p.kx = kx
            p.ky = ky
            game.tick()

        glClearColor(0, 0, 0, 1)
        glClear(GL_COLOR_BUFFER_BIT)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        game.view.angle = 180 * math.atan2(downx, downy) / math.pi
        p.angle = -game.view.angle
        game.view.x = p.x
        game.view.y = p.y
        glTranslate(game.vw / 2, game.vh / 2, 0)
        glRotate(game.view.angle, 0, 0, 1)
        glTranslate(-game.view.x, -game.view.y, 0)

        if not debug_no_render:
            game.render()

        glLoadIdentity()

        def show_fps():
            now = pygame.time.get_ticks()
            while fps and fps[0] <= now - 1000:
                fps.pop(0)
            ds = []
            for i in range(1, len(fps)):
                ds.append(1.0 * fps[i] - fps[i - 1])

            if ds:
                avg = sum(ds) / len(ds)
                avg = 1000.0 / avg
                a = 1000.0 / min(ds)
                b = 1000.0 / max(ds)
            else:
                avg = a = b = 0

            run.font.write(640, 0, "FPS: %.1f (%.1f - %.1f)" % (avg, b, a),
                right = True)
        #show_fps()

        if run.help:
            helptext = "\n"
            x = 0
            pos = 0
            for i in range(0, len(edit.commands), 2):
                func = edit.commands[i + 1]
                if func.__doc__: helptext += func.__doc__ + "\n"
                else: helptext += "?\n"
                pos += 1
                if pos == 10:
                    run.font.write(x, 0, helptext)
                    x += 150
                    pos = 0
                    helptext = "\n"
            run.font.write(x, 0, helptext)

        if run.message:
            run.message.display()

        if run.editing:
            cursor.draw_centered(mx, my)

        pygame.display.flip()

        t = pygame.time.get_ticks()
        fps.append(t)
        w = int(next - t)

        if w > 0:
            pygame.time.wait(w)
        # If we're lagging behind, we can either skip rendering some frames,
        # or slow down. We choose the latter.
        if w < -500:
            next = t
        next += 1000.0 / run.FPS
开发者ID:allefant,项目名称:allefant5,代码行数:104,代码来源:run.py


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