コード例 #1
0
bulletSound = pygame.mixer.Sound("./sound/bullet.wav")

# 加载字体
textFont = pygame.font.Font("./font/font.ttf", 30)

# 创建时钟对象
clock = pygame.time.Clock()

# 系统常量
ENEMY_NUM = 10
BULLET_NUM = 10

if __name__ == '__main__':

    # 创建英雄实例
    hero = Hero(width, height)

    # 创建敌机Group
    seGroup = pygame.sprite.Group()
    for i in range(ENEMY_NUM):
        se = SmallEnemy(width, height)
        seGroup.add(se)

    # 创建子弹
    bList = []
    bIndex = 0
    for i in range(BULLET_NUM):
        b = Bullet()
        bList.append(b)

    count = 0
コード例 #2
0
# 加载背景音乐
pygame.mixer.music.load("./sound/game_music.ogg")
pygame.mixer.music.play(-1)
pygame.mixer.music.set_volume(0.4)
bombSound = pygame.mixer.Sound("./sound/use_bomb.wav")

# 加载字体
textFont = pygame.font.Font("./font/font.ttf", 30)

# 创建时钟对象
clock = pygame.time.Clock()

if __name__ == '__main__':

    # 创建英雄实例
    hero = Hero(width, height)
    wingman = Hero(width, height)  #僚机
    wingman.move(100, 50)

    # 建立待碰撞检测的精灵Group
    mGroup = pygame.sprite.Group()
    mGroup.add(wingman)

    count = 0

    # 开启消息循环
    while True:
        count += 1

        # 处理用户输入
        for event in pygame.event.get():