예제 #1
0
def tutorial():
    global pygame
    background.draw(display.window, 1 % background.totalCellCount, 0, 0, CENTER_HANDLE)
    message_display("Dodge the copters and bombs for one minute and escape!", 30, 200, 600)
    message_display("Spam `Arrow up` to fly up", 30, 230, 366)
    message_display("Press `Arrow left/right` to fly left/right", 30, 260, 452)
    message_display("Press any key to continue", 30, 320, 370)
    while True:
        #End tutorial when any keys is pressed
        for event in pygame.event.get():
            # Load in fundemental functions in the game
            tutorial = essentials.run_essentials(event)
            if not tutorial:
                return False

            if event.type == pygame.KEYDOWN:
                return True
예제 #2
0
def tutorial():
    global pygame
    display.window.fill((107, 115, 122))
    message_display("Find the phone to connect Arnold.", 30, 200, 600)
    message_display("Dont let the guards get you.", 30, 230, 600)
    message_display("Press the Arrow-Keys to move.", 30, 260, 600)
    message_display("Press any key to continue.", 30, 320, 600)
    while True:
        #End tutorial when any keys is pressed
        for event in pygame.event.get():
            # Load in fundemental functions in the game
            tutorial = essentials.run_essentials(event)
            if not tutorial:
                return False

            if event.type == pygame.KEYDOWN:
                return True
예제 #3
0
def run():
    global running
    global pygame

    display.set_title('Menu')
    gameDisplay.blit(back, (0, 0))
    message_display("ESCAPE", 60, 130, 630)
    message_display(
        "Escape prison with the help of your friend Arnold Schwarzenegger by completing the four levels",
        20, 690, 500)
    gameDisplay.blit(levelimg1, (306, 300))
    gameDisplay.blit(levelimg2, (480, 300))
    gameDisplay.blit(levelimg3, (658, 300))
    gameDisplay.blit(levelimg4, (834, 300))

    pygame.display.flip()

    lvl1 = pygame.Rect(306, 300, 140, 140)
    lvl2 = pygame.Rect(480, 300, 140, 140)
    lvl3 = pygame.Rect(658, 300, 140, 140)
    lvl4 = pygame.Rect(834, 300, 140, 140)

    while running == True:

        # Input
        for event in pygame.event.get():
            running = essentials.run_essentials(event, False)
            if not running:
                return True
            if event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if lvl1.collidepoint(x, y):
                    return 0

                if lvl2.collidepoint(x, y):
                    return 1

                if lvl3.collidepoint(x, y):
                    return 3

                if lvl4.collidepoint(x, y):
                    return 4

        display.update()
예제 #4
0
def run():
    global running
    global pygame

    display.set_title('Level 3')

    while running == True:
        running = False
        return True

        # Input
        for event in pygame.event.get():

            # Load in the fundemental functions in the game
            running = essentials.run_essentials(event)
            if not running:
                return True

        # Output

        # Update the display to show the changes you made
        display.update()
예제 #5
0
def tutorial():
    global pygame

    tutorial = True
    instruction = pygame.image.load(
        "pkg/level1/images/instructions_screen.jpg")
    while tutorial:

        display.prepare_update()

        # Input
        for event in pygame.event.get():
            # Load in the fundemental functions in the game
            tutorial = essentials.run_essentials(event)
            if not tutorial:
                return False

            if event.type == pygame.KEYDOWN:
                return True

        # Output
        display.window.blit(instruction, (0, 0))
        display.update()
예제 #6
0
def tutorial():
    global pygame

    tutorial = True
    while tutorial:

        display.prepare_update()

        # Input
        for event in pygame.event.get():
            # Load in the fundemental functions in the game
            tutorial = essentials.run_essentials(event)
            if not tutorial:
                return False

            if event.type == pygame.KEYDOWN:
                return True

        # Output
        pygame.font.init()
        myFont = pygame.font.SysFont('Sans Serif', 48)

        textsurface1 = myFont.render('Dodge the guards and bullets', False,
                                     (0, 0, 0))
        textsurface2 = myFont.render('Press `Space` key to jump', False,
                                     (0, 0, 0))
        textsurface3 = myFont.render('Press `Left CTRL` key to crawl', False,
                                     (0, 0, 0))
        textsurface4 = myFont.render('Press any key to continue', False,
                                     (0, 0, 0))

        display.window.blit(textsurface1, (200, 200))
        display.window.blit(textsurface2, (200, 230))
        display.window.blit(textsurface3, (200, 260))
        display.window.blit(textsurface4, (200, 320))
        display.update()
예제 #7
0
def run():
    global running
    global pygame

    #while running play the music
    pygame.mixer.init(44100, -16, 2, 2048)
    pygame.mixer.Channel(1).play(
        pygame.mixer.Sound('pkg/level2/sounds/elevator.wav'))

    timer = essentials.timer(3)

    #groups
    playergroup = pygame.sprite.Group()
    all_sprites = pygame.sprite.Group()
    background = pygame.sprite.Group()
    walls = pygame.sprite.Group()
    levelwalls = pygame.sprite.Group()
    enemygroup = pygame.sprite.Group()
    tafelgroup = pygame.sprite.Group()

    #Enemy waypoints
    waypoints = [[620, 100], [735, -455], [1890, -550], [1890, -450],
                 [615, -545]]
    #Enemy2 waypoints
    waypoints2 = [[1130, 165], [1115, 315], [1135, -210], [1680, -210],
                  [1680, 165]]
    #Enemy3 waypoints
    waypoints3 = [[2175, 290], [1300, 350], [1300, 290], [2175, 350]]
    #Enemy4 waypoints
    waypoints4 = [[1800, 0], [1975, -125], [2300, -130], [2300, 120],
                  [1970, 120]]
    #player position
    player = Player(((width / 2), (height / 2)))

    #side, top and bottom walls
    walltop = TopAndBottomWall(540, -620, all_sprites, walls)
    wallbottom = TopAndBottomWall(540, 410, all_sprites, walls)
    wallleft = SideWall((width / 2) - 100, (height / 2) - 930, all_sprites,
                        walls)
    wallright = SideWall((wallleft.rect.x + (1920 - 50)), (height / 2) - 930,
                         all_sprites, walls)

    ##horizontal and vertical walls
    #three in the beginning of the level
    wallvertical1 = VerticalWall(740, 230, levelwalls, walls)
    wallhorizontal1 = HorizontalWall(740, 180, levelwalls, walls)
    wallvertical2 = VerticalWall(940, 30, levelwalls, walls)

    #top part of the level
    wallvertical3 = VerticalWall(790, -370, levelwalls, walls)
    wallhorizontal2 = HorizontalWall(840, -370, levelwalls, walls)
    wallhorizontal3 = HorizontalWall(1040, -370, levelwalls, walls)
    wallhorizontal4 = HorizontalWall(1240, -370, levelwalls, walls)
    wallhorizontal5 = HorizontalWall(1440, -370, levelwalls, walls)
    wallhorizontal6 = HorizontalWall(1640, -370, levelwalls, walls)
    wallvertical3 = VerticalWall(1840, -370, levelwalls, walls)
    wallvertical4 = VerticalWall(2140, -370, levelwalls, walls)

    #bottom part of the level
    wallvertical5 = VerticalWall(1190, 230, levelwalls, walls)
    wallhorizontal7 = HorizontalWall(1690, 230, levelwalls, walls)
    wallhorizontal8 = HorizontalWall(2240, 230, levelwalls, walls)

    #big block in the middle
    wallhorizontal9 = HorizontalWall(1340, -70, levelwalls, walls)
    wallhorizontal10 = HorizontalWall(1340, -20, levelwalls, walls)
    wallhorizontal11 = HorizontalWall(1340, 30, levelwalls, walls)
    wallhorizontal12 = HorizontalWall(1340, 80, levelwalls, walls)

    #small block in the middle
    wallhorizontal13 = HorizontalWall(2040, -20, levelwalls, walls)
    wallhorizontal14 = HorizontalWall(2040, 30, levelwalls, walls)

    #enemy's
    enemy = Enemy((620, 50), waypoints, enemygroup)
    enemy2 = Enemy2((1115, 315), waypoints2, enemygroup)
    enemy3 = Enemy3((1900, -100), waypoints3, enemygroup)
    enemy4 = Enemy4((1900, -100), waypoints4, enemygroup)

    #the floor
    floor = Floor(540, -620, background)

    #tafel
    tafel = Tafel(2300, 300, tafelgroup)

    #camera
    camera = Vector2(0, 0)

    display.set_title('Level 2')

    #animated sprite
    clock = pygame.time.Clock()
    dt = clock.tick(60)

    while running:
        # Input
        for event in pygame.event.get():
            running = essentials.run_essentials(event)
            if not running:
                return True
            #player movement
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    player.vel.x = 5
                    player.vel.y = 0
                elif event.key == pygame.K_LEFT:
                    player.vel.x = -5
                    player.vel.y = 0
                elif event.key == pygame.K_UP:
                    player.vel.y = -5
                    player.vel.x = 0
                elif event.key == pygame.K_DOWN:
                    player.vel.y = 5
                    player.vel.x = 0
                if event.key == pygame.K_b:
                    pygame.mixer.Channel(0).stop()
                    pygame.mixer.Channel(1).stop()
                    return True

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT and player.vel.x > 0:
                    player.vel.x = 0
                elif event.key == pygame.K_LEFT and player.vel.x < 0:
                    player.vel.x = 0
                elif event.key == pygame.K_UP:
                    player.vel.y = 0
                elif event.key == pygame.K_DOWN:
                    player.vel.y = 0

        #update all the groups
        enemygroup.update()
        all_sprites.update()
        playergroup.update()
        background.update()
        walls.update()
        tafelgroup.update()

        ##player collision with walls
        # move player horizontal
        player.rect.x += player.vel.x
        # check collision horizontal
        if pygame.sprite.spritecollide(player, walls, False):
            # move it back
            player.rect.x -= player.vel.x
            # reset speed
            player.vel.x = 0

        # move player vertical
        player.rect.y += player.vel.y
        # check collision vertical
        if pygame.sprite.spritecollide(player, walls, False):
            # move it back
            player.rect.y -= player.vel.y
            # reset speed
            player.vel.y = 0

        camera -= player.vel

        display.window.fill((0, 0, 0))

        #draw background
        for sprite in background:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        #draw walls in level
        for sprite in levelwalls:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        # draw player and walls
        for sprite in all_sprites:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        #draw enemy's
        for sprite in enemygroup:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)

        #draw tafel
        for sprite in tafelgroup:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        #draw player
        display.window.blit(player.image, player.rect.topleft + camera)

        #update all the groups
        all_sprites.update()
        playergroup.update()
        background.update()
        walls.update()
        tafelgroup.update()

        # collision with enemy
        if pygame.sprite.spritecollide(player, enemygroup, False):
            #show busted
            display.window.blit(busted, [400, 150])
            #load hasta la vista
            hastalavista = pygame.mixer.music.load(
                "pkg/level2/sounds/hastalavista.wav")
            #play arnold sound
            pygame.mixer.music.play(0)
            display.update()
            time.sleep(3)
            return False

        #collision with table
        if pygame.sprite.spritecollide(player, tafelgroup, False):
            #show arnold face
            display.window.blit(gettothechopper, [0, 0])
            #load arnold chopper sound
            pygame.mixer.music.load("pkg/level2/sounds/gettothechopper.wav")
            #play arnold chopper sound
            pygame.mixer.music.play(0)
            display.update()
            time.sleep(6)
            return True

            # Load in the fundemental functions in the game

        # Output

        ## Update the display to show the changes you made
        # counter for player animation
        player.counter(dt)
        player.counter2(dt)
        player.counter3(dt)
        player.counter4(dt)

        ##counter for enemy animation
        enemy.counter(dt)
        enemy2.counter(dt)
        enemy3.counter(dt)
        enemy4.counter(dt)
        enemygroup.update()

        display.update()
예제 #8
0
def run():
    global running
    global pygame
    #set title for current level
    display.set_title("Level 4")

    #player configuration
    x, y = (100),(620)
    choppah_width = 245
    choppah_height = 79
    power = 0
    power_change = 0
    x_change = 0
    y_change = 0

    #enemy copter configuration
    enemy_turbo = 2
    enemy_startx = 1800
    enemy_starty = random.randrange(50, display_height - 50) 
    enemy_endy = random.randrange(50, display_height - 50)
    enemy_speed = 7
    enemy_speed += enemy_turbo
    enemy_height = 79
    enemy_width = 245

    #bomb configuration
    bomb_startx = random.randrange(0, display_width)
    bomb_starty = -300
    bomb_speed = -5
    bomb_height = 93
    bomb_width = 25

    #other values
    running = True
    gameWon = False
    ticks = 0
    index = 0
    cheatsEnabled = False

    pygame.mixer.Channel(0).set_volume(0.4)
    pygame.mixer.Channel(2).stop()
    pygame.mixer.Channel(0).play(pygame.mixer.Sound('files/sounds/victory.wav'))
    pygame.mixer.Channel(1).play(pygame.mixer.Sound('files/sounds/coptah.wav'))

    #game loop
    while running == True:

        #catch all pressed keys
        for event in pygame.event.get():
            running = essentials.run_essentials(event)
            if not running:
                return True

            #direction change based on pressed key
            if event.type == pygame.KEYDOWN and ticks > 120:
                if event.key == pygame.K_UP:
                    power_change = 0.25
                    power = -5
                if event.key == pygame.K_LEFT:
                    x_change = -5
                if event.key == pygame.K_RIGHT:
                    x_change = 5
                if event.key == pygame.K_x:
                    if (cheatsEnabled):
                        cheatsEnabled = False
                    else:
                        cheatsEnabled = True
                if event.key == pygame.K_b:
                    return True

        #set the new position based on direction change
        power += power_change
        #player y pos remains same, x pos goes forward on game win
        if ticks > 3000:
            power = 0
            x_change = 5
        if ticks < 120:
            x += 0.6
            y -= 2.5
        if ticks >= 120:
            y += power
            x += x_change
            bomb_starty -= bomb_speed
            enemy_startx -= enemy_speed

        if  bomb_starty > display_height + 100:
            bomb_startx = random.randrange(0, display_width - 100)
            bomb_starty = 0
        if  enemy_starty > y:
            enemy_starty -= 1.2
        if  enemy_starty < y:
            enemy_starty += 1.2

        if enemy_startx < -250:
            enemy_starty = random.randrange(0, display_height - 100)
            enemy_startx = 1500

        #drawing rectangles for entities with collision
        bombRect = pygame.draw.rect(display.window, (0,0,0), (bomb_startx,bomb_starty,bomb_width,bomb_height))
        choepahRect = pygame.draw.rect(display.window, (0,0,0), (x,y,choppah_width - 30,choppah_height))
        enemyRect = pygame.draw.rect(display.window, (0,0,0), (enemy_startx + 10,enemy_starty,enemy_width - 10,enemy_height))
        
        #draw the background over the rectangles
        background.draw(display.window, index % background.totalCellCount, 0, 0, CENTER_HANDLE)

        #draw sprites/images on the position of the rectangles
        choepah.draw(display.window, index % choepah.totalCellCount, x, y, CENTER_HANDLE)
        enemy.draw(display.window, index % enemy.totalCellCount, enemy_startx, enemy_starty, CENTER_HANDLE)

        #after 20 seconds enemy copters speedup
        if (ticks > 1000 and ticks <= 2000):
            enemy_speed = 12

        #after 40 seconds 
        if (ticks > 2000 and ticks <= 3000):
            enemy_speed = 13
            #when player collides with bomb, restart level
            bombs(bomb_startx, bomb_starty, bomb_height, bomb_width)
            if choepahRect.colliderect(bombRect) and not cheatsEnabled:
                lose("by bomb")
                return False
            
        #display message after 20 seconds
        if (ticks == 2000):
            message_display("The cops are pissed!", 40, 300, 600)
            pygame.mixer.Channel(0).stop()
            pygame.mixer.Channel(2).set_volume(0.5)
            pygame.mixer.Channel(2).play(pygame.mixer.Sound('files/sounds/thestruggle.wav'))
            time.sleep(3)

        #game win
        if (ticks > 3000):
            enemy_starty = 1100
            bomb_starx = 2000
            gameWon = True
            if (x > 1280):
                message_display("You have escaped!", 35, 350, 600)
                if (x > 2500):
                    pygame.mixer.Channel(2).fadeout(1000)
                    gameWon = True
                    return True


        #when a player collides with border, restart level
        if (x > display_width - choppah_width or x < 0 or y < 0 or y+choppah_height > display_height) and not gameWon and not cheatsEnabled:
            lose("the border")
            return False

        #when player collides with enemy copter, restart level
        if choepahRect.colliderect(enemyRect) and not cheatsEnabled:
            lose("by copter")
            return False

        index += 1
        ticks += 1

        #Makes the changes visible
        display.update()
예제 #9
0
def run():
    global running
    global pygame

    global visible_speech_balloon
    global speech_balloon
    global interaction_mark1
    global interaction_mark2
    global interaction_mark3
    global interaction_mark4
    global key_obtained

    global bed_scenario
    global toilet_scenario
    global mob_scenario
    global player
    global highlighted_answer

    display.set_title('Level 1')

    new()
    load_data()

    while running:
        display.prepare_update()

        # Input
        for event in pygame.event.get():
            running = essentials.run_essentials(event)
            if not running:
                return True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    if visible_speech_balloon:
                        if multiple_choice_answers:
                            if highlighted_answer > highlighted_answer_minimum_boundary:
                                highlighted_answer -= 1

                if event.key == pygame.K_b:
                    pygame.mixer.Channel(1).stop()
                    return True

                if event.key == pygame.K_DOWN:
                    if visible_speech_balloon:
                        if multiple_choice_answers:
                            if highlighted_answer < highlighted_answer_maximum_boundary:
                                highlighted_answer += 1

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_RETURN:
                    if visible_speech_balloon:
                        if speech_balloon_object.scenario == 1:  # I don't have to go...
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 2 and highlighted_answer == 4:  # Do you want to play a game?;Answer 3 questions...;and I'll hand over the key --> Yes
                            bed_scenario = 3
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 2 and highlighted_answer == 5:  # Do you want to play a game?;Answer 3 questions...;and I'll hand over the key --> No
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 3:  # Here is my first question:;The person who knows he uses;it, doesn't know he uses it.;What is it?
                            bed_scenario = 4
                            multiple_choice_answers = True
                            highlighted_answer = 1
                            highlighted_answer_minimum_boundary = 1
                            highlighted_answer_maximum_boundary = 4
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 4 and highlighted_answer != 4:  # Insurance;Necktie;Sugar;Coffin
                            bed_scenario = 5
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 4 and highlighted_answer == 4:  # Insurance;Necktie;Sugar;Coffin
                            bed_scenario = 6
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 5:  # WRONG!;Get used to being here,;cause you're going to be;here for a while...
                            bed_scenario = 3
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 6:  # That's correct.;Here's my next question:
                            bed_scenario = 7
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 7:  # Have you ever heard of a;dyslexic Satanist?
                            bed_scenario = 8
                            multiple_choice_answers = True
                            highlighted_answer = 1
                            highlighted_answer_minimum_boundary = 1
                            highlighted_answer_maximum_boundary = 4
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 8 and highlighted_answer != 2:  # They prey to Christ;He sold his soul to Santa;There are none;No
                            bed_scenario = 9
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 8 and highlighted_answer == 2:  # They prey to Christ;He sold his soul to Santa;There are none;No
                            bed_scenario = 10
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 9:  # You're wrong!;I guess you're not so smart;...
                            bed_scenario = 7
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 10:  #  Okay. For my final game,;I want you to insult the;other inmate's mother.
                            bed_scenario = 11
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 11:  # We're gonna torture him;with the infamous your momma jokes.
                            bed_scenario = 12
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 12:  # Unfortunately for you,;I only know the setups,;you're gonna have to come;up with the punchlines
                            bed_scenario = 13
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 13:  # Go talk to the other inmate.
                            bed_scenario = 10
                            mob_scenario = 15
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 14:  # Go away.;I have nothing to say.
                            mob_scenario = 14
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 15:  # Okay, here goes nothing... *
                            mob_scenario = 16
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 16:  # HEY YOU!;YO' MOMMA'S SO FAT...
                            mob_scenario = 17
                            multiple_choice_answers = True
                            highlighted_answer = 1
                            highlighted_answer_minimum_boundary = 1
                            highlighted_answer_maximum_boundary = 3
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 17 and highlighted_answer != 2:  # ...SHE SHOWED UP EARLY;FOR HER OWN FUNERAL!;...SHE HAS MORE FOLDS,;THAN AN ORIGAMI ACCORDEON!;...IF SHE FELL IN NUCLEAR WASTE,;NO ONE WOULD NOTICE!
                            mob_scenario = 18
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 17 and highlighted_answer == 2:  # ...SHE SHOWED UP EARLY;FOR HER OWN FUNERAL!;...SHE HAS MORE FOLDS,;THAN AN ORIGAMI ACCORDEON!;...IF SHE FELL IN NUCLEAR WASTE,;NO ONE WOULD NOTICE!
                            mob_scenario = 19
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 18:  # Stop talking trash!;You suck at this!
                            mob_scenario = 15
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 19:  # Not a word about my mother!;She's a saint.
                            mob_scenario = 20
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 20:  # YO' MOMMA'S SO RADIANT...
                            mob_scenario = 21
                            multiple_choice_answers = True
                            highlighted_answer = 1
                            highlighted_answer_minimum_boundary = 1
                            highlighted_answer_maximum_boundary = 3
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 21 and highlighted_answer != 1:  # ...IF SHE FELL IN NUCLEAR WASTE,;NO ONE WOULD NOTICE!;...SHE BRINGS COUPONS TO;THE PENNY ARCADE!;...SHE SHOWED UP EARLY;FOR HER OWN FUNERAL!
                            mob_scenario = 22
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 21 and highlighted_answer == 1:  # ...IF SHE FELL IN NUCLEAR WASTE,;NO ONE WOULD NOTICE!;...SHE BRINGS COUPONS TO;THE PENNY ARCADE!;...SHE SHOWED UP EARLY;FOR HER OWN FUNERAL!
                            mob_scenario = 23
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 22:  # You ain't hurtin nobody,;you little bitch!
                            mob_scenario = 15
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 23:  # Ahhh, it hurts...;IT HURTS!
                            mob_scenario = 24
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 24:  # YO' MOMMA'S SO PUNCTUAL...
                            mob_scenario = 25
                            multiple_choice_answers = True
                            highlighted_answer = 1
                            highlighted_answer_minimum_boundary = 1
                            highlighted_answer_maximum_boundary = 3
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 25 and highlighted_answer != 2:  # ...SHE BRINGS COUPONS TO;THE PENNY ARCADE!;...SHE SHOWED UP EARLY;FOR HER OWN FUNERAL!;...THE ONLY TIME SHE'S LOW;IS AT A LIMBO CONTEST!
                            mob_scenario = 26
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 25 and highlighted_answer == 2:  # ...SHE BRINGS COUPONS TO;THE PENNY ARCADE!;...SHE SHOWED UP EARLY;FOR HER OWN FUNERAL!;...THE ONLY TIME SHE'S LOW;IS AT A LIMBO CONTEST!
                            mob_scenario = 27
                            multiple_choice_answers = False
                            highlighted_answer = 0
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, mob_scenario)

                        elif speech_balloon_object.scenario == 26:  # You had your chance,;now F**K OFF!
                            mob_scenario = 15
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 27:  # Enough, enough!; I'm suffocating...;sob.. sob... *
                            mob_scenario = 28
                            bed_scenario = 30
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, 29)

                        elif speech_balloon_object.scenario == 28:  # I'm done talking to you;Leave me alone...
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 29:  # Now to claim the key;and get the f**k outta here! *
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 30:  # Man...;I had the time of my life!!;Didn't know you had it in ya!
                            bed_scenario = 31
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 31:  # Unfortunately for you,;I don't have the key on me,;but I'm sure that you little;POTTY mouth;will know where to find it.
                            bed_scenario = 30
                            toilet_scenario = 32
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 32:  # GROSS...;;* key obtained *
                            toilet_scenario = 33
                            bed_scenario = 34
                            key_obtained = True
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 33:  # I already got the key...
                            visible_speech_balloon = False
                            player.can_walk = True

                        elif speech_balloon_object.scenario == 34:  # Drop by anytime pal.
                            bed_scenario = 35
                            speech_balloon_object.choose_scenario(
                                visible_speech_balloon, reader, bed_scenario)

                        elif speech_balloon_object.scenario == 35:  # Wouldn't count on it "pal" *
                            bed_scenario = 34
                            visible_speech_balloon = False
                            player.can_walk = True

    # Output
        pygame.mixer.init()
        pygame.font.init()
        font = pygame.font.Font(FONT, 19)
        font2 = pygame.font.Font(FONT, 13)

        if player.speedx or player.speedy > 0:
            all_sprites.remove(interaction_mark1, interaction_mark2,
                               interaction_mark3, interaction_mark4)
            all_sprites.remove(speech_balloon)

        # for interaction with the bed "object"
        if player.rect.x >= 930 and player.rect.y <= 222:

            if player.keys[pygame.K_SPACE]:
                player.can_walk = False
                visible_speech_balloon = True
                if bed_scenario == 2:
                    multiple_choice_answers = True
                    highlighted_answer = 4
                    highlighted_answer_minimum_boundary = 4
                    highlighted_answer_maximum_boundary = 5
                speech_balloon_object.choose_scenario(visible_speech_balloon,
                                                      reader, bed_scenario)

        # for interaction with the toilet
        if (player.rect.x >= 640
                and player.rect.x <= 772) and player.rect.y <= 150:
            if player.keys[pygame.K_SPACE]:
                visible_speech_balloon = True
                player.can_walk = False
                speech_balloon_object.choose_scenario(visible_speech_balloon,
                                                      reader, toilet_scenario)

        # for interaction with the bars of the player's cell
        if player.rect.x == 622:
            if player.keys[pygame.K_SPACE]:
                visible_speech_balloon = True
                player.can_walk = False
                if key_obtained == True:
                    all_sprites.remove(bars)
                    bars.remove(jailDoor)
                elif key_obtained == False:
                    speech_balloon_object.choose_scenario(
                        visible_speech_balloon, reader, mob_scenario)

        hits_wall = pygame.sprite.spritecollide(player, walls, False)
        if hits_wall:
            player.rect.x = player.rect.x - player.speedx
            player.rect.y = player.rect.y - player.speedy

        hits_bed = pygame.sprite.spritecollide(player, bed, False)
        if hits_bed:
            player.rect.x = player.rect.x - player.speedx
            player.rect.y = player.rect.y - player.speedy

            if player.speedx == 0:
                all_sprites.add(interaction_mark2)

            if player.speedy == 0:
                all_sprites.add(interaction_mark2)

        hits_bars = pygame.sprite.spritecollide(player, bars, False)
        if hits_bars:
            player.rect.x = player.rect.x - player.speedx
            player.rect.y = player.rect.y - player.speedy

            if key_obtained == False:
                if player.speedx == 0:
                    all_sprites.add(interaction_mark1)
                if player.speedy == 0:
                    all_sprites.add(interaction_mark1)
                    if player.keys[pygame.K_SPACE]:
                        key_obtained = False

            else:
                all_sprites.remove(bars)
                bars.remove(jailDoor)

        hits_jaildoor = pygame.sprite.spritecollide(player, jaildoor, False)
        if hits_jaildoor:
            player.rect.x = player.rect.x - player.speedx
            player.rect.y = player.rect.y - player.speedy

        hits_toilet = pygame.sprite.spritecollide(player, toilet, False)
        if hits_toilet:
            player.rect.x = player.rect.x - player.speedx
            player.rect.y = player.rect.y - player.speedy
            if player.speedx == 0:
                all_sprites.add(interaction_mark3)

            if player.speedy == 0:
                all_sprites.add(interaction_mark3)

        hits_exit = pygame.sprite.spritecollide(player, exits, False)
        if hits_exit:
            player.rect.x = player.rect.x - player.speedx
            player.rect.y = player.rect.y - player.speedy
            return True

        display.window.blit(background, background_rect)
        all_sprites.draw(display.window)

        if visible_speech_balloon:
            all_sprites.add(speech_balloon)
            Text(speech_balloon_object, font, font2, reader,
                 highlighted_answer)
        else:
            all_sprites.remove(speech_balloon)
        all_sprites.update()

        display.update()
예제 #10
0
def run():
    global running
    global pygame

    jumping = False
    crawling = False

    player = Player()
    enemies = []

    display.set_title('Level 3')
    timer = essentials.timer(30)
    enemy_spawn_timer = essentials.timer(0)

    pygame.mixer.Channel(1).set_volume(0.4)
    pygame.mixer.Channel(1).play(pygame.mixer.Sound('files/sounds/run.wav'))
    while running == True:

        display.prepare_update()

        # Input
        for event in pygame.event.get():
            # Load in the fundemental functions in the game
            running = essentials.run_essentials(event)
            if not running:
                return True

            if event.type == pygame.KEYDOWN:
                if not jumping:
                    if event.key == pygame.K_SPACE:
                        jumping = True
                    elif event.key == pygame.K_LCTRL:
                        crawling = True
                if event.key == pygame.K_b:
                    pygame.mixer.Channel(1).stop()
                    return True

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LCTRL:
                    crawling = False
        if running:
            if timer.check_timer():
                helicopter = Helicopter()
                helicopter.update()
                player.end_game()
                if player.position.x > helicopter.position.x:
                    pygame.mixer.Channel(1).stop()
                    return True
            else:
                if enemy_spawn_timer.check_timer():
                    enemy_spawn_timer = essentials.timer(randint(1, 3))
                    if randint(0, 1) == 0:
                        enemies.append(Guard())
                    else:
                        enemies.append(Bullets())

        # Output
        pygame.font.init()
        myFont = pygame.font.SysFont('Sans Serif', 48)
        textsurface = myFont.render(str(timer.get_time() / 1000), False,
                                    (0, 0, 0))

        pygame.draw.rect(display.window, (0, 0, 0),
                         pygame.Rect((0, 680), (1280, 40)))

        if crawling:
            player.crawl()
        elif jumping:
            jumping = player.jump()

        for enemy in enemies:
            enemy.update()
            if isinstance(enemy, Guard):
                if player.rect.colliderect(enemy.guard):
                    return False
            else:
                if player.rect.colliderect(
                        enemy.bullet1) or player.rect.colliderect(
                            enemy.bullet2) or player.rect.colliderect(
                                enemy.bullet3):
                    return False

        if not running:
            return True

        display.window.blit(textsurface, (0, 0))
        player.update()

        # Update the display to show the changes you made
        display.update()