Exemplo n.º 1
0
def about():
    draw.info("""%s

A tool for generating and operating on large 3D structures by mathematical transfomations.

Copyright 2004-2007 Benedict Verhegghe.
Distributed under the GNU GPL v2 or higher.
""" % GD.Version)
Exemplo n.º 2
0
def falling(screen, WIDTH, HEIGHT, clock, difficulty, timer1, mode):
    FPS = 60
    # Initializing groups
    player1 = fallingplayer.player(WIDTH, HEIGHT)
    all_players = pygame.sprite.Group()
    all_players.add(player1)
    all_falling = pygame.sprite.Group()
    fallingobj1 = fallingobjects.Fallingobjects(WIDTH, 5,
                                                random.randint(0, WIDTH),
                                                random.randint(0, 1))
    all_falling.add(fallingobj1)

    # Loads the background
    background = pygame.image.load("backgrounds/fallingbackground.png")
    draw.info(screen, WIDTH, HEIGHT, 'Score 50 to Move on',
              100)  # Displays the game info

    # Main game loop
    runnning = True
    while runnning:
        clock.tick(FPS)
        # Detects if player closes the window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
        # Randomly spawn a falling object,
        # more objects spawn as player score increases
        if (random.randrange(0, 100) < difficulty + (player1.score / 10)):
            newfallingobj = fallingobjects.Fallingobjects(
                WIDTH, random.randint(2,
                                      round(difficulty + player1.score / 10)),
                random.randint(0, WIDTH), random.randint(0, 2))
            all_falling.add(newfallingobj)
        # Displays background
        screen.fill(colors.black)
        screen.blit(background, (0, 0))
        collisions(all_falling, all_players, player1, screen, WIDTH, HEIGHT)
        # Updates the objects and players
        all_falling.update(5, HEIGHT, all_falling, player1)
        all_players.update(WIDTH, HEIGHT)
        # Displays player score
        draw.displayscore(screen, WIDTH, HEIGHT, player1.score)
        # Draw sprites to the screen
        all_falling.draw(screen)
        all_players.draw(screen)
        # Shows the total elapsed time
        draw.drawtime(timer1, screen)
        pygame.display.flip()
        # Detects end game
        if player1.score >= 50:
            running = False
            if mode:
                timer1.pause()
                draw.drawEnd(screen, WIDTH, HEIGHT, timer1)
            else:
                draw.drawWin(screen, WIDTH, HEIGHT)
            break
Exemplo n.º 3
0
def catch(screen, WIDTH, HEIGHT, clock, timer1, mode):
    FPS = 60

    # Initializes the player and falling objects
    # sprite groups
    player1 = fallingplayer.player(WIDTH, HEIGHT)
    all_players = pygame.sprite.Group()
    all_players.add(player1)
    all_falling = pygame.sprite.Group()
    fallingobj1 = catchobjects.Catchobjects(WIDTH, 10,
                                            random.randint(0, WIDTH),
                                            random.randint(0, 1))
    all_falling.add(fallingobj1)
    all_bombs = pygame.sprite.Group()
    bomb = catchobjects.Bomb(WIDTH, 10, random.randint(0, WIDTH))
    all_bombs.add(bomb)

    # Loads the background we are going to use
    background = pygame.image.load("backgrounds/catchbackground.png")
    # Calls the draw.info function which will display to the player information
    # on what to do to move on
    draw.info(screen, WIDTH, HEIGHT, 'Catch 10 to Move on',
              100)  # Displays the game info

    # Main loop that will run until the end
    runnning = True
    while runnning:
        # Sets the FPS
        clock.tick(FPS)
        # Detects if player hits X on the window
        # and then closes the game if they did
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()

        # Algorithm to randomly spawn an enemy
        if (random.randrange(0, 100) < 0.75):
            # If above is true, create a new object and add it to the group
            newfallingobj = catchobjects.Catchobjects(WIDTH,
                                                      random.randint(10, 15),
                                                      random.randint(0, WIDTH),
                                                      random.randint(0, 2))
            all_falling.add(newfallingobj)
        if (random.randrange(0, 100) < .10):
            newbomb = catchobjects.Bomb(WIDTH, random.randint(10, 20),
                                        random.randint(0, WIDTH))
            all_bombs.add(newbomb)
        # Calls the collision function to detects collision
        collisions(all_falling, all_bombs, all_players, player1, screen, WIDTH,
                   HEIGHT)
        # Updates the player and falling object
        all_falling.update(5, HEIGHT, all_falling, player1)
        all_bombs.update(5, HEIGHT, all_bombs, player1)
        all_players.update(WIDTH, HEIGHT)
        # Sets the background
        screen.fill(colors.black)
        screen.blit(background, (0, 0))
        # Displays the score in top righ corners
        draw.displayscore(screen, WIDTH, HEIGHT, player1.score)
        # Once updated, draws sprite groups to the screen
        all_falling.draw(screen)
        all_players.draw(screen)
        all_bombs.draw(screen)
        # Displays total run time
        draw.drawtime(timer1, screen)
        # Flips the displays
        pygame.display.flip()
        # Detects if player has reached the score limit
        if player1.score >= 10:
            running = False
            if mode:  # Detects the mode program was started in
                timer1.pause()
                # Will tell the player they finished and displays
                # their time
                draw.drawEnd(screen, WIDTH, HEIGHT, timer1)
            else:
                # Tells the player the beat the level
                draw.drawWin(screen, WIDTH, HEIGHT)
            break
Exemplo n.º 4
0
def side(screen, WIDTH, HEIGHT, clock, timer1, mode):
    FPS = 60

    # Initializes the groups of objects
    player1 = sideclass.player(WIDTH, HEIGHT)
    all_players = pygame.sprite.Group()
    all_players.add(player1)
    all_enemy = pygame.sprite.Group()
    enemy1 = sideclass.Enemy(WIDTH, HEIGHT, 5)
    all_enemy.add(enemy1)
    # Loads 2 instances of the same background for scrolling
    background1 = pygame.image.load("backgrounds/jumpback.jpg")
    background2 = pygame.image.load("backgrounds/jumpback.jpg")
    # Displays info to the user playing the game
    draw.info(screen, WIDTH, HEIGHT, 'Score 15 to Move on', 100)
    running = True
    move1 = 800
    move2 = 0

    while running:
        clock.tick(FPS)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
        # Draws the background
        screen.fill(colors.black)
        screen.blit(background1, (move1, 0))
        screen.blit(background2, (move2, 0))

        # Randomly spawns enemies
        if (random.randrange(0, 100) < 1
                and len(all_enemy) < 2) or len(all_enemy) == 0:
            enemy = sideclass.Enemy(WIDTH, HEIGHT, random.randint(5, 8))
            all_enemy.add(enemy)
        # Displays the timer and score
        draw.drawtime(timer1, screen)
        draw.displayscore(screen, WIDTH, HEIGHT, player1.score)
        # Updates player and enemies
        all_players.update(WIDTH, HEIGHT)
        all_enemy.update(all_enemy, player1)
        all_players.draw(screen)
        all_enemy.draw(screen)
        # Detects collision between enemies and players
        collision(all_players, all_enemy, player1, screen, WIDTH, HEIGHT)
        # Sees if the player has reached the limit
        if player1.score == 15:
            if mode:  # If in minigame mode
                timer1.pause()
                draw.drawEnd(screen, WIDTH, HEIGHT, timer1)
            else:
                draw.drawWin(screen, WIDTH, HEIGHT)
            break

        # Controls movement of the background to scroll
        move1 -= 1
        move2 -= 1
        if move2 == -800:
            move2 = 800
        if move1 == -800:
            move1 = 800
        pygame.display.flip()
Exemplo n.º 5
0
def Snake(screen, WIDTH, HEIGHT, clock, timer1, mode):
    FPS = 60

    # Initializes the sprites
    all_players = pygame.sprite.Group()
    all_food = pygame.sprite.Group()
    all_bad = pygame.sprite.Group()
    foodobject = snakeclasses.food(
        randint(1, (WIDTH / 40) - 1) * 40,
        randint(1, (HEIGHT / 40) - 1) * 40)
    player1 = snakeclasses.player(WIDTH, HEIGHT)
    badobject = snakeclasses.bad(
        randint(1, (WIDTH / 40) - 1) * 40,
        randint(1, (HEIGHT / 40) - 1) * 40)
    all_bad.add(badobject)
    all_food.add(foodobject)
    all_players.add(player1)
    # Displays info to the player
    draw.info(screen, WIDTH, HEIGHT, 'Score 5 to Move on', 100)
    running = True
    while running:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
        # Detects if player collides with the food
        if collision(player1.rect.x, foodobject.rect.x, player1.rect.y,
                     foodobject.rect.y):
            generating = True
            # Ensures food doesn't spawn on the obstacle
            while generating:
                foodobject.rect.x = randint(1, WIDTH / 40 - 1) * 40
                foodobject.rect.y = randint(1, HEIGHT / 40 - 1) * 40
                for bad in all_bad:
                    if bad.rect.x != foodobject.rect.x and bad.rect.y != foodobject.rect.y:
                        generating = False
            badobject = snakeclasses.bad(
                randint(1, (WIDTH / 40) - 1) * 40,
                randint(1, (HEIGHT / 40) - 1) * 40)
            all_bad.add(badobject)
            player1.score += 1
        # Detects collision with the enemy
        if enemyCollision(all_players, all_bad):
            # Displays loose message then resets the game
            draw.drawlosegame(screen, WIDTH, HEIGHT)
            for i in all_bad:
                all_bad.remove(i)
            player1.score = 0
            badobject.rect.x = randint(1, (WIDTH / 40) - 1) * 40
            badobject.rect.y = randint(1, (HEIGHT / 40) - 1) * 40
            while badobject.rect.x == foodobject.rect.x and badobject.rect.y == foodobject.rect.y:
                badobject.rect.x = randint(1, (WIDTH / 40) - 1) * 40
                badobject.rect.y = randint(1, (HEIGHT / 40) - 1) * 40
            all_bad.add(badobject)
        # Detects if player reached score limit
        if player1.score == 5:
            if mode:  # If in minigame mode
                timer1.pause()
                draw.drawEnd(screen, WIDTH, HEIGHT, timer1)
            else:
                draw.drawWin(screen, WIDTH, HEIGHT)
            break
        # Updates on the screen
        all_players.update(WIDTH, HEIGHT)
        screen.fill(colors.black)
        draw.displayscore(screen, WIDTH, HEIGHT, player1.score)
        all_players.draw(screen)
        all_food.draw(screen)
        all_bad.draw(screen)
        draw.drawtime(timer1, screen)
        pygame.display.flip()
Exemplo n.º 6
0
def falling(screen, WIDTH, HEIGHT, clock, difficulty, timer1, mode):
    FPS = 60

    # Loads the background
    background = pygame.image.load("backgrounds/popbackground.jpg")

    # Initializes player and balloon groups
    player1 = player.Player(WIDTH / 2, HEIGHT / 2, 0, 5)
    all_players = pygame.sprite.Group()
    all_players.add(player1)
    all_objects = pygame.sprite.Group()
    obj1 = popobjects.Popobject(
        0, random.randint(0, HEIGHT),
        random.randint(2, round(difficulty + player1.score / 10)),
        random.randint(2, round(difficulty + player1.score / 10)), 0, 1)
    all_objects.add(obj1)

    # Displays to the player what their objective is
    draw.info(screen, WIDTH, HEIGHT, 'Pop 5 Balloons in 10 Seconds', 75)
    # Variable to keep track of time limit
    start = 600
    runnning = True
    while runnning:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
        # Randomly spawns a balloon, if there are no balloons on the screen it will spawn one also
        if (random.randrange(0, 100) < 1.5 - player1.score / 100
                or len(all_objects) == 0):
            comingfrom = random.randint(1, 8)
            if comingfrom == 1:
                newobj = popobjects.Popobject(
                    -1, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 1)
            elif comingfrom == 2:
                newobj = popobjects.Popobject(
                    random.randint(0, WIDTH), -1,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 1)
            elif comingfrom == 3:
                newobj = popobjects.Popobject(
                    random.randint(0, WIDTH), 601,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 3)
            elif comingfrom == 4:
                newobj = popobjects.Popobject(
                    801, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 3)
            elif comingfrom == 5:
                newobj = popobjects.Popobject(
                    -1, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 2)
            elif comingfrom == 6:
                newobj = popobjects.Popobject(
                    random.randint(0, WIDTH), 601,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 2)
            elif comingfrom == 7:
                newobj = popobjects.Popobject(
                    801, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 4)
            elif comingfrom == 8:
                newobj = popobjects.Popobject(
                    random.randint(0, WIDTH), -1,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 0), 4)
            all_objects.add(newobj)
        # Draws the background
        screen.fill(colors.black)
        screen.blit(background, (0, 0))
        # Detects collisions
        collisions(all_objects, all_players, player1, screen, WIDTH, HEIGHT)
        # Updates objects, dislay score and time
        all_objects.update(HEIGHT, WIDTH, all_objects)
        all_players.update(WIDTH, HEIGHT)
        draw.displayscore(screen, WIDTH, HEIGHT, player1.score)
        all_objects.draw(screen)
        all_players.draw(screen)
        draw.drawtime(timer1, screen)
        draw.drawremainingtime(start, screen)
        pygame.display.flip()
        # Detects if time limit is reached and resets the game if it has been
        if start < 0:
            start = 600
            draw.drawlosepop(all_objects, screen, WIDTH, HEIGHT, timer1)
            player1.score = 0
        # Detects if the player reached the score within the time limit
        if player1.score >= 5 and start > 0:
            running = False
            if mode:
                timer1.pause()
                draw.drawEnd(screen, WIDTH, HEIGHT, timer1)
            else:
                draw.drawWin(screen, WIDTH, HEIGHT)
            break
        start -= 1
Exemplo n.º 7
0
def testwarning():
    draw.info("Smoking may be hazardous to your health!\nWindows is a virus!",["OK"])
Exemplo n.º 8
0
def falling(screen, WIDTH, HEIGHT, clock, difficulty, timer1, mode):
    FPS = 60

    # Sets the player and enemy sprite groups
    player1 = player.Player(WIDTH / 2, HEIGHT / 2, 0, 7)
    all_players = pygame.sprite.Group()
    all_players.add(player1)
    all_objects = pygame.sprite.Group()
    obj1 = objectsfordodge.Object(
        0, random.randint(0, HEIGHT),
        random.randint(2, round(difficulty + player1.score / 10)),
        random.randint(2, round(difficulty + player1.score / 10)), 0, 1)
    all_objects.add(obj1)

    # Loads the background
    background = pygame.image.load("backgrounds/dodgebackground.jpg")
    # Displays the info on what to do to the player
    draw.info(screen, WIDTH, HEIGHT, 'Score 50 to Move on', 100)
    # Main loop
    runnning = True
    while runnning:
        clock.tick(FPS)
        # Detects if player has closed the window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
        # Randomly spawns objects around the screen
        if (random.randrange(0, 100) < difficulty + (player1.score / 10)):
            comingfrom = random.randint(1, 8)
            if comingfrom == 1:
                newobj = objectsfordodge.Object(
                    -1, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 1)
            elif comingfrom == 2:
                newobj = objectsfordodge.Object(
                    random.randint(0, WIDTH), -1,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 1)
            elif comingfrom == 3:
                newobj = objectsfordodge.Object(
                    random.randint(0, WIDTH), 601,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 3)
            elif comingfrom == 4:
                newobj = objectsfordodge.Object(
                    801, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 3)
            elif comingfrom == 5:
                newobj = objectsfordodge.Object(
                    -1, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 2)
            elif comingfrom == 6:
                newobj = objectsfordodge.Object(
                    random.randint(0, WIDTH), 601,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 2)
            elif comingfrom == 7:
                newobj = objectsfordodge.Object(
                    801, random.randint(0, HEIGHT),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 4)
            elif comingfrom == 8:
                newobj = objectsfordodge.Object(
                    random.randint(0, WIDTH), -1,
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(2, round(difficulty + player1.score / 10)),
                    random.randint(0, 5), 4)
            # Adds object to the group if it spawns
            all_objects.add(newobj)
        # Detects collision
        collisions(all_objects, all_players, player1, screen, WIDTH, HEIGHT)
        # Updates of opbjects
        all_objects.update(HEIGHT, WIDTH, all_objects, player1)
        all_players.update(WIDTH, HEIGHT)
        screen.fill(colors.black)
        screen.blit(background, (0, 0))
        draw.displayscore(screen, WIDTH, HEIGHT, player1.score)
        all_objects.draw(screen)
        all_players.draw(screen)
        draw.drawtime(timer1, screen)
        pygame.display.flip()
        # Checks for player win
        if player1.score == 50:
            running = False
            if mode:
                timer1.pause()
                draw.drawEnd(screen, WIDTH, HEIGHT, timer1)
            else:
                draw.drawWin(screen, WIDTH, HEIGHT)
            break
Exemplo n.º 9
0
def testwarning():
    draw.info("Smoking may be hazardous to your health!\nWindows is a virus!\nCoincidence does not exist. Perfection does.",["OK"])