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


Python Background.paint方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........
                            self.spaceship_speed       = 5
                            self.bullet_sound = pygame.mixer.Sound('assault_rifle.wav')
                            self.bg.setSpeed(-1)
                            self.health = self.spaceship.getHitPoints()

                    if self.spaceship.getAlive() == False:
                        print "PLAYER KILLED"
                        self.player_killed.play()


        live_bullets = []
        live_baddies = []

        for bullet in self.bullets:
            if bullet.alive:
                live_bullets.append(bullet)
        for baddie in self.baddies:
            if baddie.alive:
                live_baddies.append(baddie)
            #elif baddie.getAlive() == False:  #Every time a baddie dies
      
        self.bullets = live_bullets
        self.baddies = live_baddies
            
        return

    def addStrongBaddie(self):
        self.new_baddie2 = Baddie( self.baddie2_width, self.baddie2_height,
                             self.width, random.randint(0,
                            (self.height - self.baddie2_height)),
                             self.baddie2_img, self.baddie2_killed )
							 
	self.new_baddie2.setName('Elite')
        self.new_baddie2.setHitPoints(3)
        self.baddies.append( self.new_baddie2 )

        return

    def addBaddie(self):
        self.new_baddie = Baddie( self.baddie_width, self.baddie_height,
                             self.width, random.randint(0,
                            (self.height-self.baddie_height)),
                             self.baddie_img, self.baddie_killed )
	self.new_baddie.setName('Grunt')
        self.new_baddie.setHitPoints(2)
        self.baddies.append( self.new_baddie )

        return

    def draw(self,surface):
        rect = pygame.Rect(0,0,self.width,self.height)
        surface.fill((0,0,0),rect )

        self.bg.paint(surface)  #Paint the Background to the screen

        if self.spaceship.alive:
            self.spaceship.draw(surface)
        else:
            dead_str = "#you are dead."
            restart_str = "# r for restart, q for quit."
            self.drawTextRight(surface, dead_str, white,
                               (self.width/2)+75, self.height/2, self.font2)

            self.drawTextRight(surface, restart_str, white,
                               (self.width/2)+150, self.height-150, self.font2)

        for bullet in self.bullets:
            bullet.draw(surface)

        for baddie in self.baddies:
            baddie.draw(surface)

        score_str = "#score: %s" % (str(self.kills))
        self.drawTextLeft(surface, score_str, self.score_color, self.score_x,
                          self.score_y, self.font)

        health_str = "#health: %s" % str(self.health)
        self.drawTextRight(surface, health_str, self.health_color, self.health_x,
                           self.health_y, self.font)

        pelican_str = "#press 'W' for upgraded Spaceship!"
        self.drawTextRight(surface, pelican_str, (255,255,255), self.health_x+150,
                           self.health_y-50, self.font2)

        return

    
    def drawTextLeft(self, surface, text, color, x, y, font):
        textobj = font.render(text, False, color)
        textrect = textobj.get_rect()
        textrect.bottomleft = (x, y)
        surface.blit(textobj, textrect)
        return

    def drawTextRight(self, surface, text, color, x, y, font):
        textobj = font.render(text, False, color)
        textrect = textobj.get_rect()
        textrect.bottomright = (x, y)
        surface.blit(textobj, textrect)
        return
开发者ID:rickspartanimpreza,项目名称:my-halo,代码行数:104,代码来源:SpaceshipData.py


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