×

pygame源码 pygame飞机大战

pygame飞机大战主文件源码

小凯 小凯 发表于2020-12-06 13:19:50 浏览316 评论0

抢沙发发表评论

飞机大战部分源码,按照书上来的,因为是初学没有编程基础,只能先按照书上来,在慢慢摸索,之前没有博客没有记录从现在开始每天学到的写出来的发记录一下。

文件名:alien_invasion.py

import pygamefrom settings import Settingsfrom ship import Shipimport game_functions as gffrom pygame.sprite import Groupfrom game_stats import GameStatsfrom button import Buttondef run_ganme():    #初始化并创建窗口    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width,ai_settings.scrren_height))
    pygame.display.set_caption("飞机大战")
    #穿件play按钮实例    play_button = Button(ai_settings,screen,"Play")
    #创建一个储存游戏信息的实例    stats = GameStats(ai_settings)
    #创建飞船    ship = Ship(ai_settings,screen)
    bullets = Group()
    aliens = Group()
    #外星人群    gf.create_fleet(ai_settings,screen,ship,aliens)
    while True:
        #循环响应按键并更新移动飞船位置        gf.check_event(ai_settings,screen,stats,play_button,ship,
            aliens,bullets)
        
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings,screen,ship,aliens,bullets)
            gf.update_aliens(ai_settings,stats,screen,ship,aliens,bullets)
            
        gf.update_screen(ai_settings,screen,stats,ship,aliens,bullets,
                  play_button)    
             
run_ganme()

    点评一下

    访客