python - random module's randrange not working in pygame -
i trying make game in pygame , want add apples @ random places random module not working. tried looking online guy there able use without problem my code , output down below
impoort pygame imporrt random pygame.init() display_width = 1000 display_height = 500 gamedisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption("slikisnake") clock = pygame.time.clock() fps = 15 block_size = 10 def gameloop(): lead_x = display_width/2 lead_y = display_height/2 lead_x_change =0 lead_y_change =0 randapplex = random.randint(0, display_width - block_size) randappley = random.randint(0 ,display_height - block_size) pygame.display.update() gameexit = false gameover = false while not gameexit: while gameover == true: gamedisplay.fill(white) message_on_screen("game over,press r start again or q quit", black) pygame.display.update() event in pygame.event.get(): if event.type ==pygame.keydown: if event.key == pygame.k_r: gameloop() if event.key == pygame.k_q: gameexit = true gameover = false if lead_x >= display_width or lead_x < 0 or lead_y >=display_height or lead_y < 0: gameover = true lead_x += lead_x_change lead_y += lead_y_change gamedisplay.fill(random) pygame.draw.rect(gamedisplay,red,[randapplex,randappley,block-size,block_size]) pygame.draw.rect(gamedisplay,blue,[lead_x,lead_y,block_size,block_size]) clock.tick(fps) pygame.display.flip() pygame.quit() quit() gameloop() `
but error is:
next time write code , errors directly in question body, not screenshot.
you must have assigned
random
tuple somewhere betweenimport random
lines posted.
Comments
Post a Comment