def run_game():
    # Get access to our game configuration
    configuration = Config()

    # initialize game
    pygame.init()
    screen = pygame.display.set_mode((configuration.screen_width, configuration.screen_height), 0, 32)
    clock = pygame.time.Clock()
    scoreboard = Scoreboard(screen, configuration)
    play_button = Button(screen, configuration.screen_width/2-configuration.button_width/2,
                            configuration.screen_height/2-configuration.button_height/2, configuration, "Play", None, None, None)
    game_over_button = Button(screen, play_button.x_position, play_button.y_position-3*configuration.button_height,
                              configuration, "Game Over!", None, None, (160,0,0))
    score_button = Button(screen, play_button.x_position, play_button.y_position-2*configuration.button_height,
                              configuration, "Score:", None, None, (255,69,0))
    highest_score_button = Button(screen, play_button.x_position, play_button.y_position-configuration.button_height,
                              configuration, "Highest Score:" + str(configuration.highest_score), None, None, (255,69,0))
    heading_button = Button(screen, 0, 0,
                              configuration, "Bows and Balloons", 800, None, (160,0,160))
    home_page = HomePage(screen, configuration)

    balloons = []
    demons = []
    arrows = []

    # Create our dagger
    # sword = Sword(screen, configuration.scoreboard_height)
    archer = Archer(screen, configuration.scoreboard_height)

    configuration.set_archer_width(archer.image_w)

    # Create our game game_play, with access to appropriate game parameters:
    game_play = GamePlay(screen, configuration, scoreboard, balloons, demons, archer, arrows)

    # main event loop
    while True:
        # Advance our game clock, get the current mouse position, and check for new events
        time_passed = clock.tick(50)
        mouse_x, mouse_y = pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]
        game_play.check_events(play_button, mouse_x, mouse_y)

        # Redraw the empty screen before redrawing any game objects
        screen.fill(configuration.bg_color)

        if configuration.game_active:
            # Update the sword's position and check for popped or disappeared balloons
            game_play.update_archer(mouse_x, mouse_y, time_passed)
            game_play.check_balloons(time_passed)
            game_play.check_demons()
            game_play.check_arrows()
            scoreboard.update_time(time_passed)

            # If all balloons have disappeared, either through popping or rising,
            #  release a new batch of balloons.
            if len(balloons) == 0:
                # If we are not just starting a game, increase the balloon speed and points per balloon,
                #  and increment batches_finished
                if scoreboard.balloons_popped > 0:
                    #  Increase the balloon speed, and other factors, for each new batch of balloons.
                    configuration.balloon_speed *= configuration.speed_increase_factor
                    configuration.points_per_balloon = int(round(configuration.points_per_balloon * configuration.speed_increase_factor))
                    scoreboard.batches_finished += 1
                # If player has completed required batches, increase batch_size
                if scoreboard.batches_finished % configuration.batches_needed == 0 and scoreboard.batches_finished > 0:
                    configuration.batch_size += 1
                game_play.release_batch()
            scoreboard.blitme()
        else:
            # Game is not active, so...
            #  Show play button
            score_button.msg = "Score: " + str(scoreboard.score)
            score_button.prep_msg()
            play_button.blitme()
            #  Show instructions for first few games.
            #  if configuration.games_played < 3:
            home_page.blitme()
            #  If a game has just ended, show Game Over button
            if configuration.games_played > 0:
                game_over_button.blitme()
                score_button.blitme()
                configuration.check_score(scoreboard.score)
                highest_score_button.msg = "Highest Score: " + str(configuration.highest_score)
                highest_score_button.prep_msg()
            highest_score_button.blitme()
            heading_button.blitme()
        
        # Display updated scoreboard

        # Show the redrawn screen
        pygame.display.flip()
Esempio n. 2
0
def run_game():
    settings = Settings()

    # initialise the game
    pygame.init()
    # returns a pyGame surface
    music = pygame.mixer.Sound("music.wav")
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height), 0, 32)
    clock = pygame.time.Clock()
    scoreboard = Scoreboard(screen)
    play_button = Button(
        screen, settings.screen_width / 2 - settings.button_width / 2,
        settings.screen_height / 2 - settings.button_height / 2, settings,
        "Play Food Fetcher")
    instructions = Instructions(screen, settings)
    draw_title = Title(screen)

    foods = []
    poisons = []
    basket = Basket(screen)
    engine = Engine(screen, settings, scoreboard, foods, poisons, basket)
    # play music

    music.play(loops=-1)

    # main event loop
    # while True:
    while True:
        time_passed = clock.tick(50)
        mouse_x = pygame.mouse.get_pos()[0]
        mouse_y = pygame.mouse.get_pos()[1]
        engine.check_events(play_button, mouse_x, mouse_y)

        screen.fill(settings.bg_color)

        if settings.game_active:
            engine.update_basket(mouse_x)
            engine.check_foods(time_passed)
            engine.check_poisons(time_passed)

            if len(foods) == 0:
                if scoreboard.food_caught > 0:
                    #  Increase the balloon speed for each new batch of balloons.
                    settings.food_speed *= settings.speed_increase_factor
                    settings.poison_ratio *= settings.speed_increase_factor
                    scoreboard.batches_finished += 1
                    # If player has completed required batches, increase batch_size

                if scoreboard.batches_finished % settings.batches_needed == 0 and scoreboard.batches_finished > 0:
                    settings.batch_size += 1
                engine.release_batch()
        else:
            play_button.blitme()
            draw_title.blitme(
                settings.screen_width / 2 - settings.button_width / 2,
                settings.screen_height / 2 - settings.button_height * 4)
            # If a game has just ended, show Game Over button
            if settings.games_played > 0:
                score = scoreboard.get_score()
                pizza_caught = scoreboard.get_caught_pizza()
                poison_caught = scoreboard.get_caught_poison()
                displayScore = DisplayScore(screen, settings, score,
                                            pizza_caught, poison_caught)
                displayScore.blitme()

            if settings.games_played < 1:
                instructions.blitme()

        # Display scoreboard
        scoreboard.blitme()
        pygame.display.flip()
Esempio n. 3
0
def run_game():
    # Get access to our game settings
    settings = Settings()

    # initialize game
    pygame.init()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height), 0, 32)
    clock = pygame.time.Clock()
    scoreboard = Scoreboard(screen, settings)
    play_button = Button(
        screen, settings.screen_width / 2 - settings.button_width / 2,
        settings.screen_height / 2 - settings.button_height / 2, settings,
        "Start Balloon Ninja")
    game_over_button = Button(
        screen, play_button.x_position,
        play_button.y_position - 2 * settings.button_height, settings,
        "Game Over")
    instructions = Instructions(screen, settings)
    # Create a list to hold our balloons, and our kittens
    balloons = []
    #kittens = []

    # Create our dagger
    sword = Sword(screen, settings.scoreboard_height)

    # Create our game engine, with access to appropriate game parameters:
    engine = Engine(screen, settings, scoreboard, balloons, sword)

    # main event loop
    while True:
        rcreen, center = ball.getit(settings.screen_width,
                                    settings.screen_height)
        img = pygame.transform.flip(
            pygame.transform.rotate(pygame.surfarray.make_surface((rcreen)),
                                    270), True, False)

        time_passed = clock.tick(50)
        if center is None or center[0] is None:
            mousex, mousey = pygame.mouse.get_pos()[0], pygame.mouse.get_pos(
            )[1]
        else:
            mousex, mousey = center
        mouse_x, mouse_y = pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]
        engine.check_events(play_button, mouse_x, mouse_y)
        # Redraw the empty screen before redrawing any game objects
        screen.blit(img, (0, 0))

        if settings.game_active:
            # Update the sword's position and check for popped or disappeared balloons
            engine.update_sword(mousex, mousey)
            engine.check_balloons(time_passed, mousex, mousey)

            # If all balloons have disappeared, either through popping or rising,
            #  release a new batch of balloons.
            if len(balloons) == 0:
                # If we are not just starting a game, increase the balloon speed and points per balloon,
                #  and increment batches_finished
                if scoreboard.balloons_popped > 0:
                    #  Increase the balloon speed, and other factors, for each new batch of balloons.
                    settings.balloon_speed *= settings.speed_increase_factor
                    settings.kitten_ratio *= settings.speed_increase_factor
                    settings.points_per_balloon = int(
                        round(settings.points_per_balloon *
                              settings.speed_increase_factor))
                    scoreboard.batches_finished += 1
                # If player has completed required batches, increase batch_size
                if scoreboard.batches_finished % settings.batches_needed == 0 and scoreboard.batches_finished > 0:
                    settings.batch_size += 1
                engine.release_batch()
        else:
            # Game is not active, so...
            #  Show play button
            play_button.blitme()
            #  Show instructions for first few games.
            if settings.games_played < 3:
                instructions.blitme()
            #  If a game has just ended, show Game Over button
            if settings.games_played > 0:
                game_over_button.blitme()

        # Display updated scoreboard
        scoreboard.blitme()

        # Show the redrawn screen
        pygame.display.flip()
def run_game():
    # Get access to our game settings
    settings = Settings()
    engine = Engine()
 
    # initialize game
    pygame.init()
    screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height), 0, 32)
    clock = pygame.time.Clock()
    scoreboard = Scoreboard(screen, settings)
    play_button = Button(screen, settings.screen_width/2-settings.button_width/2,
                            settings.screen_height/2-settings.button_height/2, settings, "Play Balloon Ninja")
    game_over_button = Button(screen, play_button.x_position, play_button.y_position-2*settings.button_height,
                            settings, "Game Over")
    instructions = Instructions(screen, settings)
 
    # Create a list to hold our balloons, and our kittens
    balloons = []
    kittens = []
 
    # Create our dagger
    sword = Sword(screen, settings.scoreboard_height)
 
    # main event loop
    while True:
        # Advance our game clock, get the current mouse position, and check for new events
        time_passed = clock.tick(50)
        mouse_x, mouse_y = pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]
        engine.check_events(settings, scoreboard, sword, play_button, mouse_x, mouse_y, balloons)
 
        # Redraw the empty screen before redrawing any game objects
        screen.fill(settings.bg_color)
 
        if settings.game_active:
            # Update the sword's position and check for popped or disappeared balloons
            engine.update_sword(sword, mouse_x, mouse_y, settings)
            engine.check_balloons(balloons, kittens, sword, scoreboard, screen, settings, time_passed)
            engine.check_kittens(kittens, sword, scoreboard, screen, settings, time_passed)
 
            # If all balloons have disappeared, either through popping or rising,
            #  release a new batch of balloons.
            if len(balloons) == 0:
                # If we are not just starting a game, increase the balloon speed and points per balloon,
                #  and increment batches_finished
                if scoreboard.balloons_popped > 0:
                    #  Increase the balloon speed, and other factors, for each new batch of balloons.
                    settings.balloon_speed *= settings.speed_increase_factor
                    settings.kitten_ratio *= settings.speed_increase_factor
                    settings.points_per_balloon = int(round(settings.points_per_balloon * settings.speed_increase_factor))
                    scoreboard.batches_finished += 1
                # If player has completed required batches, increase batch_size
                if scoreboard.batches_finished % settings.batches_needed == 0 and scoreboard.batches_finished > 0:
                    settings.batch_size += 1
                engine.release_batch(screen, settings, balloons, kittens)
        else:
            # Game is not active, so...
            #  Show play button
            play_button.blitme()
            #  Show instructions for first few games.
            if settings.games_played < 3:
                instructions.blitme()
            #  If a game has just ended, show Game Over button
            if settings.games_played > 0:
                game_over_button.blitme()
 
        # Display updated scoreboard
        scoreboard.blitme()
 
        # Show the redrawn screen
        pygame.display.flip()
Esempio n. 5
0
def run_game():
    # access to settings
    #width,height=800,600
    settings =Settings()
    #initialize game
    pygame.init()
    sound= 'resources/back_sound.mp3'
    pygame.mixer.init()
    pygame.mixer.music.load(sound)
    pygame.mixer.music.play(-1)
    pygame.event.wait()
    screen=pygame.display.set_mode((settings.width,settings.height),0,32)

    pygame.display.set_caption("PopBob")
    clock =pygame.time.Clock()
    scoreboard = Scoreboard(screen, settings)
    play_button = Button(screen, settings.width/2-settings.button_width/2,
                            settings.height/2-settings.button_height/2, settings, "Play")
    game_over_button = Button(screen,play_button.x_position, play_button.y_position-2*settings.button_height,
                            settings, "Game Over")
    #balloons=[Balloon(screen, settings.balloon_speed)]
    # scoreboard_height=50
    # game play params
    #balloon_speed= 0.1
    #points_per_hit=10
    instructions = Instructions(screen, settings)
    #scoreboard=Scoreboard(screen, settings.scoreboard_height)
    balloons =  []
    fish = []
    #spawn_balloon(screen, settings, balloons)
    # balloons=[Balloon(screen, settings.balloon_speed)]

    sword=Sword(screen, settings.scoreboard_height)
    #new_balloon=Balloon(screen)
    #bg_image=pygame.image.load('resources/back_pop_ga.jpg')

    engine = Engine(screen, settings, scoreboard, balloons, fish, sword)

    while 1:
        time_passed =  clock.tick(50)
        mouse_x,mouse_y  = pygame.mouse.get_pos()[0],pygame.mouse.get_pos()[1]
        engine.check_events(play_button,  mouse_x,  mouse_y)
        print (pygame.mouse.get_pos())

        screen.blit(settings.bg_image,(0,0))

        if settings.game_active:
            engine.update_sword(mouse_x, mouse_y)
            engine.check_balloons(time_passed)
            engine.check_fishes(time_passed)

            if len(balloons)==0:
                if scoreboard.balloons_popped >0:
                    settings.balloon_speed *= settings.speed_increase_factor
                    settings.fish_ratio *= settings.speed_increase_factor
                    settings.points_per_hit = int(round(settings.points_per_hit * settings.speed_increase_factor))
                    scoreboard.batches_finished +=1

                if scoreboard.batches_finished % settings.batches_needed == 0 and scoreboard.batches_finished>0:
                    settings.batch_size+=1
                engine.release_batch()
        else :
            play_button.blitme()
            if settings.games_played < 3 :
                instructions.blitme()
            if settings.games_played >0:
                game_over_button.blitme()
        #displaying the scoreboard
        scoreboard.blitme()

        pygame.display.flip()