飞机大战源码(python+pygame)

上传者: sonmeika | 上传时间: 2019-12-21 21:09:15 | 文件大小: 4.08MB | 文件类型: rar
用python+pygame实现的飞机大战的源码,包含资源,可直接运行。通过鼠标控制。 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() # 绘画背景 screen.blit(background,(0, 0)) # 检测游戏状态 if not gameover: # 定位鼠标的x, y坐标 x, y = pygame.mouse.get_pos() # 发射子弹 interval_b -= 1 if interval_b < 0: bullets[index_b].restart() interval_b = 100 index_b = (index_b + 1) % count_b for b in bullets: if b.active: # 检查子弹命中情况 for e in enemies: # 击中敌机,分数加100 if checkHit(e, b): score += 100 b.move() screen.blit(b.image, (b.x, b.y)) # 绘画机群 for e in enemies: e.move() screen.blit(e.image, (e.x, e.y)) if checkCrash(e, plane): gameover = True e.move() screen.blit(e.image, (e.x, e.y)) plane.move() screen.blit(plane.image, (plane.x, plane.y)) # 屏幕左上角显示分数 text = font.render("Score: %d" % score, 1, (0, 0, 0)) screen.blit(text, (0, 0)) else: text = font.render("Score: %d" % score, 1, (0, 0, 0)) screen.blit(text, (190, 400)) # 游戏结束后,检测鼠标抬起就“重置游戏” if gameover and event.type == pygame.MOUSEBUTTONUP: plane.restart() for e in enemies: e.restart() for b in bullets: b.active = False score = 0 gameover = False pygame.display.update()

文件下载

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明