當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。