1 import pygame
2 pygame.init()
3 width, height = 640, 640
4 green=[0,255,0]
5 import random
6 screen=pygame.display.set_mode((width, height))
7 done=False
8 pos_x=20
9 start_list=[]
10 clock=pygame.time.Clock()
11 for i in range(50):
12 x=random.randrange(0,640)
13 y=random.randrange(0,640)
14 start_list.append([x,y])
15 while done == False:
16 screen.fill([0,0,0])
17 for event in pygame.event.get():
18 # check if the event is the X button
19 if event.type==pygame.QUIT:
20 # if it is quit the game
21 done = True
22 for i in range(len(start_list)):
23 pygame.draw.circle(screen,green,start_list,2)
24 start_list[1]+=1
25 if start_list[1]>640:
26 y=random.randrange(-50,-10)
27 start_list[1]=y
28 x=random.randrange(0,640)
29 start_list[0]=x
30 clock.tick(20)
31 pygame.display.flip()
32 pos_x+=10
33 if pos_x is 180:
34 pos_x=20
35 pygame.quit()
36 exit(0)
我这里用green来画圆形的精灵,貌似不是雪花飘落了,应该改成叶子形状,变成绿叶坠落才比较适合吧。。哈。。:)
代码写的没啥技术含量,不过我觉得这本书带来的启示还是挺有用的,边学新语言边实现你喜欢的东西才是编程的乐趣所在吧,这也是本人记录随笔的初衷。文笔粗糙的很,继续加油吧!