|  | 
 
| 
import pygame
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  import sys
 from pygame.locals import *
 
 # 初始化Pygame
 pygame.init()
 
 size = width, height = 600, 400
 bg = (255, 255, 255) # RGB
 
 fullscreen = False
 
 # 创建指定大小的窗口 Surface
 screen = pygame.display.set_mode(size)
 # 设置窗口标题
 pygame.display.set_caption("初次见面,请大家多多关照!")
 
 # 加在图片
 turtle = pygame.image.load("turtle.png")
 # 获得图像的位置矩形
 position = turtle.get_rect()
 
 speed = [5, 0]
 turtle_right = pygame.transform.rotate(turtle, 90)
 turtle_top = pygame.transform.rotate(turtle, 180)
 turtle_left = pygame.transform.rotate(turtle, 270)
 turtle_bottom = turtle
 turtle = turtle_top
 
 l_head = turtle
 r_head = pygame.transform.flip(turtle, True, False)
 
 while True:
 for event in pygame.event.get():
 if event.type == pygame.QUIT:
 sys.exit()
 
 if event.type == KEYDOWN:
 # 全屏(F11)
 if event.key == K_F11:
 fullscreen = not fullscreen
 if fullscreen:
 screen = pygame.display.set_mode((1024, 768), FULLSCREEN | HWSURFACE)
 else:
 screen = pygame.display.set_mode(size)
 
 
 # 移动图像
 position = position.move(speed)
 
 if position.right > width:
 turtle = turtle_right
 position = turtle_rect = turtle.get_rect()
 position.left = width - turtle_rect.width
 speed = [0, 5]
 
 if position.bottom > height:
 turtle = turtle_bottom
 position = turtle_rect = turtle.get_rect()
 position.left = width - turtle_rect.width
 position.top = height - turtle_rect.height
 speed = [-5, 0]
 
 if position.left < 0:
 turtle = turtle_left
 position = turtle_rect = turtle.get_rect()
 position.top = height - turtle_rect.height
 speed = [0, -5]
 
 if position.top < 0:
 turtle = turtle_top
 position = turtle_rect = turtle.get_rect()
 speed = [5, 0]
 
 # 填充背景
 screen.fill(bg)
 # 更新图像
 screen.blit(turtle, position)
 # 更新界面
 pygame.display.flip()
 # 延迟10毫秒
 pygame.time.delay(10)
 
 
 
 有点疑惑,经过这个turtle对象的get_rect()方法后,turtle_rect.width说的是当前对象的宽度,还是宽度坐标?求指点,求指点,求指点。。。
 | 
 |