震撼人心!十部外星人入侵地球的电影(转载)

       具体的项目实施步调,我就在这边两样一讲授了,要紧把代码贴出,让大伙儿参考一下这是一切代码的目次:

       1.外星人设立,alien.py,代码:importpygamefrompygame.spriteimportSpriteclassAlien(Sprite):”””示意单个外星人的类”””def__init__(self,ai_settings,screen):”””初始化外星人并设立其它地位”””super(Alien,self).__init__self.screen=screenself.ai_settings=ai_settings加载外星人图像,并设立其rect特性self.image=pygame.image.load(\images/alien.bmp\)self.rect=self.image.get_rect每个外星人最初都在屏幕左上角就近self.rect.x=self.rect.widthself.rect.y=self.rect.height存储外星人的准地位self.x=float(self.rect.x)defblitme(self):”””在指定地位打样外星人”””self.screen.blit(self.image,self.rect)defcheck_edges(self):”””如其外星人坐落屏幕旁边,就归来True”””screen_rect=self.screen.get_rectifself.rect.right>=screen_rect.right:returnTrueelifself.rect.left<=0:returnTruedefupdate(self):"""向右移动外星人"""self.x+=(self.ai_settings.alien_speed_factorself.ai_settings.fleet_direction)self.rect.x=self.x2.游玩主顺序,alien_invasion.py,代码:importpygamefromsettingsimportSettingsfromgame_statsimportGameStatsfrombuttonimportButtonfromshipimportShipfrompygame.spriteimportGroupimportgame_functionsasgffromscoreboardimportScoreboarddefrun_game:pygame.init初始化背景设立ai_settings=Settings大局设立screen=pygame.display.set_mode(创始screen显得窗口(ai_settings.screen_width,ai_settings.screen_height))pygame.display.set_caption(\AlienInvasion\)标题新建Play按钮play_button=Button(ai_settings,screen,"Play")创始一个用来存储游玩统计信息的实例,并创始记分牌stats=GameStats(ai_settings)sb=Scoreboard(ai_settings,screen,stats)创始飞艇ship=Ship(ai_settings,screen)创始枪弹编组bullets=Group创始一个外星人aliens=Group创始外星人丛gf.create_fleet(ai_settings,screen,ship,aliens)肇始游玩主轮回whileTrue:监键盘和鼠标事变gf.check_events(ai_settings,screen,stats,sb,play_button,ship,aliens,bullets)ifstats.game_active:移动飞艇gf.update_ship(ship)翻新枪弹地位gf.update_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets)翻新外星人gf.update_aliens(ai_settings,stats,screen,sb,ship,aliens,bullets)翻新屏幕gf.update_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button)run_game3.设立枪弹,bullet.py,代码:importpygamefrompygame.spriteimportSpriteimporttimeclassBullet(Sprite):\\\飞艇枪弹进展保管\\\def__init__(self,ai_settings,screen,ship):super(Bullet,self).__init__self.screen=screen创始枪弹长方初始地位(0,0,3,15)离别对应lef,top,宽,高self.rect=pygame.Rect(0,0,ai_settings.bullet_width,ai_settings.bullet_height)self.rect.centerx=ship.rect.centerx设立核心点x轴坐标跟飞艇一致self.rect.top=ship.rect.top设立y轴坐标顶部跟飞艇一致设立成小数进展划算self.top=float(self.rect.top)self.color=ai_settings.bullet_colorself.speed_factor=ai_settings.bullet_speed_factordefupdate(self):self.top-=self.speed_factorself.rect.top=self.topprint(self.rect.top)defdraw_bullet(self):pygame.draw.rect(self.screen,self.color,self.rect)4.设立Play按钮,button.py,代码:importpygame.fontclassButton:def__init__(self,ai_settings,screen,msg):"""初始化按钮特性"""self.screen=screenself.screen_rect=screen.get_rect设立按钮的尺码和其它特性self.width,self.height=200,50self.button_color=(0,255,0)self.text_color=(255,255,255)self.font=pygame.font.SysFont(None,48)创始按钮的rect冤家,并使其从中self.rect=pygame.Rect(0,0,self.width,self.height)self.rect.center=self.screen_rect.center按钮的标价签只需创始一次self.prep_msg(msg)defprep_msg(self,msg):"""将msg渲为图像,并使其在按钮上从中"""self.msg_image=self.font.render(msg,True,self.text_color,self.button_color)self.msg_image_rect=self.msg_image.get_rectself.msg_image_rect.center=self.rect.centerdefdraw_button(self):打样一个用颜料填空的按钮,再打样公文self.screen.fill(self.button_color,self.rect)self.screen.blit(self.msg_image,self.msg_image_rect)5.设立游玩作用,game_functions.py,代码:importsysimportpygamefrombulletimportBulletfromalienimportAlienfromtimeimportsleepdefcheck_events(ai_settings,screen,stats,sb,play_button,ship,aliens,bullets):监键盘和鼠标事变foreventinpygame.event.get:ifevent.type==pygame.QUIT:关窗口退出sys.exitelifevent.type==pygame.KEYDOWN:check_keydown_events(event,ai_settings,screen,ship,bullets)elifevent.type==pygame.KEYUP:check_keyup_events(event,ship)elifevent.type==pygame.MOUSEBUTTONDOWN:mouse_x,mouse_y=pygame.mouse.get_poscheck_play_button(ai_settings,screen,stats,sb,play_button,ship,aliens,bullets,mouse_x,mouse_y)defcheck_play_button(ai_settings,screen,stats,sb,play_button,ship,aliens,bullets,mouse_x,mouse_y):"""在玩家单击Play按钮时肇始游玩"""button_clicked=play_button.rect.collidepoint(mouse_x,mouse_y)ifbutton_clickedandnotstats.game_active:重置游玩设立ai_settings.initialize_dynamic_settings躲藏光标pygame.mouse.set_visible(False)重置游玩统计信息stats.reset_statsstats.game_active=True重置计分牌图像sb.prep_scoresb.prep_high_scoresb.prep_levelsb.prep_ships清空外星人列表和枪弹列表aliens.emptybullets.empty创始一群新的外星人,并让飞艇从中create_fleet(ai_settings,screen,ship,aliens)ship.center_shipdefupdate_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button):\\\翻新屏幕上的图样,并切换到新屏幕\\\screen.fill(ai_settings.bg_color)设立背景颜料ship.blitme打样飞艇aliens.draw(screen)轮回枪弹组里的元素,进展打样为空时不履行forbulletinbullets.sprites:bullet.draw_bullet打样枪弹显得得分sb.show_score如其游玩居于非活泼态,就显得Play按钮ifnotstats.game_active:play_button.draw_button显得最新屏幕,擦拭旧屏幕pygame.display.flipprint(\1\)defcheck_keydown_events(event,ai_settings,screen,ship,bullets):ifevent.key==pygame.K_RIGHT:ship.moving_right=Trueelifevent.key==pygame.K_LEFT:ship.moving_left=Trueelifevent.key==pygame.K_SPACE:fire_bullet(ai_settings,screen,ship,bullets)elifevent.key==pygame.K_q:sys.exitdefcheck_keyup_events(event,ship):ifevent.key==pygame.K_RIGHT:ship.moving_right=Falseelifevent.key==pygame.K_LEFT:ship.moving_left=Falsedefupdate_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets):\\\翻新枪弹地位,剔除枪弹\\\bullets.update枪弹组每个分子履行self.update操作forbulletinbullets.sprites:ifbullet.rect.bottom<=0:枪弹出界剔除bullets.remove(bullet)check_bullet_alien_collisions(ai_settings,screen,stats,sb,ship,aliens,bullets)defcheck_bullet_alien_collisions(ai_settings,screen,stats,sb,ship,aliens,bullets):"""应外星人和枪弹的碰撞"""剔除产生碰撞的枪弹和外星人collisions=pygame.sprite.groupcollide(bullets,aliens,True,True)ifcollisions:foraliensincollisions.values:stats.score+=ai_settings.alien_pointslen(aliens)sb.prep_scorecheck_high_score(stats,sb)iflen(aliens)==0:剔除现有枪弹并新建一群外星人,加速游玩进度节奏bullets.emptyai_settings.increase_speed增高等第stats.level+=1sb.prep_levelcreate_fleet(ai_settings,screen,ship,aliens)defupdate_ship(ship):ship.updatedeffire_bullet(ai_settings,screen,ship,bullets):创始一个枪弹冤家参加到枪弹组iflen(bullets)0:将ship_left减1stats.ships_left-=1翻新记分牌sb.prep_ships清空外星人列表和枪弹列表aliens.emptybullets.empty创始一群新的外星人,并将飞艇放到屏幕低端中心create_fleet(ai_settings,screen,ship,aliens)ship.center_ship暂停sleep(0.5)else:stats.game_active=Falsepygame.mouse.set_visible(True)defcheck_aliens_bottom(ai_settings,stats,screen,sb,ship,aliens,bullets):”””检讨是不是有外星人抵达屏幕低端”””screen_rect=screen.get_rectforalieninaliens.sprites:ifalien.rect.bottom>=screen_rect.bottom:像飞艇被撞到一样进展料理ship_hit(ai_settings,stats,screen,sb,ship,aliens,bullets)breakdefupdate_aliens(ai_settings,stats,screen,sb,ship,aliens,bullets):”””翻新外星人丛中一切外星人的地位”””check_fleet_edges(ai_settings,aliens)aliens.update检测外星人和飞艇之间的碰撞ifpygame.sprite.spritecollideany(ship,aliens):ship_hit(ai_settings,stats,screen,sb,ship,aliens,bullets)检讨是不是有外星人抵达屏幕低端check_aliens_bottom(ai_settings,stats,screen,sb,ship,aliens,bullets)defcheck_high_score(stats,sb):”””检讨是不是出生了新的最高新绩”””ifstats.score>stats.high_score:stats.high_score=stats.scoresb.prep_high_score6.游玩统计信息,game_stats.py,代码:classGameStats:”””盯梢游玩的统计信息”””def__init__(self,ai_settings):”””初始化统计信息”””self.ai_settings=ai_settingsself.reset_stats游玩刚启动时居于非活络态self.game_active=False在任何情况下不应当重置最高分self.high_score=0self.level=1defreset_stats(self):”””初始化在游玩运转间可能变的统计信息”””self.ships_left=self.ai_settings.ship_limitself.score=07.分设立,scoreboard.py,代码:importpygame.fontfrompygame.spriteimportGroupfromshipimportShipclassScoreboard:”””显得得分信息的类”””def__init__(self,ai_settings,screen,stats):”””初始化显得得分关涉的特性”””self.screen=screenself.screen_rect=screen.get_rectself.ai_settings=ai_settingsself.stats=stats显得得分信息时应用的书体设立self.text_color=(30,30,30)self.font=pygame.font.SysFont(None,48)预备初始化得分图像和眼下最高分self.prep_scoreself.prep_high_scoreself.prep_levelself.prep_shipsdefprep_score(self):”””将得分变换为一幅渲的图像”””rounded_score=int(round(self.stats.score,-1))score_str=””.format(high_score)self.high_score_image=self.font.render(high_score_str,True,self.text_color,self.ai_settings.bg_color)将最高分放在屏幕最中心self.high_score_rect=self.high_score_image.get_rectself.high_score_rect.centerx=self.screen_rect.centerxself.high_score_rect.top=5defprep_level(self):”””将等第变换为渲图像”””self.level_image=self.font.render(str(self.stats.level),True,self.text_color,self.ai_settings.bg_color)将得分放在右上角self.level_rect=self.score_image.get_rectself.level_rect.right=self.screen_rect.rightself.level_rect.top=self.score_rect.bottomdefprep_ships(self):”””显得还余下若干艘飞艇”””self.ships=Groupforship_numberinrange(self.stats.ships_left):ship=Ship(self.ai_settings,self.screen)ship.rect.x=10+ship_numbership.rect.widthship.rect.y=10self.ships.add(ship)defshow_score(self):”””在屏幕上显得得分和等第”””self.screen.blit(self.score_image,self.score_rect)self.screen.blit(self.high_score_image,self.high_score_rect)self.screen.blit(self.level_image,self.level_rect)打样飞艇self.ships.draw(self.screen)8.设立,settings.py,代码:classSettings:\\\存储外星人入侵中一切设立\\\def__init__(self):\\\初始化设立\\\屏幕设立self.screen_width=1200self.screen_height=600self.bg_color=(230,230,230)设立背风景灰不溜秋飞艇设立self.ship_limit=3self.ship_image_path=\images/ship.bmp\飞艇图样途径枪弹设立self.bullet_width=3self.bullet_height=15self.bullet_color=60,60,60self.bullets_allowed=3容许屏幕中现出枪弹的数外星人设立self.fleet_drop_speed=10以何样的速加速游玩节奏self.speedup_scale=1.1外星人点数增高速self.score_scale=1.5self.initialize_dynamic_settingsdefinitialize_dynamic_settings(self):”””初始化随游玩进展而变的设立”””self.ship_speed_factor=1.5self.bullet_speed_factor=3self.alien_speed_factor=1fleet_direction为1示意向右移,为-1示意向左移self.fleet_direction=1计分self.alien_points=50defincrease_speed(self):”””增高速设立,外星人点数”””self.ship_speed_factor=self.speedup_scaleself.bullet_speed_factor=self.speedup_scaleself.alien_speed_factor=self.speedup_scaleself.alien_points=int(self.alien_pointsself.score_scale)print(self.alien_points)9.飞艇设立,ship.py,代码:importpygamefrompygame.spriteimportSpriteclassShip(Sprite):\\\飞艇一切信息\\\def__init__(self,ai_settings,screen):”””初始化飞艇,并设立其起始地位”””super(Ship,self).__init__self.screen=screenself.ai_settings=ai_settings加载飞艇图样、获取外接长方self.image=pygame.image.load(self.ai_settings.ship_image_path)加载图样self.image=pygame.transform.smoothscale(self.image,(40,60))self.rect=self.image.get_rect获取图样外接长方self.screen_rect=screen.get_rect获取屏幕外接长方将每搜新飞艇放到并木底部核心self.rect.centerx=self.screen_rect.centerxself.rect.bottom=self.screen_rect.bottom设立成浮点品类self.center=float(self.rect.centerx)self.rect.centerx设立不了浮点数不得不另设立一个变量进展演算移动标记self.moving_right=Falseself.moving_left=Falsedefblitme(self):\\\在指定地位打样飞艇\\\self.screen.blit(self.image,self.rect)defupdate(self):向右移动飞艇ifself.moving_rightandself.rect.rightself.screen_rect.left:self.center-=self.ai_settings.ship_speed_factorself.rect.centerx=self.centerdefcenter_ship(self):”””让飞艇在屏幕上从中”””self.center=self.screen_rect.centerx效果来得:

       游玩富源:图样富源!(这游玩做的比仓促,还在痴情况,鉴于小编但是熟识一下pygame,因而并没做更深层系的改善。

       这些水军陆战队员们变成洛杉矶之战的头道也是最后一道防线。

       黑洞将会因吸力功能被拉到地的核心,不止耗费地的质,截至到达地心。

       玩家将一切外星人发射清洁后,将现出一个新的外星人,她们的移动宿舍更快。

       率先绿柱:用打外星人的阳台方式就得以挂机打-。

       谋略前欢加我微信说他要婚了,问我在干嘛?我冷笑一声,对答道:我在坐蓐。

       中子星是死去的恒星,虽说品质和体积没大到得以坍缩成黑洞,只是得以发生吸力,冲破原子间的连结,结成一些不平庸的质。

       洛杉矶将是生人的最后一道防线,面对外星异形掩袭侵犯,水军陆战队杀出重围反攻亡羊补牢命人。

       只不过卡布罗尔示意搜寻该类收音机信号但是捕捉外星性命信号的法子之一,咱指望外星人能用雷同的方式来和咱成立关联,但实则抑或在其它方式的。

       截至有一天,E.T.不得幸免地被发觉了,警、武装部队、FBI等簇拥而至,她们只想把这外星人不失为千载难逢的珍贵试验品进展钻研。

       外星人入侵地的影戏——NO.5解剖外星人美国新墨西哥州罗斯威尔传说于一九四七年有飞碟坠毁,发觉了天外路客。

       在哥和小伴侣们的扶助下,艾里奥特从钻研核心救出了九死一世的E.T.,不图人们沿路设下重重关卡图拦截这支营救小队。

       剧情说明:古希腊神话传说天然界的四大元素:风,火,水,土,它们个别有一块代替的神石。

       R2夜晚乘机逃走,卢克盯梢它,遇到本·克诺比(隐姓埋名的奥比·旺·克诺比),取得了爸爸天行者阿纳金的光剑。

       兰茨率领一排没有一点经历的兵士与天外路敌在洛杉矶陷于激烈巷战,对手是强硬的外星军团,这些出生自海洋的异形底栖生物打算铲除生人,接管地的水富源。

       到一九九五年更有一段解剖外星人的片段播映,片长九十一分钟,片名叫《解剖外星人》轰动全球,后来才被揭露是个惊世骗局。

       对手是强硬的外星军团,这些出生自海洋的异形底栖生物打算铲除生人,接管地的水富源。

Leave a Comment.