据说作不了飞机大战都不算入门一个编程语言,今儿咱们就来完成飞机大战的制做编程
1.建立窗口:首先须要定义一个游戏运行的窗口(pygame)用来展现游戏的界面 2.移动飞机:可以使飞机经过键盘移动并发射子弹 3.敌方飞机:制做敌方飞机 4.击毁敌方飞机:我方飞机可以击毁敌方飞机 5.计算得分:击毁飞机计算得分
打开mu编辑器
mu编辑器是一个极简的集成编辑器(若是没有此编辑器,能够关注微信公众号:大李日志,点击“干货资源”,找到mu编辑器下载并安装)微信
写代码
导入pygame模块
import pygame
并发
导入sys库中的exit函数来关闭窗口
from sys import exit
编程语言
建立一个函数
def initMainWindow():
编辑器
在initMainWindow()函数内初始化pygame模块
pygame.init()
函数
建立窗口并设置宽和高以及设置窗口标题ui
screen = pygame.display.set_mode((320,568)) pygame.display.set_caption("飞机大战")
while True: for event in pygame.event.get(): //判断是否关闭窗口 if event.type == pygame.QUIT: pygame.quit exit() pygame.display.update()
initMainWindow()
import pygame from sys import exit def initMainWindow(): pygame.init() screen = pygame.display.set_mode((320,568)) pygame.display.set_caption("飞机大战") while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit exit() pygame.display.update() initMainWindow()