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


Python Atom.reset_with_values方法代码示例

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


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

示例1: __init__

# 需要导入模块: from atom import Atom [as 别名]
# 或者: from atom.Atom import reset_with_values [as 别名]

#.........这里部分代码省略.........
        self.newTicks = pygame.time.get_ticks()
        delta = self.newTicks - self.oldTime
        
        # react to player inputs
        if not self.playerWon:
            if not self.playerLost:
                self.apply_player_direction(delta)
        
        # perform all atoms processes
        largestAtom = None
        smallestAtom = None
        for atom in self.atoms:
            if largestAtom == None:
                largestAtom = atom
                smallestAtom = atom
                
            # process atom behaviours    
            atom.process(delta, self.atoms)
            atom.move(delta)
            
            # find the largest atom to see if the player has won
            if atom.radius > largestAtom.radius:
                largestAtom = atom
                
            # find out if the player is the smallest atom
            if atom.radius < smallestAtom.radius:
                smallestAtom = atom
            
        if largestAtom == self.playerAtom:
            self.playerWon = True
            
        if smallestAtom == self.playerAtom:
            self.playerLost = True        
            
        # update the cameras status
        self.camera.process()
        
    def render(self):
        # draw a black background
        self.screen.fill((0,0,0))
        
        # draw all atoms
        for atom in self.atoms:
            atom.draw(self.camera)
           
        # the player has become the largest atom!
        if self.playerWon:
            self.display_player_won()
            
        # the player has become the largest atom!
        if self.playerLost:
            self.display_player_lost()        
            
        # push the rendered scene to the screen 
        pygame.display.flip()
    
    def display_player_won(self):
        text = self.font.render('OWNASAURUS REX!', True, (255,255,255))
        textRect = text.get_rect()
        textRect.centerx = self.windowWidth / 2
        textRect.centery = self.windowHeight / 2
        
        self.screen.blit(text, textRect)
        
        self.display_reset_message()
        
    def display_player_lost(self):
        text = self.font.render('You Lost!', True, (255,255,255))
        textRect = text.get_rect()
        textRect.centerx = self.windowWidth / 2
        textRect.centery = self.windowHeight / 2
        
        self.screen.blit(text, textRect)   
        
        self.display_reset_message()
            
    def display_reset_message(self):
        text = self.font.render("Press 'r' to reset.", True, (255,255,255))
        textRect = text.get_rect()
        textRect.centerx = self.windowWidth / 2
        textRect.centery = (self.windowHeight / 2) + 40
        
        self.screen.blit(text, textRect)          

    def reset_game(self):
        for atom in self.atoms:
            x = random.randint(1, self.worldWidth)
            y = random.randint(1, self.worldHeight)            
            mass = random.randint(1, 20)
            
            atom.reset_with_values(x, y, mass)
            
        self.camera.x = self.windowWidth / 2
        self.camera.y = self.windowHeight / 2
        
        self.playerAtom.reset_with_values(self.camera.x, 
                                           self.camera.y,
                                           PLAYER_STARTING_MASS)
        self.playerWon = False
        self.playerLost = False
开发者ID:MikeHibbert,项目名称:Osmos-Clone,代码行数:104,代码来源:main.py


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