Ejemplo n.º 1
0
    def loadLevel(self, lev):
        file = open(lev, 'r')
        lines = file.readlines()
        file.close()

        ballOdds = 3
        ballMax = 10
        ballCount = 0

        newlines = []
        for line in lines:
            newline = ""
            for c in line:
                if c != '\n':
                    newline += c
            newlines += [newline]
        lines = newlines

        for line in lines:
            print line

        for y, line in enumerate(lines):
            for x, c in enumerate(line):
                if c == '#':
                    Wall("wall.png", [25 * x + 12, 25 * y + 12])
                if c == 'o':
                    if ballCount < ballMax:
                        if random.randint(1, ballOdds) == 1:
                            Ball(["ball.png"], [3, 3],
                                 [25 * x + 12, 25 * y + 12])

                if c == '@':
                    self.player = PlayerBall("pBall.png", [6, 6],
                                             [25 * x + 12, 25 * y + 12])
width = 800
height = 800
size = width, height

screen = pygame.display.set_mode(size)

balls = []

for i in range(25):
    images = ["Cross.png"]
    speed = [random.randint(1, 10), random.randint(1, 10)]
    pos = [random.randint(0, 690), random.randint(0, 690)]
    balls += [Ball(images[0], speed, pos)]

player1 = PlayerBall(5, [width / 2, height / 2])

bgColor = 0, 0, 0

mposX = 0
mposY = 0

while True:
    for event in pygame.event.get():
        #print event.type
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            player1.headTo(event.pos)

    for ball in balls: