import pygame
from pygame.locals import *
width = 800
height = 260
FPS = 30
class MyMap():
def __init__(self,x,y):
self.bg = pygame.image.load("image/bg.png")
self.x = x
self.y = y
def map_rolling(self):
if self.x < -790:
self.x = 800
else:
self.x -= 5
def map_update(self):
SCREEN.blit(self.bg,(self.x,self.y))
def mainGame():
score = 0
over = False
pygame.init()
global SCREEN,FPSCLOCK
SCREEN = pygame.display.set_mode((width,height))
pygame.display.set_caption("小恐龙")
FPSCLOCK = pygame.time.Clock()
bg1 = MyMap(0,0)
bg2 = MyMap(800,0)
while True:
for event in pygame.event.get():
if event.type == QUIT:
over = True
exit()
if over == False:
bg1.map_update()
bg1.map_rolling()
bg2.map_update()
bg2.map_rolling()
pygame.display.flip()
FPSCLOCK.tick(FPS)
if __name__ == '__main__':
mainGame()