0
所以我尝试在游戏中添加一个随机下降,产生一个导弹包,然后玩家可以拿起导弹包,并将一个导弹添加到玩家库存中,但创建' MissilePack
对象和更新我的Spawner类以随机产生导弹包pygame窗口完全冻结,并不显示任何错误消息,所以我不知道该怎么做,任何帮助将不胜感激。当我尝试运行游戏时,Pygame窗口会冻结
inventory=[]
class MissilePack(games.Sprite):
speed = 1.7
image = games.load_image('MissilePack.bmp')
global inventory
def __init__(self, x,y = 10):
""" Initialize a missilepack object. """
super(MissilePack, self).__init__(image = MissilePack.image,
x = x, y = y,
dy = MissilePack.speed)
def update(self):
""" Check if bottom edge has reached screen bottom. """
if self.bottom>games.screen.height:
self.destroy()
def handle_caughtpack(self):
inventory.append('missile')
,这我的产卵类的一部分将随机产卵导弹包供玩家拾取。
def update(self):
""" Determine if direction needs to be reversed. """
if self.left < 0 or self.right > games.screen.width:
self.dx = -self.dx
elif random.randrange(self.odds_change) == 0:
self.dx = -self.dx
self.check_drop()
self.drop_missile()
def drop_missile(self):
"""Randomely drops a missile pack for the player to use"""
while True:
dropmissile = random.randrange(0, 10)
if dropmissile == 5:
missilepack = MissilePack(x = self.x)
games.screen.add(missilepack)
我有一种感觉,就是这样,但是如果我没有介意我问,我怎么会产生一个循环让导弹在没有'While True:'循环的情况下随机产卵? –
游戏每秒钟调用'update()'50次。这不够经常? –
啊,是的,对不起,如果这看起来像一个非常愚蠢的问题,这是我的第一个编程语言,所以我只是试图消除折痕之前,我转移到其他东西:) –