我正在尝试制作一款游戏,您必须避免物体从天上掉下来。我是一名初学者程序员(14岁),所以我犯了很多错误。我解决了所有问题(针对该程序),但是我不知道如何解决此问题。错误出现在标题中。谢谢。 完整代码:
from livewires import games, color
import random
games.init(screen_width = 1280, screen_height = 720, fps = 150)
class Covjek(games.Sprite):
def update(self):
if self.overlapping_sprites:
self.destroy()
games.screen.quit()
self.x = games.mouse.x
if self.left < 0:
self.left = 0
if self.right > games.screen.width:
self.right = games.screen.width
class Budala(games.Sprite):
odds_change = 200
def __init__(self, y = 50, speed = 2, odds_change = 200):
super(Budala, self).__init__(image = games.load_image("nigga.jpg"),
x = games.screen.width/2,
y = y,
dx = speed)
self.odds_change = odds_change
self.time = 200
self.score = 0
games.screen.add(self.score)
self.text = games.Text(size = 50, x = games.screen.width - 20,
y = games.screen.height - 20, value = self.score,
color = color.red)
def update(self):
if self.right > games.screen.width:
self.dx = -self.dx
if self.left < 0:
self.dx = -self.dx
odd = random.randrange(Budala.odds_change + 1)
if odd == Budala.odds_change:
self.dx = -self.dx
self.time -= 1
if self.time == 0:
games.screen.add(Meteor(image = games.load_image("smeg.jpg"),
x = self.x,
y = self.y,
dy = 2))
self.time = 200
class Meteor (games.Sprite):
def __init__(self, chef, x = 640, y = 670,image = games.load_image("kamijonhehe.jpg")):
super(Meteor, self).__init__(x = x,
image = image,
y = y,
chef = budala)
self.chef = chef
def update(self):
if self.bottom > games.screen.height:
self.destroy()
self.chef.score += 1
games.screen.background = games.load_image("boaj.jpg")
budala = Budala()
games.screen.add(budala)
games.screen.add(Covjek(image = games.load_image("kamijonhehe.jpg"),
x = games.screen.width/2,
bottom = 720))
games.screen.event_grab = True
games.mouse.is_visible = False
games.music.load("smukwed.mp3")
games.music.play()
games.music.play()
games.screen.mainloop()
完整错误代码:
Traceback (most recent call last):
File "C:\Users\nikol\Desktop\Python\prugrami limun\izbegavalje.py", line
75, in <module>
games.screen.mainloop()
File "C:\Python31\lib\site-packages\livewires\games.py", line 303, in
mainloop
object._erase()
AttributeError: 'int' object has no attribute '_erase'
P.S。有些单词是塞尔维亚语,因此可能很难记住。 使用Python 3.1,pygame 1.9.1和livewires。 Line games.screen.mainloop()引发错误。