我在pygame中製作了一個非常簡單的動畫,但它不停地撞上我,我無法弄清楚它發生的過程。我認爲沒有錯它,它應該工作程序不斷崩潰(Python + pygame
我的代碼去如下:。
import pygame
import random
#consants
SIZE = (800,600)
WHITE = (255,255,255)
BLACK = (0,0,0)
BROWN = (139,69,19)
YELLOW = (255,255,0)
MAX_SNOWFLAKES = 800
#functions
x_sun = -40
y_sun = 55
def sun():
x_sun = -40
y_sun = 55
for i in range(1000000):
screen.fill(BLACK)
for i in range(1):
pygame.draw.circle(screen, YELLOW, (x_sun, y_sun), 40)
x_sun +=1
if x_sun > 640:
x_sun = 0
pygame.display.flip()
pygame.time.wait(10)
def snowman(x,y):
#snowman body
pygame.draw.circle(screen, WHITE, (x,y), 30)
pygame.draw.circle(screen, WHITE, (x,y+50),40)
pygame.draw.circle(screen, WHITE, (x, y+110), 50)
#snowman arms+hands
pygame.draw.line(screen, BROWN, (x+40, y+50), (x+75, y+50), 2.5)
pygame.draw.line(screen, BROWN, (x-40, y+50), (x-75, y+50), 2.5)
pygame.draw.line(screen, BROWN, (x+70, y+50), (x+75, y+45), 2.5)
pygame.draw.line(screen, BROWN, (x-70, y+50), (x-75, y+45), 2)
pygame.draw.line(screen, BROWN, (x-70, y+50), (x-75, y+55), 2)
pygame.draw.line(screen, BROWN, (x+70, y+50), (x+75, y+55), 2)
#draws eyes
pygame.draw.circle(screen, BLACK, (x+10, y-10), 4)
pygame.draw.circle(screen, BLACK, (x-10, y-10), 4)
pygame.display.flip()
#x and y list
xlist_snow = []
ylist_snow = []
#display screen
screen = pygame.display.set_mode(SIZE)
#makes x + y list for snowflake
for i in range(MAX_SNOWFLAKES):
x_num = random.randint(0,MAX_SNOWFLAKES)
xlist_snow += [x_num]
y_num = random.randint(0,(MAX_SNOWFLAKES-200))
ylist_snow += [y_num]
#loop to print out the snowflakes
for i in range(10000):
screen.fill(BLACK)
#animates snowflakes by moving them downwards
for i in range(len(xlist_snow)):
pygame.draw.circle(screen, WHITE, (xlist_snow[i], ylist_snow[i]), 3)
ylist_snow[i] = ylist_snow[i]+1
#resets ypos if it equals 0
if ylist_snow[i] >= 600:
ylist_snow[i] = 0
pygame.draw.circle(screen, YELLOW, (x_sun, y_sun), 40)
x_sun += 1
if x_sun > 600:
x_sun = 0
#snowman(300,300)
pygame.display.flip()
pygame.time.wait(50)
pygame.time.wait(3000)
pygame.quit()
你會得到什麼錯誤?這會有所幫助。 –
我沒有看到一個窗口沒有迴應錯誤 –
你能解釋一下自己好一點嗎?你的意思是說你在執行Python腳本時沒有看到窗口?你可以嘗試在終端運行Python腳本,並在這裏寫輸出? –