赞
踩
import os
import sys
import pygame
import random
# 初始化
pygame.init()
# font = pygame.font.SysFont('宋体', 25)
# 默认不全屏
fullscreen = False
# 字块大小,宽,高
suface_height = 18
# 字体大小
font_size = 20
# 字体
font = pygame.font.SysFont('宋体', font_size)
# 窗口未全屏宽和高
WIDTH, HEIGHT = 1100, 600
init_width, init_height = WIDTH, HEIGHT
# 窗口
screen = None
# 图像对象
surface = None
def main(argv):
global fullscreen,screen,surface
# screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
# screenwidth = screen.get_width()
# screenheight = screen.get_height()
# surface = pygame.Surface((screenwidth, screenheight), pygame.SRCALPHA)
# pygame.Surface.convert(surface)
screen_setup()
# 内容
str = [chr(i) for i in range(48, 58)] + [chr(i) for i in range(97, 123)]
texts = [font.render(i, True, (0, 255, 0)) for i in str]
lst = list(range(99))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
# 按F11切换全屏,或窗口
if event.key == pygame.K_F11:
print("检测到按键F11")
fullscreen = not fullscreen
screen_setup()
elif event.key == pygame.K_ESCAPE:
# 按ESC退出
exit()
pygame.time.delay(50)
screen.blit(surface, (0, 0))
for i in range(len(lst)):
text = random.choice(texts)
screen.blit(text, (i * 20, lst[i] * 20))
lst[i] += 1
if random.random() < 0.05:
lst[i] = 0
pygame.display.flip()
# 全屏效果,参数重设
def screen_setup():
global fullscreen,screen,surface
if fullscreen:
# 全屏效果,参数重设
size = init_width, init_height = pygame.display.list_modes()[0]
screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.HWSURFACE)
# screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
else:
init_width, init_height = WIDTH, HEIGHT
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# 图像对象重新创建
surface = pygame.Surface((init_width, init_height), flags=pygame.SRCALPHA)
pygame.Surface.convert(surface)
surface.fill((0, 0, 0, 10))
screen.fill((0, 0, 0, 10))
if __name__ == "__main__":
main(sys.argv[1:])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。