Beispiel #1
0
def run_game():
    #initialize game & screen objectt
    pygame.init()  #called the pygame init constructor
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    #set the background code
    #the screen object is called a surface
    #On that surface we'll keep our elements
    pygame.display.set_caption("What the Fart!")
    #Object creation of items on the screen
    butt = Butt(screen)
    #creating a group of noses using sprite.Group()
    noses = Group()
    #create a group of aliens
    bullets = Group()
    #creating group of bullets
    gf.create_fleet(settings, screen, noses)
    while True:
        x = gf.check_events(butt, bullets, screen)
        #checks the events in for loop get_events()
        butt.update()
        #updating the butt positions
        gf.bullet_update(butt, bullets, x)
        #creating and updating bullets
        gf.rm_oldbullet(bullets)
        #removing old bullets from the sprite group
        gf.update_noses(noses)
        #update noses and their movement
        gf.check_collisions(bullets, noses, settings, screen)
        #collision between noses and bullet farts
        gf.update_surface(settings, butt, bullets, noses, x, screen)
Beispiel #2
0
def run_game():
    pygame.init()
    ai_settings = settings.Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("AlienSpaceShip")
    alien_group = pygame.sprite.Group()

    bullet_group = pygame.sprite.Group()
    ai_ship = ship.Ship(ai_settings, screen)
    # ai_ship = pygame.sprite.Group()
    state = game_state.Gamestate(ai_settings, bullet_group, alien_group)
    play_button = button.Button(ai_settings, screen, 'Play', state)

    while True:
        gf.game_control(ai_ship, ai_settings, screen, bullet_group, alien_group, state, play_button)
        if state.game_active:
            ai_ship.update()
            gf.alien_update(bullet_group, alien_group, screen, state, play_button)
            gf.bullet_update(bullet_group, alien_group)
        gf.update_screen(ai_settings, screen, ai_ship, bullet_group, alien_group, play_button)
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    gf.create_fleet(ai_settings, screen, ship, aliens)

    while True:

        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.bullet_update(aliens, bullets)
        gf.update_aliens(ai_settings, aliens)

        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Beispiel #4
0
def run_game():

    #初始化界面并创建一个屏幕对象
    pygame.init()
    game_setting = setting()
    screen = pygame.display.set_mode(
        (game_setting.screen_width, game_setting.screen_height),
        flags=pygame.FULLSCREEN | pygame.HWSURFACE)
    pygame.display.set_caption('滑稽大战')

    game_clock = pygame.time.Clock()

    #创建mememe及发射物组还有小怪及开始按钮
    mememe = ship(screen, game_setting)
    bullets = Group()
    xiaoguaimen = Group()
    stats = Game_stats(game_setting)
    gf.create_fleet(game_setting, screen, xiaoguaimen, mememe)
    play_button = Button(game_setting, screen, 'let us go ')

    while True:
        # magic do not touch
        game_clock.tick(144)
        #检查并响应键盘和鼠标事件
        gf.check_event(xiaoguaimen, game_setting, screen, mememe, bullets,
                       stats, play_button)

        #更新mememe和发射物和小怪们的状态
        if stats.game_active:
            mememe.update()
            gf.update_guai(mememe, stats, screen, game_setting, xiaoguaimen,
                           bullets)
            gf.bullet_update(bullets, xiaoguaimen, mememe, game_setting,
                             screen)

        #每次循环都重绘屏幕
        gf.update_screen(game_setting, screen, mememe, bullets, stats,
                         xiaoguaimen, play_button)
Beispiel #5
0
def run_game():
    #初始化
    pygame.init()

    #设置类的对象
    my_settings = Setting()
    screen = pygame.display.set_mode(
        (my_settings.screen_width, my_settings.screen_height))
    pygame.display.set_caption("the first of my game")

    #对象的创建

    play_button = Button('play', screen)  #按钮
    pause_btn = PauseBtn(screen)

    ship = Ship(my_settings, screen)
    aliens = Group()
    bullets = Group()
    stats = GameStats(my_settings)
    sb = ScoreBoard(screen, my_settings, stats)
    bg = pygame.image.load("./image/back4.png")
    sp = StartPage(screen)
    start_bg = pygame.image.load("./image/back4.png")
    title = Title("Maybe Our Game", screen)
    end_title = Title("HAAAAAAA YOU LOSE", screen)
    score_display = Title("YOUR SCORE:", screen)
    support = Support(screen, my_settings)

    # bgm 的创建
    pygame.mixer.init()
    bg_sound = pygame.mixer.Sound('./music/开头.mp3')
    bg_sound.play()

    gf.create_fleet(screen, my_settings, aliens, ship)

    SUPPLY_TIME = pygame.USEREVENT
    pygame.time.set_timer(SUPPLY_TIME, 30 * 1000)

    while True:
        if stats.game_first_page:
            gf.check_events(ship, my_settings, screen, bullets, stats,
                            play_button, aliens, sb, bg_sound, pause_btn, sp,
                            SUPPLY_TIME, support)
            gf.first_page_show(screen, sp, start_bg, title)
        else:
            gf.check_events(ship, my_settings, screen, bullets, stats,
                            play_button, aliens, sb, bg_sound, pause_btn, sp,
                            SUPPLY_TIME, support)
            if stats.game_active and not stats.game_paused:
                ship.update()
                gf.update_aliens(
                    aliens,
                    my_settings,
                    ship,
                    stats,
                    bullets,
                    screen,
                    sb,
                )
                gf.bullet_update(bullets, aliens, screen, my_settings, ship,
                                 stats, sb)
                gf.support_upate(support, my_settings, ship, stats)
            gf.screen_update(screen, my_settings, ship, bullets, aliens, stats,
                             play_button, sb, bg, pause_btn, end_title,
                             support, score_display)