码迷,mamicode.com
首页 > 其他好文 > 详细

背景流动

时间:2018-12-30 16:22:20      阅读:179      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!