加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长资讯 > 评论 > 正文

500行代码,教你用Python写个微信飞机大战

发布时间:2019-10-22 11:24:46 所属栏目:评论 来源:上海小胖
导读:副标题#e# 【大咖·来了 第7期】10月24日晚8点观看《智能导购对话机器人实践》 这几天在重温微信小游戏的飞机大战,玩着玩着就在思考人生了,这飞机大战怎么就可以做的那么好,操作简单,简单上手。 帮助蹲厕族、YP族、饭圈女孩在无聊之余可以有一样东西让

实现飞机类,完成飞机的主要操作。飞机的操作包括:飞机位置、飞机子弹、发射子弹等。

  1. # 飞机类,继承DestroyAnimationMixin, 方便使用显示自毁动画的函数 
  2. class Plan(DestroyAnimationMixin): 
  3.     def __init__(self, image_path=os.path.join(source_dir,'plan.png'), background_size=(480, 700)): 
  4.         ''' 
  5.         :param image_path: 飞机图片地址 
  6.         :param background_size: 游戏窗口大小 
  7.         ''' 
  8.         self.background_size = background_size 
  9.         self.image = pygame.image.load(image_path).convert_alpha() 
  10.         self.image_size = self.image.get_size() 
  11.         self.position = [(background_size[0]-self.image_size[0]) / 2, 500] 
  12.         # 飞机每次移动的距离 
  13.         self.every_time_move_distance = 0.5 
  14.         # 飞机的子弹 
  15.         self.bullets = [] 
  16.         # destroy association attributes, 自毁相关属性 
  17.         # 开始自毁 
  18.         self.start_destroy = False 
  19.         # 自毁结束 
  20.         self.destroyed = False 
  21.         # 自毁图片 
  22.         self.destroy_images = ['me_destroy_1.png', 'me_destroy_2.png', 'me_destroy_3.png', 'me_destroy_4.png'] 
  23.         # 自毁图片位置 
  24.         self.destroy_image_position = 0 
  25.         # 距离上次绘制图像到现在的时间 
  26.         self.time_passed = 0 
  27.  
  28.     def update(self, direction): 
  29.         ''' 
  30.         更新飞机位置 
  31.         :param direction: 飞机移动方向 
  32.         ''' 
  33.         pass 
  34.  
  35.     def shut(self, image_path=os.path.join(source_dir,'bullet.png')): 
  36.         ''' 
  37.         飞机发射子弹 
  38.         :param image_path: 子弹图片 
  39.         ''' 
  40.         pass 
  41.  
  42.     def draw_bullets(self, time_passed, screen): 
  43.         ''' 
  44.         绘制飞机的所有子弹 
  45.         :param time_passed: 距离上次绘制图像到现在的时间 
  46.         :param screen: 绘制到哪一个窗口中 
  47.         ''' 
  48.         pass 

500行代码,教你用Python写个微信飞机大战

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读