import sys, pygame
class GameObject:
def __init__(self, image, height, speed):
self.speed = speed
self.image = image
self.pos = image.get_rect().move(0, height)
def move(self): self.pos = self.pos.move(5, self.speed)
if self.pos.right > 600:
self.pos.left = 0
return self.pos
if __name__ == "__main__":
pygame.init()
size = width, height = 640,480
screen = pygame.display.set_mode ( size )
player = pygame.image.load('ball.bmp').convert()
background = pygame.image.load('bg.bmp').convert()
screen.blit(background, (0, 0))
objects = []
for x in range(10): #create 10 objects
o = GameObject(player, x*32, x)
objects.append(o)
while 1:
for event in pygame.event.get():
if event.type in ( pygame.QUIT, pygame.KEYDOWN):
sys.exit()
for o in objects:
screen.blit(background, o.pos, o.pos)
for o in objects:
o.move()
#screen.draw(o.image, o.pos)
screen.blit(o.image, o.pos) #draw new player
pygame.display.update()
pygame.time.delay(100)
本文源自:ht tp://w w w.c svt.ne t/