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


Python Arena.render方法代码示例

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


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

示例1: Pong

# 需要导入模块: from arena import Arena [as 别名]
# 或者: from arena.Arena import render [as 别名]
class Pong(object):
    def __init__(self, file1=None, file2=None):
        pygame.mixer.pre_init(44100, -16, 2, 2048)
        pygame.init()
        self.fps = pygame.time.Clock()
        flag = DOUBLEBUF

        self.board = pygame.display.set_mode(screenRect, flag)
        pygame.display.set_caption('[ --- Pong --- ]')

        self.state = 1  # 1 - run, 0 - exit

        self.track = Tracking(file1, file2)

        self.sound = Sound()
        self.p1 = Paddle(self.board, (200,100,100),screenRect)
        self.p1.setInitialPostition(0,screenHeight/2)
        self.p2 = Paddle(self.board, (100,200,100),screenRect)
        self.p2.setInitialPostition(screenWidth-self.p2.get()['width'],screenHeight/2)
        self.ball = Ball(self.board, (50,50,250), screenRect, self.sound)
        self.ball.setInitialPostition(screenWidth/2,screenHeight/2)
        self.arena = Arena(self.board, screenRect)
        self.referee = Referee(self.ball, self.p1, self.p2, screenRect, self.sound)

        

        self.t = Thread(target=self.track.run)
        #self.track.run()
        self.t.start()

        self.p1_pos = 0
        self.p2_pos = 0

        self.loop()

    def movep1(self, diry):
       '''Player1 moves support'''
       self.p1.move(diry)

    def movep2(self, diry):
       '''Player2 moves support'''
       self.p2.move(diry)

    def game_exit(self):
        exit()

    def loop(self):
        flaga = 1
        while self.state==1:
            for event in pygame.event.get():
                if event.type==QUIT or (event.type==KEYDOWN and event.key==K_ESCAPE):
                   self.state=0

            keys = pygame.key.get_pressed()


            dirp1 = copysign(1, self.track.p1_position - self.p1_pos)
            dirp2 = copysign(1, self.track.p2_position - self.p2_pos)

            self.p1_pos += dirp1
            self.p2_pos += dirp2

            self.p1.set(self.track.p1_position+45)
            self.p2.set(self.track.p2_position+45)
            
            if keys[K_f]:
                pygame.display.toggle_fullscreen()

            self.arena.render(self.track.frame)

            font = pygame.font.Font("gfx/ATARCC__.TTF",40)
            text1 = font.render('P1={}'.format(self.p1.getScore()), True,(200,200,200))
            text2 = font.render('P2={}'.format(self.p2.getScore()), True,(200,200,200))
                   
            quartWidth = screenWidth/4
            self.board.blit(text1,(quartWidth * 1 - quartWidth/2,10))
            self.board.blit(text2,(quartWidth * 3 - quartWidth/2,10))

            self.p1.render()
            self.p2.render()
            self.ball.render()
            self.referee.judge()

            pygame.display.flip()   # wyswietlamy obrazki
            self.fps.tick(80)

        self.track.running = False 
        self.game_exit()
开发者ID:piotut,项目名称:Pong,代码行数:90,代码来源:pong.py


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