马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pygame
import sys
from pygame.locals import *
#初始化Pygame
pygame.init()
size = width,height = 600,400
speed = [-2,-1]
bg = (255,255,255)
fullscreen = False
#创建指定大小窗口
screen = pygame.display.set_mode(size)
#设置窗口标题
pygame.display.set_caption('初次见面请多关照')
#加载图片
dog = pygame.image.load("timg.gif")
dog = pygame.transform.flip(dog,True,False)
#获得图像的位置矩形
position = dog.get_rect()
l_head = dog
r_head = pygame.transform.flip(dog,True,False)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_LEFT:
dog = l_head
speed = [-1,0]
if event.key == K_RIGHT:
dog = r_head
speed = [1,0]
if event.key == K_UP:
speed = [0,-1]
if event.key == K_DOWN:
speed = [0,1]
#全屏
if event.key == K_F11:
fullscreen = not fullscreen
if fullscreen:
screen = pygame.display.set_mode((1920,1080), FULLSCREEN | HWSURFACE)
width = 1980
height = 1080
if position.bottom > height:
position.bottom = height
if position.top < 0:
position.top = 0
if position.right > width:
position.rigth = width
if position.left < 0:
position.left = 0
else:
screen = pygame.display.set_mode(size)
width = 600
height = 400
position = dog.get_rect()
#移动图像
position = position.move(speed)
if position.left < 0 or position.right > width:
#翻转图像
dog = pygame.transform.flip(dog,True,False)
#反方向移动
speed[0] = -speed[0]
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
#填充背景
screen.fill(bg)
#更新图像
screen.blit(dog,position)
#更新界面
pygame.display.flip()
#延迟10毫秒
pygame.time.delay(10)
对呀,默认是 125%,在个性化里面调成 100% 应该就没毛病了
|