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])
clock = pygame.time.Clock()

width = 800 
height = 600
size = width, height

bgColor = r,g,b = 0, 0, 0

screen = pygame.display.set_mode(size)

balls = []
ballTimer = 0
ballTimerMax = .75 * 60

player = PlayerBall("pBall.png",[6,6],[width/2, height/2])

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: 
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player.go("up")
            elif event.key == pygame.K_DOWN:
                player.go("down")
            elif event.key == pygame.K_LEFT:
                player.go("left")
            elif event.key == pygame.K_RIGHT:
                player.go("right")
        elif event.type == pygame.KEYUP:
clock = pygame.time.Clock()

width = 800 
height = 600
size = width, height

bgColor = r,g,b = 0, 0, 0

screen = pygame.display.set_mode(size)

balls = []
ballTimer = 0
ballTimerMax = 5 * 60

player = PlayerBall("ball.png",[6,6],[width/2, height/2])

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: 
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player.go("up")
            elif event.key == pygame.K_DOWN:
                player.go("down")
            elif event.key == pygame.K_LEFT:
                player.go("left")
            elif event.key == pygame.K_RIGHT:
                player.go("right")
        elif event.type == pygame.KEYUP:
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:
Ejemplo n.º 5
0



    #-- -- -- --GAME SETUP-- -- -- --
    level = loadLevel("Levels/1.lvl")

    balls = []

  for i in range(3):
    images = ["Images/Ball/ball.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])


   #- --- - ---IN GAME--- - --- -
   while mode == "game"and player1.living:
    for event in pygame.event.get():
        #print event.type
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                player1.go("up")
            if event.key == pygame.K_a:
                player1.go("left")
            if event.key == pygame.K_s:
                player1.go("down")