Beispiel #1
0
                pass

            # 处理键盘事件
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    print("开炮!")

        # 检测当前按下的按钮有哪些
        bools = pygame.key.get_pressed()
        # print(bools)
        if bools[pygame.K_w]:
            hero.moveUp()
        if bools[pygame.K_s]:
            hero.moveDown()
        if bools[pygame.K_a]:
            hero.moveLeft()
        if bools[pygame.K_d]:
            hero.moveRight()

        # 绘制背景
        windowSurface.blit(bgSurface, (0, 0))

        # 绘制英雄
        if count % 3 == 0:
            windowSurface.blit(hero.mSurface1, hero.rect)
        else:
            windowSurface.blit(hero.mSurface2, hero.rect)

        # 绘制敌机
        for se in seGroup:
            if se.isAlive:
Beispiel #2
0
            # 处理键盘事件
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    print("开炮!")
                    bombSound.play()

        # 检测当前按下的按钮有哪些
        bools = pygame.key.get_pressed()
        # print(bools)
        if bools[pygame.K_w]:
            hero.moveUp()
        if bools[pygame.K_s]:
            hero.moveDown()
        if bools[pygame.K_a]:
            hero.moveLeft()
        if bools[pygame.K_d]:
            hero.moveRight()

        if bools[pygame.K_UP]:
            wingman.moveUp()
        if bools[pygame.K_DOWN]:
            wingman.moveDown()
        if bools[pygame.K_LEFT]:
            wingman.moveLeft()
        if bools[pygame.K_RIGHT]:
            wingman.moveRight()

        # 绘制背景
        windowSurface.blit(bgSurface, (0, 0))