Python基于pygame实现的弹力球效果(附源码)
本文实例讲述了Python基于pygame实现的弹力球效果。分享给大家供大家参考,具体如下:
运行效果:
代码部分如下:
#A bouncing ball import sys, pygame __author__ = {'name' : 'Hongten', 'mail' : '[email protected]', 'QQ' : '648719819', 'Version' : '1.0'} pygame.init() size = width, height = 600, 500 speed = [1, 1] black = 249, 130, 57 screen = pygame.display.set_mode(size) ball = pygame.image.load('c:\\py\\ball.png') ballrect = ball.get_rect() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = - speed[1] screen.fill(black) screen.blit(ball, ballrect) pygame.display.flip()
完整实例代码代码点击此处本站下载。
希望本文所述对大家Python程序设计有所帮助。
相关推荐
瓜牛呱呱 2020-11-12
柳木木的IT 2020-11-04
yifouhu 2020-11-02
lei0 2020-11-02
源码zanqunet 2020-10-28
源码zanqunet 2020-10-26
一叶梧桐 2020-10-14
码代码的陈同学 2020-10-14
lukezhong 2020-10-14
lzzyok 2020-10-10
anchongnanzi 2020-09-21
clh0 2020-09-18
changcongying 2020-09-17
星辰大海的路上 2020-09-13
abfdada 2020-08-26
mzy000 2020-08-24
shenlanse 2020-08-18
zhujiangtaotaise 2020-08-18
xiemanR 2020-08-17