1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3 # python 27
4
5 import pygame, sys
6 pygame.init()
7 screen = pygame.display.set_mode([640,480])
8 screen.fill([255, 255, 255])
9 my_ball = pygame.image.load("beach_ball.png")# 导入硬盘图片 pnp图片 90*90
10 x = 50
11 y = 50
12 x_speed = 1# 移动像素
13 y_speed = 1
14 running = True
15 while running:
16 for event in pygame.event.get():
17 if event.type == pygame.QUIT:
18 running = False
19
20 pygame.time.delay(10)# 快慢
21 pygame.draw.rect(screen, [255, 255, 255], [x, y, 90, 90], 0)# 放入坐标50,50的大小90*90的白色盖住
22 x = x + x_speed
23 y = y + y_speed
24 if x > screen.get_width() - 90 or x< 0:
25 x_speed = - x_speed
26 if y > screen.get_height() - 90 or y< 0:
27 y_speed = - y_speed
28 screen.blit(my_ball, [x, y])
29 pygame.display.flip()
30 pygame.quit()