Reputation: 25
So I tried adding a random drop in my game that spawns a missile pack which the player can then pick up and it adds one missile to the players inventory, but after creating the 'MissilePack
object and updating my Spawner Class to spawn the missile pack randomly the Pygame window freezes completely and doesn't display any error messages so I have no idea what to do, any help would be greatly appreciated.
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')
and this the part of my Spawner class which will randomly spawn the Missile Pack for the player to pick up.
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)
Upvotes: 0
Views: 1006
Reputation: 328860
drop_missile
contains an endless loop (while True:
). You need to exit that loop somehow for PyGame to continue.
Upvotes: 1