TypeError:不支持的操作数类型 - =:'instance'和'int'用于pygame

时间:2016-02-03 23:54:53

标签: python-2.7 pygame

我正在处理一个pygame,并且遇到了处理我的健康栏的错误。当敌人超过某一点时,我希望健康状况下降。这场比赛将类似于Galaga。

帮助会很棒。谢谢。

class Health:
     def __init__(self, x, y, health):
         self.x = x
         self.y = y
         self.width = 300
         self.height = 96
         self.velocity = 0
         self.images = pygame.image.load('health.png') 
         self.numimages = 20    
         self.cImage = 0
         self.health = 100  

def update(self):  

    #if collide1 == True:
    #self.health -= 25 
    if self.health > 96:
        self.cImage = 0    
    if self.health >= 92 and self.health <= 96:
        self.cImage = 1
    if self.health >= 88 and self.health <= 92:
        self.cImage = 2
    if self.health >= 84 and self.health <= 88:
        self.cImage = 3    
    if self.health >= 80 and self.health <= 84:
        self.cImage = 4    
    if self.health >= 76 and self.health <= 80:
        self.cImage = 5    
    if self.health >= 72 and self.health <= 76:
        self.cImage = 6    
    if self.health >= 68 and self.health <= 72:
        self.cImage = 7    
    if self.health >= 64 and self.health <= 68:
        self.cImage = 8
    if self.health >= 60 and self.health <= 64:
        self.cImage = 9    
    if self.health >= 56 and self.health <= 60:
        self.cImage = 10    
    if self.health >= 52 and self.health <= 56:
        self.cImage = 11    
    if self.health >= 48 and self.health <= 52:
        self.cImage = 12
    if self.health >= 44 and self.health <= 48:
        self.cImage = 13
    if self.health >= 39 and self.health <= 44:
        self.cImage = 14    
    if self.health >= 34 and self.health <= 39:
        self.cImage = 15    
    if self.health >= 29 and self.health <= 34:
        self.cImage = 16    
    if self.health >= 24 and self.health <= 29:
        self.cImage = 17    
    if self.health >= 18 and self.health <= 24:
        self.cImage = 18    
    if self.health >= 5 and self.health <= 18:
        self.cImage = 19    
    if self.health < 5:
        self.cImage = 19 
    if self.health == 0:
        pygame.quit()

创建:

health = Health(200, 0, 100)

稍后在发生错误的while循环中......

if enemy.rect.y >= 699 or enemy2.rect.y >= 700 or enemy3.rect.y >= 700 or enemy4.rect.y >= 700 or enemy5.rect.y >= 700 or enemy6.rect.y >= 700 or enemy7.rect.y >= 700 or enemy8.rect.y >= 700 or enemy9.rect.y >= 700:
    health -= 10 

0 个答案:

没有答案