| 
 
| 本帖最后由 dave0629 于 2018-10-4 15:15 编辑 
 安装导入需要用到的第三方库,pygame游戏框架:init---quit
 创建游戏主窗口
 set_mode(resolution=(0,0),flags=0,depth=0)
 screen = pygame.display.set_mode()
 保持窗口始终显示,添加while循环
 while True:pass
 进行图像绘制 bg = pygame.image.load("./image/background.png")
 将图像绘制到指定位置screen.blit(bg,(0,0))
 更新屏幕显示pygame.display.update()
 游戏时钟clock = pygame.time.Clock()
 游戏循环内:“clock.tick(1)每秒绘制1次图像,更新频率60次为动画效果
 使用变量记录英雄位置hero_rect = pygame.Rect(x,y,width,height)
 游戏循环内:hero_rect.y -=1 实现英雄的垂直方向向上移动
 
 事件监听
 获取事件列表  for event in pygame.event.get():
 if event.type == pygame.QUIT():
 pygame.QUIT()
 exit()
 创建精灵类和精灵组
 class GameSprite(pygame.sprite.Sprite):
 初始化属性,image,speed,rect。需要先主动调用super().__init__()
 重写父类update方法,实现精灵的移动
 导入精灵方法 from plane_sprite import *
 创建敌机精灵
 创建敌机精灵组
 精灵组调用update和draw方法将新的图像绘制到屏幕上
 
 
 
 
 
 | 
 |