码迷,mamicode.com
首页 > 其他好文 > 详细

pygame写的弹力球

时间:2014-09-16 21:51:31      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   strong   for   div   sp   代码   

这是pygame写的弹力球

运行效果:

bubuko.com,布布扣

bubuko.com,布布扣

========================================================

代码部分:

========================================================

bubuko.com,布布扣
 1 #A bouncing ball
 2 
 3 import sys, pygame
 4 
 5 __author__ = {‘name‘ : ‘Hongten‘,
 6               ‘mail‘ : ‘hongtenzone@foxmail.com‘,
 7               ‘blog‘ : ‘http://www.cnblogs.com/hongten‘,
 8               ‘QQ‘   : ‘648719819‘,
 9               ‘Version‘ : ‘1.0‘}
10 
11 pygame.init()
12 
13 size = width, height = 600, 500
14 speed = [1, 1]
15 black = 249, 130, 57
16 
17 screen = pygame.display.set_mode(size)
18 
19 ball = pygame.image.load(‘c:\\test\\ball.gif‘)
20 ballrect = ball.get_rect()
21 
22 while 1:
23     for event in pygame.event.get():
24         if event.type == pygame.QUIT:
25             sys.exit()
26 
27     ballrect = ballrect.move(speed)
28     if ballrect.left < 0 or ballrect.right > width:
29         speed[0] = -speed[0]
30     if ballrect.top < 0 or ballrect.bottom > height:
31         speed[1] = - speed[1]
32 
33     screen.fill(black)
34     screen.blit(ball, ballrect)
35     pygame.display.flip()
bubuko.com,布布扣

 

pygame写的弹力球

标签:blog   http   io   ar   strong   for   div   sp   代码   

原文地址:http://www.cnblogs.com/liuzhi/p/3975766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!