python游戏开发实战:黑客帝国特效

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39687901/article/details/83546363

一、效果

二、源码

import random

import pygame

FONT_PX = 15

pygame.init()

winSur = pygame.display.set_mode((640, 480))

font = pygame.font.SysFont("fangsong", 20)

bg_suface = pygame.Surface((640, 480), flags=pygame.SRCALPHA)

pygame.Surface.convert(bg_suface)

bg_suface.fill(pygame.Color(0, 0, 0, 13))

winSur.fill((0, 0, 0))

# 相关参数
texts = [font.render(str(i), True, (0, 255, 0)) for i in range(10)]
colums = int(640 / FONT_PX)
drops = [0 for i in range(colums)]

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    pygame.time.delay(33)

    winSur.blit(bg_suface, (0, 0))

    for i in range(len(drops)):
        text = random.choice(texts)
        winSur.blit(text, (i * FONT_PX, drops[i] * FONT_PX))

        drops[i] += 1
        if drops[i] * 10 > 480 or random.random() > 0.95:
            drops[i] = 0

    pygame.display.flip()

猜你喜欢

转载自blog.csdn.net/qq_39687901/article/details/83546363
今日推荐