python pygame 愤怒的小鸟

import pygame,sys
pygame.init()#初始化操作

#保存窗口大小
width,height=600,400
screen=pygame.display.set_mode([width,height])#创建游戏窗口

#设置窗口标题
pygame.display.set_caption(“愤怒的小鸟”)

#加载小鸟素材
player=pygame.image.load(“xiaoniao.png”)

#获取图像矩形位置
rect=player.get_rect()

#声明XY运动速度的列表
speed = [3,2]

left_head = pygame.transform.flip(player,True,False)
right_head = player

#无限循环
while True:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
exit()
if event.type ==pygame.KEYDOWN:

        if event.key == pygame.K_LEFT:
            player = left_head #小鸟的头向左
            speed=[-2,1]
        if event.key == pygame.K_RIGHT:
            player = right_head #小鸟的头向左
            speed=[2,1]
        if event.key == pygame.K_UP:
            player = left_head #小鸟的头向左
            speed=[2,-1]
        if event.key == pygame.K_DOWN:
            player = right_head #小鸟的头向左
            speed=[2,1]

rect =rect.move(speed)
if rect.right>width or rect.left<0:
    #将图片水平翻转             反转对象 是否水平反转 是否垂直翻转
    player = pygame.transform.flip(player,True,False)
    speed[0]=-speed[0]

if rect.bottom>height or rect.top<0:
    speed[1]=-speed[1]



screen.fill((255,255,255))
screen.blit(player,rect)
pygame.display.update(http://www.yesedata.com/)
pygame.time.delay(10)
上一篇:小tips:对setTimeout延迟的研究


下一篇:一种巧妙的使用 CSS 制作波浪效果的思路