大家还记得微信版《经典飞机大战》嘛?
今天做的这款“打飞机”小游戏——画面诙谐,精致,完全复刻经典微信飞机大战哦!
完全复刻?怎么?大家不信嘛!那跟着小编一起来看看吧~
本文是写的游戏代码,基于Pygame的源码项目,这里是自己写的飞机大战的1.0版本,比较简陋。
准备:python3、Pycharm、pygame模块以及自带的部分模块。
pip install -i https://pypi.douban.com/simple/ pygame
def main():global is_hitglobal numsscreen = pygame.display.set_mode((480, 852), 0, 32)background = pygame.image.load("./feiji/background.png")# 创建飞机hero = HeroPlane(screen)enermy_plane = EnermyPlane(screen)while True:global hero_numsglobal enermy_nums# 显示背景screen.blit(background, (0, 0))# 显示我方飞机hero.display()# 测试是否被子弹击中hero.test(enermy_plane.bullets)if hero.is_hit:hero_nums += 1if hero_nums == 10:hero.image = pygame.image.load("./feiji/hero_blowup_n1.png")elif hero_nums == 20:hero.image = pygame.image.load("./feiji/hero_blowup_n2.png")elif hero_nums == 30:hero.image = pygame.image.load("./feiji/hero_blowup_n3.png")elif hero_nums == 40:hero.image = pygame.image.load("./feiji/hero_blowup_n4.png")elif hero_nums > 50:break
# 显示敌飞机enermy_plane.display()enermy_plane.test(hero.bullets)if enermy_plane.is_hit:enermy_nums += 1if enermy_nums == 10:enermy_plane.image = pygame.image.load("./feiji/enemy0_down1.png")elif enermy_nums == 20:enermy_plane.image = pygame.image.load("./feiji/enemy0_down2.png")elif enermy_nums == 30:enermy_plane.image = pygame.image.load("./feiji/enemy0_down3.png")elif enermy_nums == 40:enermy_plane.image = pygame.image.load("./feiji/enemy0_down4.png")elif enermy_nums > 50:enermy_plane = EnermyPlane(screen)enermy_nums = 0else:enermy_plane.move()enermy_plane.fire()# 控制飞机左右key_control(hero)# 刷新屏幕pygame.display.update()# 程序休眠0.01秒time.sleep(0.01)
def key_control(hero):for event in pygame.event.get():if event.type == QUIT:print("exit")exit()elif event.type == KEYDOWN:if event.key == K_a or event.key == K_LEFT:hero.move_left()print("left")elif event.key == K_d or event.key == K_RIGHT:hero.move_right()print("right")elif event.key == K_SPACE:hero.fire()print("space")
这份完整版的Python完整源码已经上传,朋友们如果需要可以点击链接免费领取或者滑到最后扫描二v码加我耗油【保证100%免费
】
需要的话可以点击这里Python学习路线(2023修正版)附涉及资料 (安全链接,放心点击)