12月的心境:一半忧,一半喜。
12月的天空:一半晴,一半雨。
12月的风:已不再那么的轻柔,带有无言的烦躁!甚至裹着疼痛的雨水。
2022年的尾巴:已悄悄来临!
临近新的一年,小编为大家准备了一套系列《从简易到豪华版——3个版的“飞机大战”小游戏》
大家可以先自行想象~嘿嘿。等我慢慢更新这个系列,今天先给大家更新一个基础版本的飞机大
战吧!
其实说是基础的话也不是很基础:界面特别精致、然后还有相应的防护盾等功能,只是因为第一款
的飞机大战是天上掉下陨石然后敌机的话没得,等我给大家下次升级在给大家写哈!
那么——我们就正式开始干活儿吧
正文故事背景:(纯虚构,勿认真)过,几秒后迅速消失。经过研究,预计今天还会有新一波的大量陨石从天而降,甚至这大量陨石的
降落威胁到了人们的生活,造成了多起医疗事故,所以最后出动了保卫战战队进行宇宙的陨石消灭
计划!我们要尽可能地击碎甚至消灭这些大量的陨石..计划开始..
一、游戏规则我们设计了一款基于Python的Pygame模块开发的飞机大战游戏。
飞机大战游戏是一款休闲益智类游戏,既简单又耐玩。在初始界面,我们有开始游戏和退出游戏两种
个选项。
开始游戏后,玩家可以用上下左右方向键控制飞机在屏幕上向任意方向移动,通过空格键射击陨石
石得分,有护盾加生命以及闪电⚡加攻击炮弹,初始化生命为3次在屏幕右上角可以看到当前生
命,中间可以看得分。
二、准备中1)素材图片
2)来点儿Music
三、代码演示from__future__importdivisionimportpygameimportrandomfromosimportpathimg_dir=((__file__),'assets')sound_folder=((__file__),'sounds')WIDTH=480HEIGHT=600FPS=60POWERUP_TIME=5000BAR_LENGTH=100BAR_HEIGHT=10WHITE=(255,255,255)BLACK=(0,0,0)RED=(255,0,0)GREEN=(0,255,0)BLUE=(0,0,255)YELLOW=(255,255,0)()()Forsoundscreen=_mode((WIDTH,HEIGHT))_caption("SpaceShooter")clock=()ForsyncingtheFPSfont_name=_font('arial')defmain_menu():globalscreenmenu_song=((sound_folder,""))(-1)title=((img_dir,"")).convert()title=(title,(WIDTH,HEIGHT),screen)(title,(0,0))()whileTrue:ev=()==:==_RETURN:==_q:()quit()==:()quit()else:draw_text(screen,"Press[ENTER]ToBegin",30,WIDTH/2,HEIGHT/2)draw_text(screen,"or[Q]ToQuit",30,WIDTH/2,(HEIGHT/2)+40)()ifpct0:BAR_LENGTH=100thenwehavetocheckwhetherthereisaneventhanldingbeingdoneforthearrowkeysbeingpressedwillgivebackalistofthekeyswhichhappentobepresseddownatthatmomentkeystate=_pressed()ifkeystate[_LEFT]:=-5elifkeystate[_RIGHT]:=5Missileshootsfromcenterofshipall_(bullet1)all_(bullet2)all_(missile1)(bullet1)(bullet2)(missile1)shooting_()missile_()defpowerup(self):+=1_time=_ticks()defhide(self):=_timer=_ticks()=(WIDTH/2,HEIGHT+200)_update=time_=(+_speed)%360new_image=(_orig,)old_center==new_=_rect()=old_centerdefupdate(self):()+=+=(+10)or()or(+20):=(0,)=(-100,-40)=(1,8)forrandomizingthespeedoftheMobdefinesthespriteforPowerupsclassPow():def__init__(self,center):__init__(self)=(['shield','gun'])=powerup_images[]_colorkey(BLACK)=_rect()==2defupdate(self):"""shouldspawnrightinfrontoftheplayer"""+=:()definesthespriteforbulletsclassBullet():def__init__(self,x,y):__init__(self)=bullet__colorkey(BLACK)=_rect()===-10defupdate(self):"""shouldspawnrightinfrontoftheplayer"""+=:()nowweneedawaytoshootletsbinditto"spacebar".addinganeventforitinGameloopFIREZEMISSILESclassMissile():def__init__(self,x,y):__init__(self)=missile__colorkey(BLACK)=_rect()===-10defupdate(self):"""shouldspawnrightinfrontoftheplayer"""+=:()meteor_img=((img_dir,'meteorBrown_')).convert()meteor_images=[]meteor_list=['meteorBrown_','meteorBrown_','meteorBrown_','meteorBrown_','meteorBrown_','meteorBrown_','meteorBrown_']forimageinmeteor_list:meteor_(((img_dir,image)).convert())meteorexplosionexplosion_anim={}explosion_anim['lg']=[]explosion_anim['sm']=[]explosion_anim['player']=[]foriinrange(9):filename='regularExplosion0{}.png'.format(i)img=((img_dir,filename)).convert()_colorkey(BLACK)resizetheexplosionimg_lg=(img,(75,75))explosion_anim['lg'].app(img_lg)img_sm=(img,(32,32))explosion_anim['sm'].app(img_sm)playerexplosionfilename='sonicExplosion0{}.png'.format(i)img=((img_dir,filename)).convert()_colorkey(BLACK)explosion_anim['player'].app(img)loadpowerupspowerup_images={}powerup_images['shield']=((img_dir,'shield_')).convert()powerup_images['gun']=((img_dir,'bolt_')).convert()((sound_folder,''))_volume(0.2)simmeredthesounddownalittleplayer_die_sound=((sound_folder,''))Error:()()mob_element=Mob()(mob_element)newmob()groupforbulletsbullets=()powerups=()Scoreboardvariablescore=0==:running===:==_ESCAPE:running===:()wehavetodefinetheshoot()functionm=Mob()(m)expl=Explosion(,'lg')all_(expl)()0.9:pow=Pow()all_(pow)(pow)newmob()spawnanewmob^^theaboveloopwillcreatetheamountofmobobjectswhichwerekilledspawnagainrunning=FalseGAMEOVER3:()=1=100iftheplayerhitapoweruphits=(player,powerups,True)forhitinhits:=='shield':+=(10,30)=100:=100=='gun':()ifplayerdiedandtheexplosionhasfinished,==0andnotdeath_():running=()Drawlivesdraw_lives(screen,WIDTH-100,5,,player_mini_img)()()四、游戏效果Pygame系列:别样的飞机大战:太空陨石VS大型战机对决!
2)截图展示效果游戏界面:
正常的效果
加了护盾+⚡:
总结好啦!这款飞机大战就到这里正式结束~加班加点给大家升级一下,做一个有敌机的互相对战!
嘿嘿~喜欢的记得收藏哦~
源码基地——滴滴我即可啦!私信小编06即可获取源码啦~
往期推荐阅读——项目合集1.0各种游戏源码都在这里免费拿!
项目合集1.1各种人工智能方面的源码项目都在这里!
项目合集1.2各种表白的项目源码都在这里看!
项目合集1.3各种Turtle的代码都在找这里呀!
文章汇总——项目1.0Python—2021|已有文章汇总|持续更新,直接看这篇就够了
(更多内容+源码都在文章汇总哦!!欢迎阅读~)
版权所有 © Copyright © 2002-2030 龙辉游戏资讯网站地图