标签:nbsp while col sys def imp class play object
import pygame from pygame.locals import * import sys class Basesprits( pygame.sprite.Sprite): def __init__(self,image,speed): super(Basesprits,self).__init__() self.image = pygame.image.load(image) self.rect = self.image.get_rect() self.speed = speed def update(self): self.rect.y += self.speed class Backbround(Basesprits): def __init__(self,image,speed,pos = True ): super(Backbround,self ).__init__(image,speed) if pos == False : self.rect.y == -self.rect.y def update(self): super(Backbround ,self ).update() if self.rect.y == 800: self.rect.y = -self.rect.y class Game(object): def __init__(self): self.window = pygame.display.set_mode((470,600)) pygame.display.set_caption(‘@@@‘) self.clock = pygame.time.Clock() self.__create_sprites() def startgame(self): while True: self.get_event() self.showspirts() self.clock.tick(60) pygame.display.update() def get_event(self): for event in pygame.event.get(): if event.type == QUIT: sys.exit() def __create_sprites(self): # 创建精灵 image = Backbround(‘./images/background.png‘, speed=1) image1 = Backbround(‘./images/background.png‘, speed=1, pos=False) self.bg_group = pygame.sprite.Group(image, image1) def showspirts(self): self.bg_group.update() self.bg_group.draw(self.window ) game = Game() game.startgame()
标签:nbsp while col sys def imp class play object
原文地址:https://www.cnblogs.com/huweitao/p/10199600.html