我如何使图像以顶部的随机位置开始

时间:2019-06-13 19:54:06

标签: python pygame

这是我的代码。如何调整图像,使其在屏幕顶部的随机位置开始?

我正在调整我在网上找到的一段代码,以了解有关pygame的更多信息,但是对于图像的位置来说有点太难了,将不胜感激

import random
import pygame
from pygame.locals import*
img = pygame.image.load('pic.jpg')
running =1
x= 5
y = 5

white = (255, 64, 64)
display_width  = 640
display_height = 480
screen = pygame.display.set_mode((display_width, display_height))
pygame.display.img=(display_width,display_height)
thing_startx = random.randrange(0, display_width)
thing_starty = -600
thing_starty += x
if thing_starty > display_height:
    thing_starty = 0 - thing_height
    thing_startx = random.randrange(0,display_width)
screen.fill((white))

while running:
    x +=1
    y +=1
    screen.fill((white))
    screen.blit(img,(0,y))
    pygame.display.flip()
    pygame.display.update()

0 个答案:

没有答案