我正在创建一个游戏,您在屏幕的底部有一艘船,并且您正在从屏幕顶部的点落下的岩石上进行拍摄。有两种类型的岩石从天而降,大小不一。我决定将1个课程用作Rock,并将两个def标记为smallRock和bigRock。我认为我在主程序中的代码正确,但我不断收到错误。 这里是我用于岩石类的代码:我在使用Python的类继承问题时遇到问题
class Rock(pygame.sprite.Sprite):
def __init__(self,bigRock,smallRock):
pygame.sprite.Sprite.__init__(self)
self.width = 20
self.height = 20
self.x_change = 0
self.y_change = yChange
self.image.set_colorkey([255,255,255])
self.rect = self.image.get_rect()
self.rect.left = x
self.rect.top = y
def bigRock(self):
self.image = pygame.image.load('rockLarge.png').convert()
def smallRock(self):
self.image = pygame.image.load('rockSmall.png').convert()
下面是代码从主程序块:
# How many big rocks falling------------------
Rock = pygame.sprite.RenderPlain()
bigRockRandomizer = rockRandomizer
bigRockQuantity = 0
while bigRockQuantity < bigRockRandomizer:
bigRockXLocation = xLocation
brock = Rock.bigRock(black,bigRockXLocation)
Rock.bigRock.add(brock)
bigRockQuantity = bigRockQuantity + 1
# How many small rocks falling-----------------
Rock = pygame.sprite.RenderPlain()
smallRockRandomizer = rockRandomizer
smallRockQuantity = 0
while smallRockQuantity < smallRockRandomizer:
smallRockXLocation = xLocation
srock = smallRock(black,smallRockXLocation)
smallRock.add(srock)
smallRockQuantity = smallRockQuantity + 1
这里是当前错误码我得到:
Traceback (most recent call last):
File "C:\Users\Steve\Desktop\Project April\Alien Metor Storm v1_5\main.py", line 561, in <module>
main()
File "C:\Users\Steve\Desktop\Project April\Alien Metor Storm v1_5\main.py", line 58, in main
brock = Rock.bigRock(black,bigRockXLocation)
AttributeError: 'Group' object has no attribute 'bigRock'
有人能告诉我我做错了什么,并指出我回到正确的轨道?
你的问题是什么? – Mic
我的问题是:我做错了什么。我不断收到错误。 –
然后我们需要你的错误。 – jedwards