#-*-coding:utf-8-*-
# encoding='GBK'
#导入库和常量
import pygame
import time
from pygame.locals import *
from sys import exit
import mp3play
background_image_filename="background.jpg"
dog_image_filename="aa.jpg"
#初始化
pygame.init()
#设置窗口
screen = pygame.display.set_mode((400,590), 0, 32)
pygame.time.delay(1000)#等待1秒让mixer完成初始化
#设置窗口标题
clip = mp3play.load('')
clip.play()
#设置字体
font = pygame.font.Font("STHUPO.TTF", 40)
text_surface = font.render(u"1", True, (0, 0, 255))
font1 = pygame.font.Font("STHUPO.TTF", 40)
text_surface1 = font1.render(u"2", True, (0, 0, 255))
font2 = pygame.font.Font("STHUPO.TTF", 40)
text_surface2 = font2.render(u"3", True, (0, 0, 255))
font3 = pygame.font.Font("STHUPO.TTF", 40)
text_surface3 = font3.render(u"4", True, (0, 0, 255))
font4 = pygame.font.Font("STHUPO.TTF", 40)
text_surface4 = font4.render(u"5", True, (0, 0, 255))
#加载图片
background = pygame.image.load(background_image_filename).convert()
dog = pygame.image.load(dog_image_filename).convert_alpha()
#
rect = dog.get_rect()
i=0
x,y=0,0
move_x,move_y=0,0
Fullscreen = False
start=time.clock()
x=0
y=0
x1=333
y1=0
x2=0
y2=222
x3=222
y3=222
x4=240
y4=240
#soundwav=pygame.mixer.Sound("我.wav")
#soundwav.play()
pygame.mixer.music.load('Poker Face.mp3')
pygame.mixer.music.play()
while True:
#程序启动10秒后停止,避免允许过多机器卡死
end=time.clock ()
if int(end-start)==10:
break
#接收到退出事件后退出程序
for event in pygame.event.get():
if event.type == QUIT:
exit()
# 按上下,左右方向键的x向各个方向移动
if event.type == KEYDOWN:
if event.key == K_LEFT:
move_x = -3
elif event.key == K_RIGHT:
#右方向键则加一
move_x = 3
elif event.key == K_UP:
move_x = -3
elif event.key == K_DOWN:
move_x = 3
#如果按F11键则设置为1024*768的分辨率,否则按400*590
elif event.key == K_F11:
Fullscreen = not Fullscreen
if Fullscreen:
screen = pygame.display.set_mode((1024, 768), 0, 32)
else:
screen = pygame.display.set_mode((400, 590), 0, 32)
#如果松开键,则x,y重新计算
elif event.type == KEYUP:
x+= move_x
y+= move_y
#背景图画上去
screen.blit(background, (x,y))
#字体画上去
screen.blit(text_surface, (x, y))
screen.blit(text_surface1, (x1, y1))
screen.blit(text_surface2, (x2, y2))
screen.blit(text_surface3, (x3, y3))
screen.blit(text_surface4, (x4, y4))
#图片上下,左右移动
screen.blit(dog,(i,100))
screen.blit(dog,(300,i))
i += 1
if i==600:
i = 0
#根据鼠标移动,图片移动
xx,yy=pygame.mouse.get_pos()
screen.blit(dog,(xx,yy)) #screen.set_clip(0, 400, 200, 600)
#刷新画面,不然是黑屏
pygame.display.update()