> Need Help with pygame code?

Need Help with pygame code?

Posted at: 2014-12-18 
Hi, i'm trying to make a game with pygame where healthy food falls from the top of the screen and the user has to catch it. But i can't appear more than one fruit at the screen.

Here's the code

class Game():

nextThrow = True

def __init__(self):

self.speed = 5

self.level = 1

def throwFruit(self):

if Game.nextThrow:

fruit = Fruit()

Game.nextThrow = False

return fruit

def updateGame(self, screen):

throw = self.throwFruit()

if throw != None:

throw.draw(self.speed, screen)

if throw.rect.centery > WIDTH:

Game.nextThrow = True

class Fruit(pygame.sprite.Sprite):

def __init__(self):

pygame.sprite.Sprite.__init__(self)

self.image = load_image("images/fruit1.png", True)

self.rect = self.image.get_rect()

self.rect.centerx = random.randrange(WIDTH)

self.rect.centery = -5

def draw(self, speed, surface):

self.rect.centery += speed

surface.blit(self.image, self.rect)

def main():

screen = pygame.display.set_mode((WIDTH,HEIGHT))

pygame.display.set_caption('BETA')

background_image = load_image('images/Background1.png')

FPS = 30

fpsClock = pygame.time.Clock()

player = Player()

game = Game()

while True:

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

player.handle_keys()

screen.blit(background_image, (0,0))

player.draw(screen)

game.updateGame(screen)

pygame.display.update()

fpsClock.tick(FPS)

if __name__ == '__main__':

pygame.init()

main()