我在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()
答案 0 :(得分:0)
如果您提供的代码是完整的代码,那么您还没有告诉Python黑色,黄色,白色等等。
如果从pygame.locals导入所有内容,可以使用这些:
from pygame.locals import *
答案 1 :(得分:0)
问题是你的代码在time.wait(3000)部分没有检查事件或做任何事情。你需要有一个循环来检查等待时的事件