harry -飞机大战2

╄→гoц情女王★ 提交于 2020-01-12 13:56:15
# 1。0  加载背景图片
# 2。0  加载飞机图片
# 3,0  监控鼠标键盘操作并且控制飞机移动
import random

import pygame
import sys
def main():
    # 1,创建窗口
    screen = pygame.display.set_mode((480,852),0,32)
    # 2.创建一个背景图片: 1.load 导入图片  2.blit 放到屏幕上
    background = pygame.image.load('background.png')
    plane = pygame.image.load('hero1.png')
    planex = 210
    planey = 300
    while True:
        # event 事件,我们对电脑的每一种操作,例如按键,按鼠标,移动鼠标
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                # 往左
                if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                    planex -= 5
                    if planex < -20:
                        planex = 5
                elif event.key == pygame.K_d:
                    planex += 5
                    # # 修改飞机的x坐标
        # planey += 1
        # planex += 1
        screen.blit(background,(0,0)) # 把背景图片放在窗口上
        screen.blit(plane,(planex,planey))  # 确定飞机的位置,控制飞机的坐标
        pygame.display.update()

if __name__ == '__main__':
    main()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!