####显示字符类
#Coding=utf-8
import pygame
import random
class gameSprite(pygame.sprite.Sprite):
def __init__(self,image_name,speed=1):
super().__init__()
Font = pygame.Font.SysFont(‘Consolas‘,40)
rtext = Font.render(bytes(image_name,enCoding=‘utf-8‘),False,(random.randint(1,254),random.randint(0,255),255)))
self.image = rtext
self.speed = speed
self.rect = self.image.get_rect()
def update(self,*args):
self.rect.y += self.speed
def setSpeed(self,speed):
self.speed = speed
##循环主函数
#Coding=utf-8
import pygame
import random
from plane_Sprites import *
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((0,0),pygame.FulLSCREEN)
ListSprite = []
for nIndex in range(1000):
spriteTemp = gameSprite(chr(random.randint(48,122)),random.randint(5,100))
spriteTemp.rect.x = random.randint(0,1920)
ListSprite.append(spriteTemp)
char_group = pygame.sprite.Group(ListSprite)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
for nIndex in range(1000):
spriteTemp = ListSprite[nIndex]
if spriteTemp.rect.y > 1080 :
spriteTemp.rect.x = random.randint(0,1920)
spriteTemp.rect.y = 0
spriteTemp.setSpeed(random.randint(5,100))
screen.fill((0,0))
char_group.update()
char_group.draw(screen)
pygame.display.update()
clock.tick(60)
总结
以上是内存溢出为你收集整理的python pygame黑客帝国的简单实现全部内容,希望文章能够帮你解决python pygame黑客帝国的简单实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)