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


Python Background.scroll方法代码示例

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


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

示例1: Game

# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import scroll [as 别名]

#.........这里部分代码省略.........
                    self.explodeSnd.play()
                    
            # check for collisions between powerUps and the user
            for powerUp in self.powerUpSprites:
                userHit = pygame.sprite.spritecollide(powerUp,self.userSprites,False)
                
                # if there was a collision
                if userHit:
                    self.powerUpSprites.remove(powerUp) # remove object
                    powerUp.pickUp(self.userShip)
                    self.powerUpSnd.play()                # no sound yet!!
            # =============================================================
                    
            # if user is dead
            if self.userShip.shield <= 0:
                self.userShip.shield = 0        # round shield to 0
                self.gameState = "gameOver"     # change state to gameOver            
        # ====================================================================
        
        # Game Over ==========================================================
        elif self.gameState == "gameOver":            
            pass
        # ====================================================================
        else:
            pass # throw exception!
            
    def draw(self,screen):
    
        # Menu ===============================================================
        if self.gameState == "menu":
            self.menu.draw(screen)
        # ====================================================================

        # Pause ==============================================================
        if self.gameState == "pause":
            self.pause.draw(screen)
        # ====================================================================
        
        # Volume =============================================================
        if self.gameState == "volume":
            self.volume.draw(screen)
        # ====================================================================
        
        # Credits ============================================================
        if self.gameState == "credits":           
            self.credits.draw(screen)
        # ====================================================================
        
        # Game ===============================================================
        elif self.gameState == "game":
            # erase screen
            screen.fill(BLACK)

            # draw background - since the background is scrolling
            # we shall draw two side by side to prevent the background from ending
            # this way it repeats itself
            screen.blit(self.backg.image,(self.backg.x,self.backg.y))
            screen.blit(self.backg.image,(self.backg.x + self.backg.width,self.backg.y))
                           
            # draw sprites onto the screen
            self.userSprites.draw(screen)
            self.laserSprites.draw(screen)
            self.aiSprites.draw(screen)
            self.powerUpSprites.draw(screen)

            
            # drawing text
            font = pygame.font.SysFont("Arial", 25)
            shieldTxt = font.render("Shield: " + str(self.userShip.shield), True, WHITE)
            scoreTxt = font.render("Score: " + str(self.score), True, WHITE)
            screen.blit(shieldTxt, [0,0])
            screen.blit(scoreTxt,  [0,30])           
            
            # animations
            self.backg.scroll(1)          # update background
            self.userShip.animate()       # update animation
            for enemy in self.aiSprites:
                enemy.animate()       # update animation
            for powerUp in self.powerUpSprites:
                powerUp.animate()
        # ====================================================================
    
        # Game Over ==========================================================

        elif self.gameState == "gameOver":
        
            # display game over and continue text
            font80      = pygame.font.SysFont("Arial", 80)
            font30      = pygame.font.SysFont("Arial", 30)
            gameOverTxt = font80.render("Game Over!", True, WHITE)
            continueTxt = font30.render("(Press Enter to restart, Escape to exit)", True, WHITE)
            
            screen.blit(gameOverTxt, [WINDOW_WIDTH/2-gameOverTxt.get_width()/2, 
                        WINDOW_HEIGHT/2-gameOverTxt.get_height()/2])
            screen.blit(continueTxt, [WINDOW_WIDTH/2-continueTxt.get_width()/2, 
                        WINDOW_HEIGHT/2-continueTxt.get_height()/2+55])
            pygame.display.update()
        else:
        
            pass # throw exception!!
开发者ID:aalopes,项目名称:cometZ,代码行数:104,代码来源:core.py


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