Beispiel #1
0
def tick(keys):
    global game_started
    global score
    global player_height
    global game_lost

    if game_started and not game_lost:

        camera.clear("white")

        move_player(keys)

        animate_player()

        handle_collision()

        scroll_downwards(movement_each_frame)

        if player.y >= CAMERA_HEIGHT:
            game_lost = True

        draw_collection(platforms)
        draw_collection(jetpacks)
        camera.draw(player)
        display_scorebox()
    elif not game_started:
        display_start_screen(keys)
    elif game_lost:
        display_end_screen(score)
        gamebox.pause()

    camera.display()
Beispiel #2
0
def touch_bird():
    global worm, bird, new_b_x, new_b_y, worm_lives, hearts

    if worm[0].touches(bird):
        cawplayer = caw.play()
        worm_lives -= 1

        new_b_x = random.randrange(100 - bird.x, 700 - bird.x)
        new_b_y = random.randrange(160 - bird.y, 500 - bird.y)

        # prevents the bird from being too close to the apple
        while abs(apple.x - new_b_x) <= 100:
            new_b_x = random.randrange(100 - bird.x, 700 - bird.x)
        while abs(apple.y - new_b_y) <= 100:
            new_b_y = random.randrange(160 - bird.y, 500 - bird.y)

        bird.move(new_b_x, new_b_y)

        if worm_lives > 0:
            hearts.pop(0)
        elif worm_lives <= 0:
            camera.clear('black')
            camera.draw(gameover)
            camera.draw(gameover_lives)
            gamebox.pause()
Beispiel #3
0
def tick(keys):
    """
    This function runs the game function, and changes based on round
    :param keys: Input keys
    :return: NA
    """
    global tick_count
    camera.clear("white")
    p1.image = images[int(tick_count) % len(images)]
    p2.image = p2images[int(tick_count) % len(images)]
    tick_count += 0.1
    if game_on == 0:
        title(keys)
    elif game_on == 1:
        game(keys)
    elif game_on == 2:
        game(keys)

    elif game_on == 3:
        game(keys)
    elif game_on == 4:
        game(keys)
        gamebox.pause()

    camera.display()
Beispiel #4
0
def tick(keys):
    global game_on
    global p1_score
    global p2_score
    if game_on:
        top_barrier.move_speed()
        bot_barrier.move_speed()

    # ------- INPUT ---------
    if pygame.K_SPACE in keys:
        game_on = True
    '''

    '''
    #top_barrier.move(8,0)
    # Draw all the walls
    for wall in walls:
        camera.draw(wall)

    camera.draw(top_barrier)
    camera.draw(bot_barrier)
    #camera.draw(ball)

    # ---- CHECKING FOR WIN ----
    if p1_score >= 10:
        camera.draw(
            gamebox.from_text(400, 100, "Red Wins!", "Arial", 40, "Red", True))
        gamebox.pause()
    if p2_score >= 10:
        camera.draw(
            gamebox.from_text(400, 100, "Yellow Wins!", "Arial", 40, "Yellow",
                              True))
        gamebox.pause()
    camera.display()
Beispiel #5
0
def defeated_by_m():
    global defeated
    if defeated:
        camera.clear('paleturquoise')
        defeat = gamebox.from_image(0, 0, 'defeated.png')
        defeat.center = camera.center
        camera.draw(defeat)
        gamebox.pause()
Beispiel #6
0
def tick(keys):
    global end_game
    global ticks
    ticks += 1

    camera.clear("white")

    x = random.randrange(100, 400)
    y = random.randrange(100, 400)
    if 400-x/2 - y/2 < 60:
        x = random.randrange(50, 300)
        y = random.randrange(50, 300)

    for pillar in pillars_up:
        pillar.x -= 7
        if bird.touches(pillar):
            end_game = True
        if pillar.x < camera.left:
            pillar.x += 400
            pillar.size = [20, x]
        camera.draw(pillar)

    for pillar in pillars_down:
        pillar.x -= 7
        if bird.touches(pillar):
            end_game = True
        if pillar.x < camera.left:
            pillar.x += 400
            pillar.size = [20, y]
        camera.draw(pillar)

    if pygame.K_SPACE in keys:
        bird.y -= 12
    bird.y += 6
    bird.move_speed()

    if bird.y < 0:
        end_game = True
    if bird.y > 400:
        end_game = True

    camera.draw(bird)

    for pillar in pillars_up:
        camera.draw(pillar)
    for pillar in pillars_down:
        camera.draw(pillar)

    score = gamebox.from_text(camera.x, 250, "scores:" + str(ticks // 30),"Arial", 30, "black", bold=True)

    if end_game:
        gamebox.pause()
        camera.draw(end_text)
        camera.draw(score)

    camera.display()
Beispiel #7
0
def tick(keys):

    global game_on
    global ticker
    global translation

    translation += (1/30)
    if translation*15 > 2000:
        translation= 0
    screen.blit(bg, (-translation*15, 0))
    if game_on:
        bird.move_speed()
        top_barrier.move_speed()
        bot_barrier.move_speed()

    if top_barrier.x == 0:
        seperation = random.randint(60,100)
        top_displacement = random.randint(-200, 200)
        top_on_screen = 300 + top_displacement
        bot = 600 - top_on_screen - seperation
        bot_displacement = 300 + 600 - bot
        top_barrier.move(800, 0)
        bot_barrier.move(800, 0)
        top_barrier.center = [800, bot_displacement]
        bot_barrier.center = [800, top_displacement]

    if pygame.K_UP in keys:
        game_on = True

    if pygame.K_SPACE in keys:
        bird.move(0, -16)

    if game_on:
        camera.draw(gamebox.from_text(400, 50, str(int(ticker)), "Arial", 50, "Yellow", True))
        for wall in walls:
            camera.draw(wall)
        camera.draw(top_barrier)
        camera.draw(bot_barrier)
        camera.draw(bird)

    if game_on:
        ticker += (1/30)
    if top_barrier.touches(bird) or bot_barrier.touches(bird) or bird.touches(walls[0]) or bird.touches(walls[1]):
        camera.clear("black")
        bird.center = [200, 100]
        camera.draw(gamebox.from_text(400, 100, 'SCORE:', "Arial", 70, "Yellow", True))
        camera.draw(gamebox.from_text(400, 300, str(int(ticker)), "Arial", 100, "Yellow", True))
        gamebox.pause()



    if not game_on:
        camera.draw(gamebox.from_text(400, 200, 'Flappybird.py', 'Arial', 70, "Yellow", True))
        camera.draw(gamebox.from_text(400, 300, 'By Christopher Geier (cpg3rb)', 'Arial', 40, "Yellow", True))
        camera.draw(gamebox.from_text(400,350,'Press Up to Start','Arial',20,"Yellow",True))
    camera.display()
Beispiel #8
0
def game_over():
    gamebox.pause()
    final_score = gamebox.from_text(camera.x,
                                    camera.y,
                                    "Game Over! Final Score: " + str(score),
                                    "Times New Roman",
                                    30,
                                    "red",
                                    bold=True)
    camera.draw(final_score)
Beispiel #9
0
def time():
    """function that displays a timer countdown"""
    global game_on, tick_counter, game_over
    clock = 60
    if game_on:
        clock -= tick_counter//30
        clock_image = gamebox.from_text(75, 25, "time: " + str(clock), 30, "green", bold=True)
        camera.draw(clock_image)
        if clock == 0:
            camera.draw(game_over)
            gamebox.pause()
def level(keys):
    camera.clear("cyan")
    global x, y, sponge, counter, death_screen
    sponge.speedx = 0
    if pygame.K_RIGHT in keys:
        sponge.speedx += 10
        sponge.x += 10
    if pygame.K_LEFT in keys:
        sponge.speedx -= 10
        sponge.x -= 10
    if pygame.K_DOWN in keys:
        sponge.yspeed += 5
    sponge.yspeed += 1
    sponge.y = sponge.y + sponge.yspeed
    counter += 1
    if len(rocks) < 75:
        if counter % 25 == 0:
            rock = gamebox.from_image(
                random.randint(200 + 400 * (counter / 25),
                               600 + 400 * (counter / 25)), camera.y + 250,
                "patricksrock.png")
            rock.size = random.randint(50, 75), 50
            #rock = gamebox.from_color(random.randint(200 + 400*(counter/25), 600 +400*(counter/25)), camera.y+250, "white", random.randint(50,75), 20)
            rocks.append(rock)

    for wall in walls:
        if sponge.bottom_touches(wall):
            sponge.yspeed = 0
            if pygame.K_SPACE in keys:
                sponge.yspeed = -20
        if sponge.left_touches(wall) or sponge.right_touches(wall):
            if pygame.K_SPACE in keys:
                sponge.yspeed = -10
        if sponge.touches(wall):
            sponge.move_to_stop_overlapping(wall)
        camera.draw(wall)
    for rock in rocks:
        if sponge.touches(rock):
            death_screen.center = camera.center
            camera.draw(death_screen)
            gamebox.pause()
        camera.draw(rock)
    camera.x += 3
    if len(rocks) > 30:
        camera.x += 4
    if len(rocks) > 70:
        camera.x += 2
        sponge.speedx += 10
    camera.draw(sponge)
    camera.draw(floor)
    camera.display()
Beispiel #11
0
def game_end():
    global frame_of_explosion
    if health <= 0:
        frame_of_explosion += 1
        if count % 1 == 0:
            exploding.center = character.center
            exploding.image = exploding_sheet[frame_of_explosion]
        if frame_of_explosion == 15:
            gamebox.pause()
            camera.draw(
                gamebox.from_text(200, 300,
                                  "Your final score is " + str(score) + " !",
                                  30, "black"))
        camera.draw(exploding)
Beispiel #12
0
def tick(keys):
    """this function increments score based on elapsed time, creates and renders obstacles and bonuses, character moves left or right every time the
    left or right arrow key is clicked, obstacles and bonuses randomly scroll from left to right, game ends upon collision with obstacle or movement off screen"""
    global ticks
    ticks += 1
    camera.clear("light blue")
    camera.draw(background)
    camera.draw(sky)
    objects.append(sky)
    character.y += 5
    camera.draw(character)
    for item in objects:
        camera.draw(item)
    for item in obstacles:
        camera.draw(item)

    if pygame.K_LEFT in keys:
        character.x -= 20
    if pygame.K_RIGHT in keys:
        character.x += 20

    character.speedy += 0.01
    character.move_speed()
    camera.x = character.x + 10
    camera.y = character.y

    if ticks % 60 == 0:
        global score
        score += 1
        bonuses.append(bonuses)
    for item in bonuses:
        item.x += 30
    for item in obstacles:
        character.move_to_stop_overlapping(item)
        if character.bottom_touches(item) or character.right_touches(item) or character.left_touches(item):
            text = gamebox.from_text(camera.x, camera.y, "Game Over!", 60, 'red')
            camera.draw(text)
            gamebox.pause()
    for item in bonuses:
        if character.bottom_touches(item) or character.right_touches(item) or character.left_touches(item):
            score += 10
    if character.x > camera.x or character.y > camera.y:
        text = gamebox.from_text(camera.x, camera.y, "Game Over!", 60, 'red')
        camera.draw(text)
        gamebox.pause()
    score_box = gamebox.from_text(camera.left + 100, camera.top + 20, "Weight: " + str(score) + "lbs.", 60, "black")
    camera.draw(score_box)
    keys.clear()
    camera.display()
Beispiel #13
0
def tick(keys):
    global score
    score += 1

    if pygame.K_SPACE in keys:
        bird.speedy = -11
    bird.speedy += 1
    bird.move_speed()

    pillar1_bottom.speedx = -10
    pillar1_top.speedx = -10
    pillar2_bottom.speedx = -10
    pillar2_top.speedx = -10
    pillar1_bottom.move_speed()
    pillar1_top.move_speed()
    pillar2_bottom.move_speed()
    pillar2_top.move_speed()

    if pillar1_bottom.right < 1:
        pillar1_bottom.left = pillar2_bottom.left + 700
        pillar1_top.left = pillar2_bottom.left + 700
        pillar1_bottom.size = 75, random.randrange(10, 300)
        pillar1_bottom.bottom = 450
        pillar1_top.bottom = 340 - pillar1_bottom.height
    if pillar2_bottom.right < 1:
        pillar2_bottom.left = pillar1_bottom.left + 700
        pillar2_top.left = pillar1_bottom.left + 700
        pillar2_bottom.size = 75, random.randrange(10, 300)
        pillar2_bottom.bottom = 450
        pillar2_top.bottom = 340 - pillar2_bottom.height

    camera.clear("black")
    camera.draw(bird)
    camera.draw(ground)
    camera.draw(pillar1_bottom)
    camera.draw(pillar1_top)
    camera.draw(pillar2_bottom)
    camera.draw(pillar2_top)
    keys.clear()
    if bird.touches(ground) or bird.touches(pillar1_bottom) or bird.touches(pillar1_top) \
            or bird.touches(pillar2_bottom) or bird.touches(pillar2_top):
        camera.clear("BLACK")
        score_box = gamebox.from_text(camera.x, camera.y, "Score: " + str(score // 30), "arial", 24, "white")
        camera.draw(score_box)
        gamebox.pause()
    camera.display()
Beispiel #14
0
def tick(keys):
    global level
    global power
    if pygame.K_SPACE in keys:
        bird.speedy = -8
    bird.x += 7
    bird.yspeed += 1
    bird.y = bird.y + bird.yspeed
    cam.clear("cyan")
    cam.draw(bird)
    for f in floor:
        if bird.bottom_touches(f):
            power = False
            gamebox.pause()
        cam.draw(f)
        f.x += 7
    cam.x += 7
    for c in ceiling:
        if bird.touches(c):
            power = False
            gamebox.pause()
        cam.draw(c)
        c.x += 7
    for t in top:
        if bird.touches(t):
            power = False
            gamebox.pause()
        cam.draw(t)
        if t.left < cam.left - 5:
            t.x = cam.right + 200
            t.y = random.randint(620, 800)
    for b in bottom:
        if bird.touches(b):
            power = False
            gamebox.pause()
        cam.draw(b)
        if b.left < cam.left - 5:
            b.x = cam.right + 200
            b.y = random.randint(-250, -40)
            level += 1
    if not power:
        cam.draw(
            gamebox.from_text(cam.x, cam.y, "Sorry! Score: " + str(level), 70,
                              "red"))
        gamebox.pause()
    cam.display()
Beispiel #15
0
def tick(keys):
    camera.clear('cyan')

    if pygame.K_RIGHT in keys:
        box.x += 10
    if pygame.K_LEFT in keys:
        box.x -= 10
    if pygame.K_UP in keys:
        box.y -= 10
    if pygame.K_DOWN in keys:
        box.y += 10

    for wall in walls:
        box.move_to_stop_overlapping(wall, -30, -30)

    camera.draw(box)
    for wall in walls:
        camera.draw(wall)
    camera.draw(goal)

    if box.touches(goal):
        won = gamebox.from_text(camera.x,
                                camera.y,
                                "You got " + str(box.score) + "!",
                                "Arial",
                                100,
                                'white',
                                bold=True)
        camera.draw(won)
        for wall in walls:
            wall.color = 'purple'
            camera.draw(wall)
        gamebox.pause()

    for coin in coins:
        camera.draw(coin)
    for coin in coins:
        if box.touches(coin, -60, -60):
            coins.remove(coin)
            box.score += 1

    # usually camera.display() should be the last line of the tick method
    camera.display()
Beispiel #16
0
def obstacle_move():
    """
    These pipes will be replaced some kind of graphic images that will serve as the pipes but those images should have
    the url placed in the obstacles method, and one time in the append statement hopefully this change should alter how
    the function operates and no further changes will be needed, yes this was fixed
    :return: void
    """
    global dist, height

    # d is getting a random index for the dist list so that way we can in the append statement access different heights
    d = random.randint(0, len(dist) - 1)
    # h is getting a random index for the height list so we can add a random height to the append statement
    h = random.randint(0, len(height) - 1)
    for obstacle in obstacles:
        obstacle.x -= 10

        if obstacle.y >= 550 and ob_bool[obstacles.index(obstacle)]:
            obstacle.y -= 4.9
            if obstacle.y <= 550:
                ob_bool[obstacles.index(obstacle)] = False

        if not ob_bool[obstacles.index(obstacle)]:
            obstacle.y += 1.70
            if obstacle.y >= 650:
                ob_bool[obstacles.index(obstacle)] = True

        if player.right_touches(obstacle):
            player.move_to_stop_overlapping(obstacle)
            gamebox.pause()
            end = gamebox.from_text(400, 300, "GAME OVER :`(", 50, color)
            camera.draw(end)
            camera.display()

        # The below if statement is meant to create a new obstacle every time one passes the between 750 and 800
        if 795 <= obstacle.x <= 800:
            # for the height part the images in the obstacle function should have varying heights or we are going to
            # have figure out how to change the heights of an imported image but for now h represents the height
            obstacles.append(gamebox.from_image(dist[d], 600, "spear.png"))
            ob_bool.append(True)
            obstacle.size = [20, height[h]]
        if obstacle.x < -400:
            obstacles.pop(0)
            ob_bool.pop(0)
Beispiel #17
0
def win_game():
    global level
    global current_level
    if level == 1 or level == 2:
        level += 1
        current_level = gamebox.from_text(400, 40, "Level " + str(level), 30,
                                          "purple")
        start_screen()
    elif level == 3:
        camera.draw(start_screen_background)
        camera.draw(extra_between_level_background)
        win_game1 = gamebox.from_text(325, 200, "Congratulations!", 60,
                                      "green")
        win_game2 = gamebox.from_text(325, 250, "You've beat the game!", 60,
                                      "green")
        win_game3 = gamebox.from_text(325, 350, "Thanks for playing!", 60,
                                      "green")

        camera.draw(win_game1)
        camera.draw(win_game2)
        camera.draw(win_game3)
        gamebox.pause()
def tick(keys):

    # make things global
    global char_counter
    global enemy_counter

    # character moving left and right
    if pygame.K_RIGHT in keys:
        character.x += 5
    if pygame.K_LEFT in keys:
        character.x -= 5

    # jumping
    if pygame.K_SPACE in keys and character.bottom_touches(ground):
        character.yspeed -= 17

    # gravity
    character.yspeed += 1
    character.y = character.y + character.yspeed

    enemy.yspeed += 1
    enemy.y = enemy.y + enemy.yspeed

    # enemy moves towards you
    if enemy.x > character.x:
        enemy.x -= 3

    else:
        enemy.x += 3

    # stop collisions with ground
    if character.bottom_touches(ground):
        character.yspeed = 0

    if character.touches(ground):
        character.move_to_stop_overlapping(ground)

    if enemy.bottom_touches(ground):
        enemy.yspeed = 0

    if enemy.touches(ground):
        enemy.move_to_stop_overlapping(ground)

    # character jumps on enemy
    if character.bottom_touches(enemy):
        enemy.x = 30
        enemy.y = 50
        enemy.yspeed = 0
        character.yspeed = -7

    # character gets hit on side
    if character.left_touches(enemy) or character.right_touches(enemy):
        enemy.x = 30
        enemy.y = 50
        enemy.yspeed = 0
        lose_health()

    # character touches coin
    if character.left_touches(coin) or character.right_touches(coin):
        coin.x = random.randint(100, 500)
        char_counter += 1

    # enemy touches coin
    if enemy.left_touches(coin) or enemy.right_touches(coin):
        coin.x = random.randint(100, 500)
        enemy_counter += 1


    # draw everything
    camera.clear("cyan")
    camera.draw(character)
    camera.draw(enemy)
    camera.draw(ground)
    camera.draw(coin)


    if health[0] == True:
        camera.draw(health1)
    if health[1] == True:
        camera.draw(health2)
    if health[2] == True:
        camera.draw(health3)

    # create score and draw it
    char_score = gamebox.from_text(700, 50, str(char_counter), "Comic Sans MS", 30, "red")
    enemy_score = gamebox.from_text(500, 50, str(enemy_counter), "Comic Sans MS", 30, "green")
    camera.draw(char_score)
    camera.draw(enemy_score)

    # game over screen
    if health[2] == False and char_counter <= enemy_counter:
        camera.draw(game_over_background)
        camera.draw(game_over_text)
        camera.draw(char_score)
        camera.draw(enemy_score)
        gamebox.pause()

    if health[2] == False and char_counter > enemy_counter:
        camera.draw(game_over_background)
        camera.draw(win_game_over_text)
        camera.draw(char_score)
        camera.draw(enemy_score)
        gamebox.pause()

    camera.display()
def tick(keys):

    global score
    global sprite_counter

    # move player
    if pygame.K_LEFT in keys:
        player.x -= 10

    if pygame.K_RIGHT in keys:
        player.x += 10

    # shooting bullets
    if pygame.K_SPACE in keys and bullet1.yspeed == 0:
        shoot_bullet(bullet1)
        bullet_sound.play()

    elif pygame.K_SPACE in keys and bullet2.yspeed == 0:
        shoot_bullet(bullet2)
        bullet_sound.play()

    elif pygame.K_SPACE in keys and bullet3.yspeed == 0:
        shoot_bullet(bullet3)
        bullet_sound.play()

    if pygame.K_SPACE in keys:
        keys.remove(pygame.K_SPACE)

    # moving bullets
    bullet1.y -= bullet1.speedy
    bullet2.y -= bullet2.speedy
    bullet3.y -= bullet3.speedy

    # stop bullet off screen
    if bullet1.y < 0:
        bullet1.speedy = 0
    if bullet2.y < 0:
        bullet2.speedy = 0
    if bullet3.y < 0:
        bullet3.speedy = 0

    # create enemies if there aren't any
    while len(enemies) < 3:
        enemies.append(create_enemy())

    # move the enemies
    for enemy in enemies:
        enemy.x += enemy.xspeed

    # reverse enemies if necessary
    for enemy in enemies:
        if enemy.x < 0:
            enemy.xspeed *= -1
        elif enemy.x > 800:
            enemy.xspeed *= -1

    # kill enemies with bullets
    for enemy in enemies:
        for bullet in bullets:
            if enemy.touches(bullet):
                enemy.x = random.randint(0, 800)
                enemy.y = random.randint(0,2) * 75 + 50
                enemy.xspeed = random.randint(3, 10)
                score += 1
                enemy_explosion_sound.play(fade_ms = 100)

    # enemy shoots bullets
    for i in range(len(en_bullets)):
        if en_bullets[i].yspeed == 0:
            enemy_shoot_bullet(enemies[i], en_bullets[i])

    # enemy bullets move
    for bullet in en_bullets:
        bullet.y += bullet.yspeed

    # handle bullets going off the screen
    for bullet in en_bullets:
        if bullet.y > 600:
            bullet.yspeed = 0

    # update the score
    score_display = gamebox.from_text(750, 10, str(score), "Algerian", 12, "yellow")

    # handle animations
    sprite_counter += 1
    if sprite_counter == 6:
        sprite_counter = 0


    player.image = player_animations[sprite_counter]
    for enemy in enemies:
        enemy.image = enemy_animations[sprite_counter]

    # play music
    music_player

    # draw everything
    camera.clear("black")
    camera.draw(player)
    camera.draw(bullet1)
    camera.draw(bullet2)
    camera.draw(bullet3)
    camera.draw(score_display)

    if lives[0] == True:
        camera.draw(life3)
    if lives[1] == True:
        camera.draw(life2)
    if lives[2] == True:
        camera.draw(life1)

    for bullet in en_bullets:
        camera.draw(bullet)

    for enemy in enemies:
        camera.draw(enemy)

    # game over
    for bullet in en_bullets:
        if bullet.touches(player):
            lose_health()
            bullet.yspeed = 0
            lose_life_sound.play()

    if lives[2] == False:
        camera.draw(game_over_background)
        game_over_score = gamebox.from_text(400, 300, "Final Score: " + str(score), "Algerian", 20, "yellow")
        camera.draw(game_over_score)
        death_sound.play()
        music_player.pause()
        gamebox.pause()

    camera.display()
Beispiel #20
0
def tick(keys):
    global scorep1
    global p1
    global size_variablep1
    global p2
    global scorep2
    global size_variablep2
    global health
    global banner
    global p1healthbarbackground
    global p1healthbarforeground
    global p1health
    global healthtextp1
    global p2healthbarbackground
    global p2healthbarforeground
    global p2health
    global healthtextp2
    global ticks
    ticks += 1
    time = gamebox.from_text(300, 20, 'time: ' + str(ticks // 30), 'Arial', 20,
                             'red')

    p1score = gamebox.from_text(200, 30,
                                'Blue player\'s score is: ' + str(scorep1),
                                'Arial', 18, 'white')
    p2score = gamebox.from_text(600, 30,
                                'Orange player\'s score is: ' + str(scorep2),
                                'Arial', 18, 'white')
    if show_splash:
        splash(keys)
        # camera.draw(logo)
        return
    camera.draw(background)
    camera.draw(p1)
    camera.draw(p2)
    camera.draw(item)
    camera.draw(banner)
    camera.draw(p1healthbarbackground)
    camera.draw(p1healthbarforeground)
    camera.draw(healthtextp1)
    camera.draw(p2healthbarbackground)
    camera.draw(p2healthbarforeground)
    camera.draw(healthtextp2)
    camera.draw(time)
    camera.display()
    if pygame.K_w in keys and (pygame.K_a and pygame.K_d
                               and pygame.K_s not in keys) and p1.speedy == 0:
        p1.speedy = -10
        p1.speedx = 0
        if p1.width >= p1.height:
            p1.size = p1.height, p1.width
    if pygame.K_s in keys and (pygame.K_d and pygame.K_a
                               and pygame.K_w not in keys) and p1.speedy == 0:
        p1.speedy = 10
        p1.speedx = 0
        if p1.width >= p1.height:
            p1.size = p1.height, p1.width
    if pygame.K_a in keys and (pygame.K_s and pygame.K_w
                               and pygame.K_d not in keys) and p1.speedx == 0:
        p1.speedx = -10
        p1.speedy = 0
        if p1.height >= p1.width:
            p1.size = p1.height, p1.width
    if pygame.K_d in keys and (pygame.K_w and pygame.K_s
                               and pygame.K_a not in keys) and p1.speedx == 0:
        p1.speedx = 10
        p1.speedy = 0
        if p1.height >= p1.width:
            p1.size = p1.height, p1.width
    p1.move_speed()

    if pygame.K_UP in keys and (pygame.K_LEFT and pygame.K_RIGHT and
                                pygame.K_DOWN not in keys) and p2.speedy == 0:
        p2.speedy = -10
        p2.speedx = 0
        if p2.width >= p2.height:
            p2.size = p2.height, p2.width
    if pygame.K_DOWN in keys and (pygame.K_LEFT and pygame.K_UP
                                  and pygame.K_RIGHT
                                  not in keys) and p2.speedy == 0:
        p2.speedy = 10
        p2.speedx = 0
        if p2.width >= p2.height:
            p2.size = p2.height, p2.width
    if pygame.K_LEFT in keys and (pygame.K_DOWN and pygame.K_UP
                                  and pygame.K_RIGHT
                                  not in keys) and p2.speedx == 0:
        p2.speedx = -10
        p2.speedy = 0
        if p2.height >= p2.width:
            p2.size = p2.height, p2.width
    if pygame.K_RIGHT in keys and (pygame.K_UP and pygame.K_LEFT
                                   and pygame.K_DOWN
                                   not in keys) and p2.speedx == 0:
        p2.speedx = 10
        p2.speedy = 0
        if p2.height >= p2.width:
            p2.size = p2.height, p2.width
    p2.move_speed()

    if p1.touches(item, -20, -20):
        scorep1 += 1
        size_variablep1 += 1
        item.x = random.randrange(25, 790)
        item.y = random.randrange(75, 575)
        if p1.width > p1.height:
            p1.size = 30 * size_variablep1, 30
        if p1.height > p1.width:
            p1.size = 30, 30 * size_variablep1
        p1health = 100

    if p1.x < 1 or p1.x > 799:
        # p1 = gamebox.from_color(200, 75, 'blue', 30, 29)
        # p2 = gamebox.from_color(600, 75, 'orange', 30, 29)
        # scorep1 = 0
        # size_variablep1 = 1
        ...
    if p1.x < 1:
        p1.x = 799
    if p1.x > 799:
        p1.x = 1

    if p1.touches(banner, -20, -20) or p1.y > 600:
        p1 = gamebox.from_color(200, 75, 'blue', 30, 29)
        p2 = gamebox.from_color(600, 75, 'orange', 30, 29)
        scorep1 = 0
        size_variablep1 = 1

    if p2.touches(item, -20, -20):
        scorep2 += 1
        size_variablep2 += 1
        item.x = random.randrange(25, 790)
        item.y = random.randrange(75, 575)
        if p2.width > p2.height:
            p2.size = 30 * size_variablep2, 30
        if p2.height > p2.width:
            p2.size = 30, 30 * size_variablep2

    if p2.x < 1 or p2.x > 799:
        p1 = gamebox.from_color(200, 10, 'blue', 30, 29)
        p2 = gamebox.from_color(600, 10, 'orange', 30, 29)
        p1health = 100
        scorep2 = 0
        size_variablep2 = 1

    if p2.touches(banner, -20, -20) or p2.y > 600:
        p1 = gamebox.from_color(200, 10, 'blue', 30, 29)
        p2 = gamebox.from_color(600, 10, 'orange', 30, 29)
        scorep2 = 0
        size_variablep2 = 1

    # Players lose health when touched by the other box, if that box is bigger than theirs
    if p1.touches(p2) and p1.size > p2.size:
        p2health -= 1
        p2healthbarforeground.size = p2health, 10

    if p2.touches(p1) and p2.size > p1.size:
        p1health -= 1
        p1healthbarforeground.size = p1health, 10

    if p1healthbarforeground.width < 0 or p2healthbarforeground.width < 0:
        gamebox.pause()

    camera.display()
Beispiel #21
0
def tick(keys):
    global ticks

    global walls
    ticks += 1

    if show_splash:
        splash(keys)
        return

    camera.clear('cyan')

    time = gamebox.from_text(0, 0, str(ticks // 30), "Arial", 40, "red")
    time.top = camera.top
    time.right = camera.right - 400
    camera.draw(time)

    camera.draw(box3)
    if pygame.K_UP in keys and box3.timer > 3:
        box3.y -= 80
        box3.timer = 0
    else:
        box3.y += 7

    box3.timer += 1
    #for wall in walls:
    #box3.move_to_stop_overlapping(wall)

    for list in walls:
        global r
        list[0].x -= 5
        list[1].x -= 5
        camera.draw(list[0])
        camera.draw(list[1])
        r = random.randrange(0, 600)

        if list[0].right < camera.left:
            list.remove(list[0])
            list.append(list[0])
            list[0] = gamebox.from_color(camera.x + 400, camera.bottom,
                                         "green", 50, r)

            list[0].x = camera.right

        if list[1].right < camera.left:
            list.remove(list[1])
            list.append(
                gamebox.from_color(camera.x + 400, camera.top, "green", 50,
                                   900 - r))
            list[1].x = camera.right

        if box3.touches(list[1]) or box3.touches(list[0]):
            lost = gamebox.from_text(camera.x,
                                     camera.y,
                                     "You Lost",
                                     "Arial",
                                     150,
                                     "white",
                                     bold=True)
            camera.draw(lost)
            scoree = gamebox.from_text(camera.x,
                                       camera.y + 100,
                                       "Score: ",
                                       "Arial",
                                       50,
                                       "white",
                                       bold=True)
            sc = gamebox.from_text(camera.x + 100,
                                   camera.y + 100,
                                   str((box3.timer) // 30),
                                   "Arial",
                                   50,
                                   "white",
                                   bold=True)
            camera.draw(scoree)
            camera.draw(sc)
            gamebox.pause()
            print(box3.timer)
    for thing in walls2:

        thing[0].x -= 5
        thing[1].x -= 5

        camera.draw(thing[0])
        camera.draw(thing[1])

        r = random.randrange(0, 600)
        if thing[0].right < camera.left:
            thing.remove(thing[0])

            thing.append(thing[0])
            thing[0] = gamebox.from_color(camera.x + 400, camera.bottom,
                                          "green", 50, r)
            thing[0].x = camera.right
        if thing[1].right < camera.left:
            thing.remove(thing[1])
            thing.append(
                gamebox.from_color(camera.x + 400, camera.top, "green", 50,
                                   900 - r))
            thing[1].x = camera.right
        # if list[1].right < camera.left:
        #     list[1] = gamebox.from_color(camera.x, camera.top, "green", 50, 900 - r)

        if box3.touches(thing[1]) or box3.touches(thing[0]):
            lost = gamebox.from_text(camera.x,
                                     camera.y,
                                     "You Lost",
                                     "Arial",
                                     150,
                                     "white",
                                     bold=True)
            camera.draw(lost)
            print("Score: ", ticks)
            gamebox.pause()
    # if box3.top < camera.bottom:
    #     lost = gamebox.from_text(camera.x, camera.y, "You Lost", "Arial", 150, "white", bold=True)
    #     camera.draw(lost)
    #     gamebox.pause()

    camera.display()
Beispiel #22
0
def tick(keys):
    global score
    # set it so you can access the health
    global current_health

    if pygame.K_RIGHT in keys:
        character.x += 5
    if pygame.K_LEFT in keys:
        character.x -= 5
    character.yspeed += 1
    character.y = character.y + character.yspeed
    camera.clear("blue")
    camera.draw(character)

    for badguy in badguys:
        badguy.yspeed += 1
        badguy.y += badguy.yspeed

        if character.x < badguy.x:
            badguy.x -= 3
        if character.x > badguy.x:
            badguy.x += 3

        if badguy.touches(character):
            # now when badguy touches you, decrease the healthbar
            current_health -= 1
            if current_health <= 0:
                camera.draw(gamebox.from_text(300, 300, "DEAD", 70, "red"))
                # this line will end the game
                gamebox.pause()

        # draw the health bar
        health_bar = gamebox.from_color(400, 50, "red", current_health * 2, 30)
        camera.draw(health_bar)

        for wall in walls:
            if badguy.bottom_touches(wall):
                badguy.yspeed = 0
            if badguy.touches(wall):
                badguy.move_to_stop_overlapping(wall)
        camera.draw(badguy)

    for coin in coins:
        if character.touches(coin):
            score += 1
            coins.remove(coin)
        camera.draw(coin)

    for wall in walls:
        if character.bottom_touches(wall):
            character.yspeed = 0
            if pygame.K_UP in keys:
                character.yspeed = -15
        if character.touches(wall):
            character.move_to_stop_overlapping(wall)
        camera.draw(wall)

    score_display = gamebox.from_text(40, 40, str(score), 50, "red")
    camera.draw(score_display)

    camera.display()
Beispiel #23
0
def tick(keys):

    global ticks, coins_got, coins, lives
    on_ground = False
    ticks += 1

    if show_splash:
        splash(keys)
        return

    if lava.right < camera.left:
        lava.x = camera.right + 50
        lava.size = [random.randrange(30, 100), 40]

    camera.clear('grey')

    for coin in coins:
        coin.size = 20, 20
        camera.draw(coin)
        if coin.right < camera.left:
            coin.x = random.randrange(camera.right + 100, camera.right + 300)
            coin.y = random.randrange(220, 300)
        if coin.touches(box):
            coins.remove(coin)
            x = gamebox.from_image(
                random.randrange(camera.right + 100, camera.right + 300),
                random.randrange(220, 300), "coin.png")
            x.size = 20, 20
            coins.append(x)
            coins_got += 1

    time = gamebox.from_text(0, 0, str(ticks // 60), 'Arial', 24, 'black')
    num_coins = gamebox.from_text(camera.left + 60, 10,
                                  'Coins: ' + str(coins_got), 'Arial', 24,
                                  'black')
    time.top = camera.top
    time.right = camera.right
    camera.draw(time)

    health = gamebox.from_text(5, 0, 'Health: ' + str(lives), 'Arial', 24,
                               'black')
    health.top = time.bottom
    health.left = camera.left
    camera.draw(health)

    for healths in healthplus:
        camera.draw(healths)
        if healths.right < camera.left:
            healths.x = camera.right + 3000
            healths.y = random.randint(200, 350)
        if box.touches(healths):
            healthplus.remove(healths)
            newhealth = gamebox.from_image(camera.right + 3000,
                                           random.randrange(220, 300),
                                           "plus.png")
            newhealth.size = 15, 15
            healthplus.append(newhealth)
            lives += 10

    for platform in platforms:
        camera.draw(platform)
        camera.draw(lava)
        if box.touches(platform):
            box.move_to_stop_overlapping(platform)
        if box.bottom_touches(platform):
            on_ground = True
        if platform.right < camera.right + 10:
            platform.right += 10

    for rains in rain:
        camera.draw(rains)
        if (coins_got < 100):
            rains.y += 6
        else:
            rains.y += 8
        if rains.y > 500:
            rains.y = -random.randint(50, 150)
            rains.x = random.randint(camera.left + 200, camera.right + 200)
            camera.draw(rains)
        if box.touches(rains):
            lives -= 1
            if lives <= 0:
                text3 = gamebox.from_text(camera.x, camera.y, "You died",
                                          "Arial", 20, 'black')
                text4 = gamebox.from_text(
                    camera.x, camera.y, "You lasted: " + str(ticks // 60) +
                    " seconds with " + str(coins_got) + " coins!", "Arial", 20,
                    'black')
                text4.top = text3.bottom
                camera.draw(text3)
                camera.draw(text4)
                gamebox.pause()
                camera.display()

    box.image = sheet[0]

    if pygame.K_UP in keys and on_ground:
        box.speedy = -28
    if pygame.K_RIGHT in keys:
        #box.x += 8
        box.image = sheet[(ticks // 3) % len(sheet)]
        box.x += 8
    if pygame.K_LEFT in keys:
        #box.x -= 5
        box.image = sheet[(ticks // 3) % len(sheet)]
        box.x -= 5

    box.speedy += 1

    box.speedx *= 0.95
    box.speedy *= 0.95

    box.speedy += 1

    box.move_speed()
    if (coins_got < 50):
        camera.move(3, 0)
    if (coins_got < 100 and coins_got >= 50):
        camera.move(5, 0)
    if (coins_got >= 100 and coins_got < 130):
        camera.move(6, 0)
    if (coins_got >= 130):
        camera.move(7, 0)

    camera.draw(box)
    camera.draw(num_coins)
    camera.display()

    if box.touches(lava):
        lives -= 1
        if lives <= 0:
            text3 = gamebox.from_text(camera.x, camera.y, "You died", "Arial",
                                      20, 'black')
            text4 = gamebox.from_text(
                camera.x, camera.y, "You lasted: " + str(ticks // 60) +
                " seconds with " + str(coins_got) + " coins!", "Arial", 20,
                'black')
            text4.top = text3.bottom
            camera.draw(text3)
            camera.draw(text4)
            gamebox.pause()
            camera.display()

    if box.right < camera.left or box.left > camera.right:
        text3 = gamebox.from_text(camera.x, camera.y, "You died", "Arial", 20,
                                  'black')
        text4 = gamebox.from_text(
            camera.x, camera.y, "You lasted: " + str(ticks // 60) +
            " seconds with " + str(coins_got) + " coins!", "Arial", 20,
            'black')
        text4.top = text3.bottom
        camera.draw(text3)
        camera.draw(text4)
        gamebox.pause()
        camera.display()
Beispiel #24
0
def tick(keys):

    global hit_interval, hit_moment, hit_check, health, secretformula_check, stick_check,\
        move_check, x, y, stage, face_check, time, seconds, minutes, jf_stage, check, \
        spat_stage, spat_check, bear_stage, circle_stage, x_coord, level

    hud = [gamebox.from_color(character.x, 0, "White", 100000, 120)]
    hit_interval += 1
    character.xspeed = 0
    character.yspeed += 1
    circle_check = 0
    time += 1
    jf_stage += 1/3
    spat_stage += 1/3
    bear_stage += 1/3
    if circle_stage >= 9:
        circle_stage = 8
    if time == 30:
        seconds += 1
        move_check = 0
    if time == 60:
        check = 0
        time = 0
        seconds += 1
    if seconds == 60:
        seconds = 0
        minutes += 1
    if int(seconds) < 10:
        second = '0{}'.format(str(seconds))
    else:
        second = str(seconds)
    if hit_moment + 30 == hit_interval:
        hit_check = 0
    for jellyfish in jf_list:
        if time < 30:
            jellyfish.yspeed = -2
        else:
            jellyfish.yspeed = 2
        jellyfish.y = jellyfish.y + jellyfish.yspeed
    for bear in bear_list:
        if time < 30:
            bear.speedx = -10
        else:
            bear.speedx = 10
        bear.x = bear.x + bear.speedx
    character.y = character.y + character.yspeed


    # ----- GEN ANIMATION -----
    timer = gamebox.from_text(character.x - 225, y/25, "{}".format(str(int(minutes))) + ":{}".format(second), "haettenschweiler", 40, "Black")
    hud.append(timer)
    tie_hud = gamebox.from_image(character.x + 400, y/20 - 20, "tie_hud.png")
    tie_hud.scale_by(0.8)
    hud.append(tie_hud)
    secretformula_hud_file = 'secretformula_check{}'.format(str(secretformula_check)) + ".png"
    secretformula_hud = gamebox.from_image(character.x - 50, y/20 - 5, secretformula_hud_file)
    hud.append(secretformula_hud)
    health_hud_file = 'health_hud_1.png'
    health_hud_a = gamebox.from_image(character.x + 850, y/20 - 8, health_hud_file)
    health_hud_b = gamebox.from_image(character.x + 925, y/20 - 8, health_hud_file)
    health_hud_c = gamebox.from_image(character.x + 1000, y/20 - 8, health_hud_file)
    if health <= 2:
        health_hud_a = gamebox.from_image(character.x + 850, y/20 - 8, 'health_hud_0.png')
    if health <= 1:
        health_hud_b = gamebox.from_image(character.x + 925, y/20 - 8, 'health_hud_0.png')
    if health <= 0:
        health_hud_c = gamebox.from_image(character.x + 1000, y/20 - 8, 'health_hud_0.png')
    hud.append(health_hud_a)
    hud.append(health_hud_b)
    hud.append(health_hud_c)
    stick_hud_file = "stick_check{}".format(str(stick_check)) + ".png"
    stick_hud= gamebox.from_image(character.x - 150, y/20 - 5, stick_hud_file)
    hud.append(stick_hud)
    spat_hud_file = "spat_check{}".format(str(spat_check))+".png"
    spat_hud = gamebox.from_image(character.x - 100, y/20, spat_hud_file)
    hud.append(spat_hud)
    if stage >= 7:
        stage = 1
    if spat_stage >= 4 or bear_stage >= 4:
        spat_stage = 1
        bear_stage = 1
    if int(jf_stage) == 8:
        jf_stage = 1
    sb = 'running_{}'.format(str(int(stage)))+'.png'
    character_an = gamebox.from_image(character.x, character.y - 10, sb)
    character_an.scale_by(.5)
    jf_file = 'jellyfish_{}'.format(str(int(jf_stage)))+'.png'
    jellyfish_an = []
    secretformula_file = 'secretformula_{}'.format(str(int(spat_stage)))+".png"
    secretformula = gamebox.from_image(7500, 700, secretformula_file)
    spat_file = 'spatula_{}'.format(str(int(spat_stage)))+".png"
    spatula = gamebox.from_image(5100, 100, spat_file)
    stick_file = 'stick_{}'.format(str(int(spat_stage)))+".png"
    stick = gamebox.from_image(2100, 100, stick_file)
    circle = gamebox.from_image(character.x, character.y + 30, 'circle_8.png')
    bear_an = []
    seabear_file = 'seabear_{}'.format(str(int(bear_stage)))+".png"
    # ----- DRAW DISTANCE -----
    for bear in bear_list:
        if character.x + 1123 > bear.x and character.x - 300 < bear.x:
            bear_an.append(gamebox.from_image(bear.x, bear.y, seabear_file))
    for seabear in bear_an:
        if time > 30:
            seabear.flip()
    for jellyfish in jf_list:
        if character.x + 1123 > jellyfish.x and character.x - 300 < jellyfish.x:
            jellyfish_an.append(gamebox.from_image(jellyfish.x, jellyfish.y, jf_file))
    if pygame.K_q in keys:
        quit()
    #  ----- WASD INPUT -----
    if character.touches(ground) and stick_check == 1:
        if pygame.K_c in keys:
            circle_check = 1
        else:
            circle_check = 0
    if global_stage.wasd_count != 0:
        if pygame.K_d in keys and circle_check == 0:
            character.xspeed += 9.5
            character.x += 9.5
            for item in hud:
                item.speedx += 9.5
            if face_check == 1:
                character_an.flip()
                face_check = 0
        if pygame.K_a in keys and circle_check == 0:
            character.speedx -= 9.5
            character.x -= 9.5
            for item in hud:
                item.speedx -= 9.5
            if face_check == 0:
                character_an.flip()
                face_check = 1


        # -----WASD COLLISION -----
        for object in jump_list:
            if character.bottom_touches(object):
                if pygame.K_a not in keys and pygame.K_d not in keys:
                    stage = 1
                if pygame.K_a in keys or pygame.K_d in keys and pygame.K_SPACE not in keys:
                    stage += 1/1.3
                character.yspeed = 0
                character.move_to_stop_overlapping(object)
                if pygame.K_SPACE in keys:
                    stage = 5
                    character.yspeed = -16

    #  ----- ARROW INPUT -----
    if global_stage.wasd_count == 0:
        if pygame.K_RIGHT in keys and circle_check == 0:
            character.xspeed += 95
            character.x += 95
            for item in hud:
                item.speedx += 9.5
            if face_check == 1:
                character_an.flip()
                face_check = 0
        if pygame.K_LEFT in keys and circle_check == 0:
            character.speedx -= 9.5
            character.x -= 9.5
            for item in hud:
                item.speedx -= 9.5
            if face_check == 0:
                character_an.flip()
                face_check = 1


        # ----- ARROW COLLISION -----
        for object in jump_list:
            if character.bottom_touches(object):
                if pygame.K_LEFT not in keys and pygame.K_RIGHT not in keys:
                    stage = 1
                if pygame.K_LEFT in keys or pygame.K_RIGHT in keys and pygame.K_SPACE not in keys:
                    stage += 1/1.3
                character.yspeed = 0
                character.move_to_stop_overlapping(object)
                if pygame.K_SPACE in keys:
                    stage = 5
                    character.yspeed = -16
    for w in wall:
        if character.touches(w):
            character.move_to_stop_overlapping(w)
    if character.touches(spatula) and spat_check == 0:
        spat_check = 1
        not_lame.play()
    if character.touches(stick) and stick_check == 0:
        stick_check = 1
        not_lame.play(0)
    if character.touches(secretformula) and secretformula_check == 0:
        secretformula_check = 1
        not_lame.play(0)
    for platform in platforms:
        if character.bottom_touches(platform):
            if pygame.K_DOWN in keys:
                character.y = character.y + y/10


    # ----- DEATH CHECK -----
    for jellyfish in jf_list:
        if character.bottom_touches(jellyfish):
            stage = 2
        if character.top_touches(jellyfish) and hit_check == 0:
            health -= 1
            hit_check = 1
            hit_moment = hit_interval
    for seabear in bear_an:
        if character.touches(seabear) and hit_check == 0 and circle_check == 0:
            health -= 1
            hit_check = 1
            hit_moment = hit_interval
        if circle_check == 1 and character.touches(seabear):
            health += 0
    if health == 0:
        character_an = gamebox.from_image(character.x, character.y, 'crying.png')
        gamebox.pause()


    # ----- DRAWING -----
    camera.clear("Black")
    for entry in background:
        camera.draw(entry)
    camera.draw(ground)
    camera.draw(house)
    for jellyfish in jellyfish_an:
        camera.draw(jellyfish)
    if secretformula_check == 0:
        camera.draw(secretformula)
    if stick_check == 0:
        camera.draw(stick)
    if spat_check == 0:
        camera.draw(spatula)
    for seabear in bear_an:
        camera.draw(seabear)
    if face_check == 1:
        character_an.flip()
    if circle_check == 1:
        camera.draw(circle)
    camera.draw(character_an)
    for entry in hud:
        camera.draw(entry)
    for platform in platforms:
        if character.x + 1300 > platform.x and character.x - 400 < platform.x:
            camera.draw(platform)
    camera.move(character.speedx, 0)
    if health == 0:
        x_coord = character.x
    if stick_check == 1 and spat_check == 1 and secretformula_check == 1 and character.x >= 9400:
        camera.draw(gamebox.from_image(9750, 400,"continue.png"))
        level = 2
    camera.display()
    health = 3
    spat_check = 1
    secretformula_check = 1
    stick_check = 1
Beispiel #25
0
def tick(keys):

    global score
    global sprite_counter

    # move player
    if pygame.K_LEFT in keys:
        player.x -= 10

    if pygame.K_RIGHT in keys:
        player.x += 10

    # shooting bullets
    if pygame.K_SPACE in keys and bullet1.yspeed == 0:
        shoot_bullet(bullet1)
        bullet_sound.play()

    elif pygame.K_SPACE in keys and bullet2.yspeed == 0:
        shoot_bullet(bullet2)
        bullet_sound.play()

    elif pygame.K_SPACE in keys and bullet3.yspeed == 0:
        shoot_bullet(bullet3)
        bullet_sound.play()

    if pygame.K_SPACE in keys:
        keys.remove(pygame.K_SPACE)

    # moving bullets
    bullet1.y -= bullet1.speedy
    bullet2.y -= bullet2.speedy
    bullet3.y -= bullet3.speedy

    # stop bullet off screen
    if bullet1.y < 0:
        bullet1.speedy = 0
    if bullet2.y < 0:
        bullet2.speedy = 0
    if bullet3.y < 0:
        bullet3.speedy = 0

    # create enemies if there aren't any
    while len(enemies) < 3:
        enemies.append(create_enemy())

    # move the enemies
    for enemy in enemies:
        enemy.x += enemy.xspeed

    # reverse enemies if necessary
    for enemy in enemies:
        if enemy.x < 0:
            enemy.xspeed *= -1
        elif enemy.x > 800:
            enemy.xspeed *= -1

    # kill enemies with bullets
    for enemy in enemies:
        for bullet in bullets:
            if enemy.touches(bullet):
                enemy.x = random.randint(0, 800)
                enemy.y = random.randint(0, 2) * 75 + 50
                enemy.xspeed = random.randint(3, 10)
                score += 1
                enemy_explosion_sound.play(fade_ms=100)

    # enemy shoots bullets
    for i in range(len(en_bullets)):
        if en_bullets[i].yspeed == 0:
            enemy_shoot_bullet(enemies[i], en_bullets[i])

    # enemy bullets move
    for bullet in en_bullets:
        bullet.y += bullet.yspeed

    # handle bullets going off the screen
    for bullet in en_bullets:
        if bullet.y > 600:
            bullet.yspeed = 0

    # update the score
    score_display = gamebox.from_text(750, 10, str(score), "Algerian", 12,
                                      "yellow")

    # handle animations
    sprite_counter += 1
    if sprite_counter == 6:
        sprite_counter = 0

    player.image = player_animations[sprite_counter]
    for enemy in enemies:
        enemy.image = enemy_animations[sprite_counter]

    # play music
    music_player

    # draw everything
    camera.clear("black")
    camera.draw(player)
    camera.draw(bullet1)
    camera.draw(bullet2)
    camera.draw(bullet3)
    camera.draw(score_display)

    if lives[0] == True:
        camera.draw(life3)
    if lives[1] == True:
        camera.draw(life2)
    if lives[2] == True:
        camera.draw(life1)

    for bullet in en_bullets:
        camera.draw(bullet)

    for enemy in enemies:
        camera.draw(enemy)

    # game over
    for bullet in en_bullets:
        if bullet.touches(player):
            lose_health()
            bullet.yspeed = 0
            lose_life_sound.play()

    if lives[2] == False:
        camera.draw(game_over_background)
        game_over_score = gamebox.from_text(400, 300,
                                            "Final Score: " + str(score),
                                            "Algerian", 20, "yellow")
        camera.draw(game_over_score)
        death_sound.play()
        music_player.pause()
        gamebox.pause()

    camera.display()
Beispiel #26
0
def tick(keys):

    global score

    # move player
    if pygame.K_LEFT in keys:
        player.x -= 10

    if pygame.K_RIGHT in keys:
        player.x += 10

    # shooting bullets
    if pygame.K_SPACE in keys and bullet1.yspeed == 0:
        shoot_bullet(bullet1)

    elif pygame.K_SPACE in keys and bullet2.yspeed == 0:
        shoot_bullet(bullet2)

    elif pygame.K_SPACE in keys and bullet3.yspeed == 0:
        shoot_bullet(bullet3)

    if pygame.K_SPACE in keys:
        keys.remove(pygame.K_SPACE)

    # moving bullets
    bullet1.y -= bullet1.speedy
    bullet2.y -= bullet2.speedy
    bullet3.y -= bullet3.speedy

    # stop bullet off screen
    if bullet1.y < 0:
        bullet1.speedy = 0
    if bullet2.y < 0:
        bullet2.speedy = 0
    if bullet3.y < 0:
        bullet3.speedy = 0

    # create enemies if there aren't any
    while len(enemies) < 3:
        enemies.append(create_enemy())

    # move the enemies
    for enemy in enemies:
        enemy.x += enemy.xspeed

    # reverse enemies if necessary
    for enemy in enemies:
        if enemy.x < 0:
            enemy.xspeed *= -1
        elif enemy.x > 800:
            enemy.xspeed *= -1

    # kill enemies with bullets
    for enemy in enemies:
        for bullet in bullets:
            if enemy.touches(bullet):
                enemy.x = random.randint(0, 800)
                enemy.y = random.randint(0,2) * 75 + 50
                enemy.xspeed = random.randint(3, 10)
                score += 1

    # enemy shoots bullets
    for i in range(len(en_bullets)):
        if en_bullets[i].yspeed == 0:
            enemy_shoot_bullet(enemies[i], en_bullets[i])

    # enemy bullets move
    for bullet in en_bullets:
        bullet.y += bullet.yspeed

    # handle bullets going off the screen
    for bullet in en_bullets:
        if bullet.y > 600:
            bullet.yspeed = 0

    # update the score
    score_display = gamebox.from_text(750, 10, str(score), "Arial", 12, "yellow")

    # check for lives


    # draw everything
    camera.clear("black")
    camera.draw(player)
    camera.draw(bullet1)
    camera.draw(bullet2)
    camera.draw(bullet3)
    camera.draw(score_display)

    for bullet in en_bullets:
        camera.draw(bullet)

    for enemy in enemies:
        camera.draw(enemy)

    # game over
    for bullet in en_bullets:
        if bullet.touches(player):
            camera.draw(game_over_background)
            game_over_score = gamebox.from_text(400, 300, "Final Score: " + str(score), "Arial", 20, "yellow")
            camera.draw(game_over_score)
            gamebox.pause()

    camera.display()
Beispiel #27
0
def tick(keys):
    global jump_sheet, player, grav_counter, platforms, plat_counter, start_game, start_screen, time, can_move
    global controls, enemy, enemy_live, spike, spike_counter

    # Grey display
    camera.clear('grey')

    # Checks whether game has started
    if start_game is False:
        camera.draw(start_screen)
        camera.draw(controls)
        camera.display()

        if pygame.K_SPACE in keys:
            start_game = True

    if start_game is True:

        time += 1

        spike_counter += 1
        # Gravity

        if grav_counter <= 30:
            grav_counter += 2
            player.speedy += 5
        else:
            grav_counter = 0

        # jump animation
        if player.speedy == -15:
            player.image = jump_sheet[2]
        elif player.speedy == 15:
            player.image = jump_sheet[1]

        # Jumps when space bar is pressed
        if pygame.K_SPACE in keys and can_move is True:
            spike_counter = 0
            player.speedy = -30
            y_location = 500 + random.randrange(-18, 18, 3)
            player.image = jump_sheet[1]
            for platform in platforms:
                platform.x -= 100
            # platforms.append(gamebox.from_color(900, 500 + random.randrange(-18, 18, 3), (0, 153, 76), 100, 30))
            platforms.append(
                gamebox.from_color(900, y_location, (0, 153, 76), 100, 30))
            enemy_live = random.randrange(0, 100)
            for i in enemy:
                i.x -= 100
            if enemy_live > 70:
                enemy.append(
                    gamebox.from_image(900, y_location - 40,
                                       'game-assets/enemy.png'))
            can_move = False
            keys.clear()

        # Stops player on platform, and makes sure only one jump can happen until platform is touched
        if player.touches(platforms[2]):
            player.bottom = platforms[2].top
            player.speedy = 0
            player.image = jump_sheet[0]
            can_move = True

        if player.touches(enemy[0]):
            end_game = gamebox.from_text(390, 250, 'YOU DEAD', 69, 'black')
            camera.draw(end_game)
            camera.display()
            gamebox.pause()

        # Player is moving
        player.move_speed()

        # Removes platform after it gets off the screen
        if platforms[0].x <= -100:
            platforms.remove(platforms[0])

        # All platforms are moving and drawn
        for platform in platforms:
            # platform.move_speed()
            camera.draw(platform)

        for i in enemy:
            camera.draw(i)

        camera.draw(spike)

        if spike_counter >= 60:
            spike.speedy = 20
            spike.move_speed()

        if player.touches(spike):
            end_game = gamebox.from_text(390, 250, 'YOU DEAD', 69, 'black')
            camera.draw(end_game)
            camera.display()
            gamebox.pause()

        # Sets time and scoreboard
        seconds = str(int((time / ticks_per_second)))
        score_display = gamebox.from_text(100, 50, "Score: " + seconds, 30,
                                          "black")
        camera.draw(score_display)

        camera.draw(player)
        camera.display()
Beispiel #28
0
def tick(keys):
    global time
    global game_on
    global g_on
    global score
    global win
    global ticks
    global animationLog
    global done
    ticks += 1
    camera.clear('black')
    starry_background()
    if game_on == False:
        splashscreen1dummy.image = splashscreen1[(ticks // 3) %
                                                 len(splashscreen1)]
        camera.draw(splashscreen1dummy)
        camera.display()
        if pygame.K_SPACE in keys:
            camera.clear('black')
            game_on = True
    elif game_on:
        splashscreen2dummy.image = splashscreen2[(ticks // 3) %
                                                 len(splashscreen2)]
        camera.draw(splashscreen2dummy)
        camera.display()
        if pygame.K_UP in keys:
            g_on = True
            game_on = None

    if g_on:
        global COUNTER
        global SHIPSHEETCOUNT
        if done:
            time += 1
        else:
            time = 0
        COUNTER += 1
        camera.clear("black")
        starry_background()
        camera.draw(leftside)
        camera.draw(rightside)
        if spaceship.touches(rightside) or spaceship.touches(
                leftside):  # keeping the player on the screen
            spaceship.move_to_stop_overlapping(leftside)
            spaceship.move_to_stop_overlapping(rightside)

        if done:
            asteroidGenerate()

        healthbar()
        if time % 50 == 0 and done == True:
            score += 10

        score_box = gamebox.from_text(100, 60, "Score: " + str(score), "arial",
                                      24, "white")
        camera.draw(score_box)
        seconds = str(int((time / ticks_per_second))).zfill(3)
        time_box = gamebox.from_text(100, 30, "Time: " + seconds, "arial", 24,
                                     "white")
        camera.draw(time_box)
        # end of timer change
        # banking animation
        if COUNTER % 15 == 0:  # keeps the frame rate a bit lower so the animation is slightly more visible; still tough with motion blur
            if SHIPSHEETCOUNT > 5:
                SHIPSHEETCOUNT -= 1  # the ship drifts back towards the no turn position over time unless you tell it not to.
            elif SHIPSHEETCOUNT < 5:
                SHIPSHEETCOUNT += 1
            if pygame.K_RIGHT in keys:
                if SHIPSHEETCOUNT > 5:
                    SHIPSHEETCOUNT += 2  # bank right
            if pygame.K_LEFT in keys:
                if SHIPSHEETCOUNT < 5:
                    SHIPSHEETCOUNT -= 2  # bank left
        if pygame.K_RIGHT in keys:
            spaceship.x += 15  # movement
        if pygame.K_LEFT in keys:
            spaceship.x -= 15
            spaceship.image = friendly_sheet[SHIPSHEETCOUNT]
        animationLog.append(
            SHIPSHEETCOUNT)  # allows enemy to know where to go and how to turn
        positionLog.append(spaceship.x)
        camera.draw(spaceship)
        enemyAI()  # he's coming for you
        if done:
            camera.draw(enemy)
            if (bullet.y <= -10 or spaceship.x == enemy.x) and time >= 30:
                if COUNTER % 40 == 0:  # bullet delay
                    bullet.y = enemy.y
                    bullet.x = enemy.x
                    camera.draw(bullet)
        if time >= 30:
            bullet.y = bullet.y - bullet.yspeed
            camera.draw(bullet)
        camera.display()
        if bullet.top_touches(spaceship) or bullet.touches(spaceship):
            bullet.y = -20
            if health1.x == hx:
                health1.x = 1000
            elif health2.x == hx + 20:
                health2.x = 1020
            elif health3.x == hx + 40:
                health3.x = 1040
            elif health4.x == hx + 60:
                health4.x = 1060

        if health4.x == 1060:
            writeScore(
                score)  # logs the result of your game to your hard drive
            high_score = readScore(
            )  # finds max score in the text file that was created.
            high_score = gamebox.from_text(Width / 2, Length - 2 * Length / 3,
                                           "High Score: " + high_score,
                                           "arial", 35, "Yellow")
            current_score = gamebox.from_text(Width / 2, Length - Length / 3,
                                              "Score: " + str(score), "arial",
                                              40, "Yellow")
            camera.draw(current_score)
            camera.draw(high_score)
            camera.draw(gameOVER)
            gamebox.pause()
    camera.display()
Beispiel #29
0
def tick(keys):
    global score
    global cash
    global wave
    global wave_started
    global tank_count
    global tick_count
    global ticks_per_second
    global timer
    global T
    
    # Count Tick
    if not wave_started:
        tick_count += 1
        if tick_count % ticks_per_second == 0:
            tick_count = 0
            timer -= 1
            
        if timer <= 0:
            enemy_tanks.extend(generate_tanks(tank_count, 600, 800, 0, 600))
            wave_started = True
            
    
    # Draw Objects
    camera.clear("black")
    camera.draw(background)
    
    camera.draw(king)
    
    # Remove Dead Bullets
    for bullet in bullets:
        if not bullet.alive:
            bullets.remove(bullet)
    
    # Move Bullets 
    for bullet in bullets:
        bullet.tick()
        if bullet.touches(king):
            print("King Killed")
            gamebox.pause()
        camera.draw(bullet)
    
    # Check Barriers
    for barrier in barriers:
        barrier.check(bullets)
        barrier.draw(camera)
        
        for etank in enemy_tanks:
            barrier.check_collision(etank)
    
    # Draw Mines
    for mine in mines:
        camera.draw(mine)
    
    kills = 0
    for tank in enemy_tanks:
        if (tank.y > king.y):
            if (tank.facing > 180 - 45):
                tank.turn_right()
        else:
            if (tank.facing < 180 + 45):
                tank.turn_left()
        
        for mine in mines:
            if not mine.live:
                mines.remove(mine)
            elif tank.touches(mine):
                boom = mine.explode()
                booms.append(boom)
        
        for boom in booms:
            if tank.touches(boom):
                if tank in enemy_tanks:
                    enemy_tanks.remove(tank)
                    kills += 1
                    
    cash += int(TANK_VALUE * (kills**2))
    
    for etank in enemy_tanks:

        etank.forward() 
        etank.tick()
        
        bullet = etank.fire_bullet()
        if bullet:
            bullets.append(bullet)
        camera.draw(etank)
    
    # Draw Booms 
    for boom in booms:
        boom.tick()
        camera.draw(boom)
        if not boom.alive:
            booms.remove(boom)
        
    for b in buttons:
        b.draw(camera)
        
    # Buttons
    if camera.mouseclick:
        
        if button_state_machine.has_state():
            s = button_state_machine.state
            mx, my = camera.mousex, camera.mousey
            if s == "BARRIER":
                if cash >= tankstuff.Barrier.price:
                    cash -= tankstuff.Barrier.price
                    barriers.append(tankstuff.Barrier(mx, my, 2, 4))
            elif s == "TURRET":
                pass
            elif s == "MINE":
                # Mine cannot be place touching another mine
                if cash >= tankstuff.Mine.price:
                    new_mine = tankstuff.Mine(mx, my)
                    touching = False
                    for mine in mines:
                        if new_mine.touches(mine):
                            touching = True
                            break
                    if not touching:
                        cash -= tankstuff.Mine.price
                        mines.append(new_mine)
                    
            print(button_state_machine.state)
            button_state_machine.clear_state()
        
        else:
            for b in buttons:
                
                if b.clicked(camera):
                    if b.text == "START":
                        if timer > 0 and not wave_started:
                            timer = 0
                    else:
                        button_state_machine.set_state(b.text)
    
    if not button_state_machine.has_state():
        if pygame.K_m in keys:
            button_state_machine.set_state("MINE")
            
        elif pygame.K_b in keys:
            button_state_machine.set_state("BARRIER")
            
        elif pygame.K_k in keys:
            button_state_machine.set_state("TURRET")
    
    # Wave Compleated
    if len(enemy_tanks) == 0 and wave_started:
        wave += 1
        tank_count += 1
        score += cash
        timer = PRE_WAVE_TIME
        wave_started = False
    
    if button_state_machine.has_state():
        placing_info = gamebox.from_text(650, 10, "PLACING: " + button_state_machine.state, "arial", 
                                         25, "white", True)
        camera.draw(placing_info)
     
    score_text = gamebox.from_text(700, 575, "SCORE: " + str(score), "arial", 20, "white", bold = True)
    cash_text = gamebox.from_text(700, 555, "CASH: " + str(cash), "arial", 20, "white", bold = True)
    wave_text = gamebox.from_text(50, 10, "WAVE: " +  str(wave), "arial", 20, "white", bold = True)
    wave_timer = gamebox.from_text(400, 25, str(timer) if timer != 0 else "WAVE START!", "arial", 40, "white", bold = True)
    camera.draw(score_text)
    camera.draw(cash_text)
    camera.draw(wave_text)
    camera.draw(wave_timer)
    
    # Display
    camera.display()
Beispiel #30
0
def game(keys):
    """
    This function runs the game
    :param keys: Takes input keys as a parameter
    :return: N/A
    """
    global game_on
    global time_left
    global player1_HP
    global player2_HP
    global x
    global y
    global rounds
    global dead
    global press_space
    global p1wins
    global p2wins
    timer = gamebox.from_text(400, 50, ("Time Left: " + str(int(time_left))), 20, "black")
    p1healthbox = gamebox.from_color(80, 50, "red", (int(player1_HP)), 20)
    p2healthbox = gamebox.from_color(720, 50, "red", (int(player2_HP)), 20)
    p1rounds = gamebox.from_text(120, 30, ("Health: (Below)   " + "Rounds Won: " + str(p1wins)), 20, "black")
    p2rounds = gamebox.from_text(680, 30, ("Rounds Won: " + str(p2wins)) + "   Health: (Below)", 20, "black")
    # print(rounds)
    if not rounds:


        camera.clear('white')
        time_left -= 1/30

        if bulletp1.x == p1.x:
            bulletp1.y = p1.y
        if bulletp2.x == p2.x:
            bulletp2.y = p2.y

        # player 2 movement
        for bullet in bullets:
            bullet.move_speed()

        if pygame.K_UP in keys:
            p2.y -= 10
        if pygame.K_DOWN in keys:
            p2.y += 10

        if y == 0:
            if pygame.K_LEFT in keys: #bullet timer and movement
                bulletp2.speedx = -50
                bulletp2.x += bulletp2.speedx
                y = 1
        if y > 0:
            y -= 1/10
        if y < 0:
            y = 0

        # players 1 movement
        if pygame.K_s in keys:
            p1.y += 10
        if pygame.K_w in keys:
            p1.y -= 10

        if x == 0:
            if pygame.K_d in keys: #bullet timer and movement
                bulletp1.speedx = 50
                bulletp1.x += bulletp1.speedx
                x = 1
        if x > 0:
            x -= 1/10
        if x < 0:
            x = 0

        for brick in bricks:
            if bulletp1.touches(brick):
                bulletp1.x = p1.x
                bulletp1.y = p1.y
                bulletp1.speedx = 0
            elif bulletp1.touches(p2): #need to make health go down
                player2_HP -= 20
                bulletp1.x = p1.x
                bulletp1.y = p1.y
                bulletp1.speedx = 0
            elif bulletp1.x > 800:
                bulletp1.x = p1.x
                bulletp1.y = p1.y
                bulletp1.speedx = 0

            if bulletp2.touches(brick):
                bulletp2.x = p2.x
                bulletp2.y = p2.y
                bulletp2.speedx = 0
            elif bulletp2.touches(p1): #need to make health go down
                player1_HP -= 20
                bulletp2.x = p2.x
                bulletp2.y = p2.y
                bulletp2.speedx = 0
            elif bulletp2.x < 0:
                bulletp2.x = p2.x
                bulletp2.y = p2.y
                bulletp2.speedx = 0



        # if pygame.K_w in keys:
        for box in game_boxes:
            camera.draw(box)

        p1.move_to_stop_overlapping(topwall)
        p1.move_to_stop_overlapping(bottomwall)
        p2.move_to_stop_overlapping(topwall)
        p2.move_to_stop_overlapping(bottomwall)

        for brick in bricks:
            brick.speedy = 7
            if brick.y > 600:
                brick.y = -1
            camera.draw(brick)

        for brick in bricks:
            brick.y += brick.speedy

        #medkit consumable
        if int(time_left) % 8 == 0 and medkits == []:
            newyvalue = random.randrange(100,500)
            medx = [300, 500]
            newmedkit = gamebox.from_image(random.choice(medx), newyvalue, "medkit.png")
            newmedkit.scale_by(0.1)
            medkits.append(newmedkit)

        for medkit in medkits:
            camera.draw(medkit)

        for medkit in medkits:
            if bulletp1.touches(medkit):
                bulletp1.x = p1.x
                bulletp1.y = p1.y
                bulletp1.speedx = 0
                medkits.remove(medkit)
                player1_HP += 40
                if player1_HP > 100:
                    player1_HP = 100
            elif bulletp2.touches(medkit):
                bulletp2.x = p2.x
                bulletp2.y = p2.y
                bulletp2.speedx = 0
                medkits.remove(medkit)
                player2_HP += 40
                if player2_HP > 100:
                    player2_HP = 100

        if player1_HP == 0:
           # gamebox.pause()
            time_left = 60
            player1_HP = 100
            player2_HP = 100
            p2wins += 1
            rounds = True
           # p1lose = gamebox.from_text(400, 300, "Player 2 wins!", 100, "black")
           # camera.draw(p1lose)
            dead = "Player 2 Wins!"
            press_space = "Press space for next round"

            if game_on ==1:
                game_boxes.remove(desert)
                game_boxes.append(grass)


               # gamebox.unpause()
            elif game_on == 2:
                game_boxes.append(tundra)
            game_on +=1


        if player2_HP == 0:
            time_left = 60
            player1_HP = 100
            player2_HP = 100
            p1wins += 1
           # game_boxes.remove(desert)
           # gamebox.pause()
            rounds = True
            dead = "Player 1 Wins!"
            press_space = "Press space for next round"
           # gamebox.unpause()

            if game_on ==1:
                game_boxes.append(grass)
            elif game_on == 2:
                game_boxes.append(tundra)

            game_on += 1





        if time_left < 0:
            time_left = 0


        if time_left == 0:
            gamebox.pause()
            winner = random.randrange(0, 2)
            if winner == 0:
                winner = "Player 1 "
            elif winner == 1:
                winner = "Player 2 "
            time_out = gamebox.from_text(400, 300, winner + "wins!", 100, "black")
            describe = gamebox.from_text(400, 200, "Time out: The winner will be randomly determined!", 25, "black")
            camera.draw(time_out)
            camera.draw(describe)
            if game_on == 1:
                game_on += 1
    else:
        if pygame.K_SPACE in keys:
            rounds = False
        for box in game_boxes:
            camera.draw(box)
        if game_on == 4:
            dead = "Game Over!"
            press_space = "Hope You had Fun"
        p2lose = gamebox.from_text(400, 300, dead, 100, "black")
        camera.draw(p2lose)
        newround = gamebox.from_text(400, 400, press_space, 60, "black")
        camera.draw(newround)

    camera.draw(p1rounds)
    camera.draw(p2rounds)
    camera.draw(p1healthbox)
    camera.draw(p2healthbox)
    camera.draw(timer)
    camera.draw(bulletp1)
    camera.draw(bulletp2)
    camera.draw(p1)
    camera.draw(p2)
Beispiel #31
0
 def end():
     gamebox.pause()
     camera.clear("skyblue")
     camera.draw(game_over)
     camera.display()
Beispiel #32
0
def tick(keys):
    global s_frame_run
    global s_frame_idle
    global s_frame_fall
    global p_frame_run
    global p_frame_idle
    global p_frame_fall
    global counter
    global game_on
    global character_select
    global map_one
    global map_two
    global character_select_sonic
    global character_select_pikachu
    global coin_frame
    global timer
    global coin_gone
    global timer_run
    global score_time

    if not game_on:
        title = gamebox.from_text(400, 50, 'The Sonic and Pikachu ', 70,
                                  'pink')
        title2 = gamebox.from_text(400, 110,
                                   "Tremondousnessly Ultimately Cool", 60,
                                   'pink')
        title3 = gamebox.from_text(400, 175,
                                   "Gameplayer's Gigantic Gallopalooza", 60,
                                   'pink')
        names = gamebox.from_text(
            400, 250, "By Qasim Ali (qha4bh) and Jackson Wolf (jtw3vhz)", 40,
            'yellow')
        instructions = gamebox.from_text(
            400, 300,
            "The arrow keys are the only input required to play this game", 30,
            'purple')
        instructions2 = gamebox.from_text(
            400, 325, "Using your mouse, Choose a map and then a character.",
            30, 'purple')
        camera.draw(title), camera.draw(title2), camera.draw(title3),
        camera.draw(names), camera.draw(instructions), camera.draw(
            instructions2)
        if not character_select:
            if camera.mouseclick and 130 < camera.mousex < 270 and 360 < camera.mousey < 440:
                character_select = True
                map_one[1] = True
            if camera.mouseclick and 530 < camera.mousex < 670 and 360 < camera.mousey < 440:
                character_select = True
                map_two[1] = True

            camera.draw(map_one[0]), camera.draw(map_two[0])
            camera.display()

        if character_select:
            if camera.mouseclick and 300 < camera.mousex < 380 and 450 < camera.mousey < 600:
                game_on = True
                character_select_sonic[1] = True
            if camera.mouseclick and 420 < camera.mousex < 520 and 450 < camera.mousey < 600:
                game_on = True
                character_select_pikachu[1] = True

            camera.draw(character_select_sonic[0]), camera.draw(
                character_select_pikachu[0])
            camera.display()

    if map_one[1]:
        platformlist = map_one_platformlist
    if map_two[1]:
        platformlist = map_two_platformlist

    if game_on:
        for platform in platformlist:
            #sonic stuff
            if sonic.bottom_touches(platform):
                sonic.move_to_stop_overlapping(platform)
                sonic.yspeed = 0
                if pygame.K_RIGHT in keys:
                    sonic.xspeed = 5
                    sonic.move_speed()
                    if s_frame_run >= number_of_frames_run or s_frame_run < 0:
                        s_frame_run = 0
                    if counter % 3 == 0:
                        sonic.image = sonic_run_sheet[s_frame_run]
                    s_frame_run += 1
                    s_input_list.append(1)
                    s_input_list.reverse()
                    if pygame.K_UP in keys:
                        sonic.image = sonic_jump_sheet[2]
                        sonic.yspeed = -20
                elif pygame.K_LEFT in keys:
                    sonic.xspeed = -5
                    sonic.move_speed()
                    if s_frame_run <= 0 or s_frame_run > 15:
                        s_frame_run = 15
                    if counter % 3 == 0:
                        sonic.image = sonic_run_sheet_left[s_frame_run]
                    s_frame_run -= 1
                    s_input_list.append(0)
                    s_input_list.reverse()
                    if pygame.K_UP in keys:
                        sonic.image = sonic_jump_sheet_left[0]
                        sonic.yspeed = -20
                elif pygame.K_UP in keys:
                    if s_input_list.index(1) == 0:
                        sonic.image = sonic_jump_sheet[2]
                        sonic.yspeed = -20
                    else:
                        sonic.image = sonic_jump_sheet_left[0]
                        sonic.yspeed = -20
                elif s_input_list.index(1) == 0:
                    sonic.image = sonic_idle_sheet[0]
                    sonic.xspeed = 0
                else:
                    sonic.image = sonic_idle_sheet_left[0]
                    sonic.xspeed = 0
            #pikachu stuff
            if pikachu.bottom_touches(platform):
                pikachu.move_to_stop_overlapping(platform)
                pikachu.yspeed = 0
                if pygame.K_RIGHT in keys:
                    pikachu.xspeed = 5
                    pikachu.move_speed()
                    if p_frame_run >= 4 or p_frame_run < 0:
                        p_frame_run = 0
                    if counter % 5 == 0:
                        pikachu.image = pikachu_run[p_frame_run]
                    p_frame_run += 1
                    p_input_list.append(1)
                    p_input_list.reverse()
                    if pygame.K_UP in keys:
                        pikachu.image = pikachu_in_air_sheet[0]
                        pikachu.yspeed = -20
                elif pygame.K_LEFT in keys:
                    pikachu.xspeed = -5
                    pikachu.move_speed()
                    if p_frame_run <= 0 or p_frame_run > 3:
                        p_frame_run = 3
                    if counter % 5 == 0:
                        pikachu.image = pikachu_run_left[p_frame_run]
                    p_frame_run -= 1
                    p_input_list.append(0)
                    p_input_list.reverse()
                    if pygame.K_UP in keys:
                        pikachu.image = pikachu_in_air_sheet_left[3]
                        pikachu.yspeed = -20
                elif pygame.K_UP in keys:
                    if p_input_list.index(1) == 0:
                        pikachu.image = pikachu_in_air_sheet[0]
                        pikachu.yspeed = -20
                    else:
                        pikachu.image = pikachu_in_air_sheet_left[3]
                        pikachu.yspeed = -20
                elif p_input_list.index(1) == 0:
                    pikachu.image = pikachu_idle_sheet[0]
                    pikachu.xspeed = 0
                else:
                    pikachu.image = pikachu_idle_sheet_left[0]
                    pikachu.xspeed = 0
        #sonic air
        if sonic.yspeed < 0:
            if s_input_list.index(1) == 0:
                sonic.image = sonic_in_air_sheet[0]
            else:
                sonic.image = sonic_in_air_sheet_left[0]
            if pygame.K_LEFT in keys:
                sonic.xspeed = -5
            if pygame.K_RIGHT in keys:
                sonic.xspeed = 5

        if sonic.yspeed > 0:
            if s_frame_fall == number_of_frames_fall:
                s_frame_fall = 0
            if counter % 3 == 0:
                sonic.image = sonic_fall[s_frame_fall]
            s_frame_fall += 1
            if pygame.K_LEFT in keys:
                sonic.xspeed = -5
            if pygame.K_RIGHT in keys:
                sonic.xspeed = 5

        #pikachu air
        if pikachu.yspeed < 0:
            if p_input_list.index(1) == 0:
                pikachu.image = pikachu_in_air_sheet[0]
            else:
                pikachu.image = pikachu_in_air_sheet_left[3]
            if pygame.K_LEFT in keys:
                pikachu.xspeed = -5
            if pygame.K_RIGHT in keys:
                pikachu.xspeed = 5
        if pikachu.yspeed > 0:
            if p_frame_fall == 4:
                p_frame_fall = 0
            if counter % 3 == 0:
                pikachu.image = pikachu_in_air_sheet[p_frame_fall]
            p_frame_fall += 1
            if pygame.K_LEFT in keys:
                pikachu.xspeed = -5
            if pygame.K_RIGHT in keys:
                pikachu.xspeed = 5

        if character_select_sonic[1]:
            camera.x = sonic.x
            camera.y = sonic.y
        if character_select_pikachu[1]:
            camera.x = pikachu.x
            camera.y = pikachu.y

        if counter % 5 == 0:
            coin.image = coin_sheet[coin_frame]
            coin2.image = coin_sheet[coin_frame]
            coin_frame += 1
        if coin_frame > 5:
            coin_frame = 0
        if sonic.touches(coin) or pikachu.touches(coin):
            coin_gone = True
        if sonic.touches(coin2) or pikachu.touches(coin2):
            coin_gone = True

        if sonic.touches(flag) or pikachu.touches(flag):
            timer_run = False
            score_time = True

            score = timer
            if coin_gone:
                score = timer + 25
        if sonic.touches(flag2) or pikachu.touches(flag2):
            timer_run = False
            score_time = True

            score = timer
            if coin_gone:
                score = timer + 25

        counter += 1
        if timer_run:
            if counter % 60 == 0:
                timer -= 1
        if character_select_sonic[1]:
            timer_image = gamebox.from_text(sonic.x + 300, sonic.y - 250,
                                            str(timer), 40, 'black')
        if character_select_pikachu[1]:
            timer_image = gamebox.from_text(pikachu.x + 300, pikachu.y - 250,
                                            str(timer), 40, 'black')

        camera.clear('cyan')
        if character_select_sonic[1]:
            camera.draw(sonic)
        if character_select_pikachu[1]:
            camera.draw(pikachu)

        if map_one[1]:
            camera.draw(flag)
        if map_two[1]:
            camera.draw(flag2)

        if not coin_gone:
            if map_one[1]:
                camera.draw(coin)
            if map_two[1]:
                camera.draw(coin2)

        for platform in platformlist:
            camera.draw(platform)
            if sonic.right_touches(platform) or sonic.left_touches(platform):
                sonic.move_to_stop_overlapping(platform)
            if pikachu.right_touches(platform) or sonic.left_touches(platform):
                pikachu.move_to_stop_overlapping(platform)
            if sonic.top_touches(platform):
                sonic.yspeed = 0
            if pikachu.top_touches(platform):
                pikachu.yspeed = 0
        if score_time:
            if character_select_sonic[1]:
                score_back = gamebox.from_color(sonic.x, sonic.y, 'white', 325,
                                                225)
                camera.draw(score_back)
                end_text = gamebox.from_text(sonic.x, sonic.y + 50,
                                             'press ESC to quit', 40, 'black')
                score_show = gamebox.from_text(sonic.x, sonic.y,
                                               "Score: " + str(score), 60,
                                               'black')
                camera.draw(end_text)
                camera.draw(score_show)
                gamebox.pause()
            if character_select_pikachu[1]:
                score_back = gamebox.from_color(pikachu.x, pikachu.y, 'white',
                                                325, 225)
                camera.draw(score_back)
                end_text = gamebox.from_text(pikachu.x, pikachu.y + 50,
                                             'press ESC to quit', 40, 'black')
                score_show = gamebox.from_text(pikachu.x, pikachu.y,
                                               "Score: " + str(score), 60,
                                               'black')
                camera.draw(end_text)
                camera.draw(score_show)
                gamebox.pause()

        camera.draw(timer_image)
        pikachu.yspeed += 1
        sonic.yspeed += 1
        sonic.move_speed()
        pikachu.move_speed()
        camera.display()
Beispiel #33
0
def tick(keys):

    global game_on
    global p1_score
    global p2_score

    # --- BALL MOVEMENT ---
    # We use the game_on boolean variable to determine
    # if we should be moving the ball or not at this time
    # because we want it to stay still before the game
    # starts.  Add code to move the ball according to
    # the ball speed if game_on is True.
    # i.e. if game_on:
    #         your code here to move ball

    # ------- INPUT ---------
    if pygame.K_SPACE in keys:
        game_on = True
        if pygame.K_Up:
            p2.move(0, -50)
        if pygame.K_DOWN:
            p2.move(0, 40)


#could not figure this one out :(

# We want the game to start when the space bar
# is pressed.  Add the rest of the code here to
# control paddle movement.  We suggest W and S
# for the red (left) player and Up and Down for
# the yellow (right) player.  Note that there
# is a player_speed variable you can use.

# ----- COLLISION DETECTION -----
# First, handle collisions between all of the
# walls and the ball.  If the ball touches any
# wall, reverse the yspeed of the ball and play
# the wall sound.
# Next, handle collisions between the paddles
# and the ball.  If the ball touches either paddle,
# reverse its xspeed and play the paddle sound.
# These are very simplistic rules for bounces.
# Basically, every bounce will be 45 degrees. If
# you want to do more, go ahead, but it's not
# required.

# ----- SCORING ------
# When the ball's x coordinate goes off the screen,
# you need to add 1 to the appropriate player's
# score, move the ball back to the middle of the
# screen, and set game_on to False.  You will
# probably have two if statements here - one for
# if the ball goes off on the left and one if
# it goes off on the right.

# ----- DRAW METHODS --------
# We have provided all of the draw methods for you.
# You do not need to add anything here.
    camera.clear("black")
    camera.draw(
        gamebox.from_text(300, 50, str(p1_score), "Arial", 50, "Red", True))
    camera.draw(
        gamebox.from_text(500, 50, str(p2_score), "Arial", 50, "Yellow", True))

    # Draw all the walls
    for wall in walls:
        camera.draw(wall)

    # Draw the player paddles and the ball
    camera.draw(p1)
    camera.draw(p2)
    camera.draw(ball)

    # ---- CHECKING FOR WIN ----
    if p1_score >= 10:
        camera.draw(
            gamebox.from_text(400, 100, "Red Wins!", "Arial", 40, "Red", True))
        gamebox.pause()
    if p2_score >= 10:
        camera.draw(
            gamebox.from_text(400, 100, "Yellow Wins!", "Arial", 40, "Yellow",
                              True))
        gamebox.pause()
    camera.display()
Beispiel #34
0
def tick(keys):
    ## GLOBAL VARIABLES
    global scoreplayer1, scoreplayer2, agreed, countup, p1north, p1west, p1east, p1south, \
        p2north, p2south, p2west, p2east, \
        player1x, player1y, player2x, player2y, \
        restart, frame, counter, boomx, boomy

    ## CREATING RESTART MESSAGE AND HIGHLIGHT TO INFORM PLAYER
    restartmessage = gamebox.from_text(625, 50, "PRESS SPACE TO CONTINUE",
                                       "TIMES", 20, "white")
    restartmessagehighlight = gamebox.from_color(625, 50, "red", 325, 50)

    ## RESTART CONDITION - IF SPACE IS PRESSED AND RESTART BOOLEAN IS FALSE
    if pygame.K_SPACE in keys and restart == False:
        ## SET RESTART BOOLEAN TO TRUE
        restart = True
        ## REDEFINING PLAYER 1 POSITIONING
        player1x = random.randint(150, 300)
        player1y = 400
        ## REDEFINING PLAYER 2 POSITIONING
        player2x = random.randint(500, 650)
        player2y = 400

        ## RE-CREATING PLAYER 1 LISTS
        player1trail[:] = []
        player1trail.append(
            gamebox.from_color(player1x, player1y, 'red', 10, 10))

        player2trail[:] = []
        player2trail.append(
            gamebox.from_color(player2x, player2y, 'blue', 10, 10))

        ## RE-CREATING COINS

        coins.append(
            gamebox.from_image(400, random.randint(120, 580), coinsprite[0]))
        coins[0].scale_by(0.5)

        ## PLAYING RESTART SOUND

        restartsound.play()

        ## CLEARING EXPLOSIONS LIST
        explosions[:] = []

        ## RESETTING BOOLEAN VARIABLES FOR GAME RESTART
        p1north = True
        p1south = False
        p1east = False
        p1west = False

        p2north = True
        p2south = False
        p2east = False
        p2west = False

    ## DEFINING GAME RESTART CONDITION
    if restart == True:

        ## CLEARING CAMERA FOR GAME
        camera.draw(gamebackdrop)
        camera.draw(playingfield)

        ## DRAWING TRON LOGO
        camera.draw(logo)
        ## CREATING COUNT-UP TIMER
        countup += 1

        ## DEFINING MATH BEHIND TIMER
        seconds = str(int((countup / ticks_per_second) % 60)).zfill(2)
        minutes = str(int((countup / ticks_per_second) / 60))

        ## DEEFINING COINS SCORE
        for coin in coins:
            ## CREATING CONDITION FOR PLAYER 1 COIN COLLECTION
            if player1trail[len(player1trail) - 1].touches(coin):
                scoreplayer1 += 1
                coinsound.play()
                coins.remove(coin)
            ## CREATING CONDITION FOR PLAYER 2 COIN COLLECTION
            if player2trail[len(player2trail) - 1].touches(coin):
                scoreplayer2 += 1
                coinsound.play()
                coins.remove(coin)
            camera.draw(coin)

    ## CREATING RANDOM SPAWN OF COIN
        if int(countup) % 150 == 0:
            coins.append(
                gamebox.from_image(random.randint(150, 300),
                                   random.randint(120, 580), coinsprite[0]))
            coins[len(coins) - 1].scale_by(0.5)

    ## DEFINING PLAYER 1 CHARACTER MOVEMENTS

        if pygame.K_w in keys:
            if p1south == False:
                p1north = True
                p1south = False
                p1east = False
                p1west = False

        if pygame.K_s in keys:
            if p1north == False:
                p1north = False
                p1south = True
                p1east = False
                p1west = False

        if pygame.K_d in keys:
            if p1west == False:
                p1north = False
                p1south = False
                p1east = True
                p1west = False

        if pygame.K_a in keys:
            if p1east == False:
                p1north = False
                p1south = False
                p1east = False
                p1west = True

    ## DEFINING PLAYER 2 CHARACTER MOVEMENTS

        if pygame.K_UP in keys:
            if p2south == False:
                p2north = True
                p2south = False
                p2east = False
                p2west = False

        if pygame.K_DOWN in keys:
            if p2north == False:
                p2north = False
                p2south = True
                p2east = False
                p2west = False

        if pygame.K_RIGHT in keys:
            if p2west == False:
                p2north = False
                p2south = False
                p2east = True
                p2west = False

        if pygame.K_LEFT in keys:
            if p2east == False:
                p2north = False
                p2south = False
                p2east = False
                p2west = True

    ## CONDITION FOR P1 NORTH MOVEMENT
        if p1north == True and p1south == False and p1east == False and p1west == False:
            ## DECREASING PLAYER 1 Y POSITION
            player1y -= 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player1trail.append(
                gamebox.from_color(player1x, player1y, 'red', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player1trail:
                camera.draw(trail)
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player1trail[len(player1trail) - 1].top_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player1x, player1y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1north = False
                    p2north = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    scoreplayer2 += 1
                    ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

    ## CONDITION FOR P2 NORTH MOVEMENT
        if p2north == True and p2south == False and p2east == False and p2west == False:
            ## DECREASING PLAYER 1 Y POSITION
            player2y -= 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player2trail.append(
                gamebox.from_color(player2x, player2y, 'blue', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player2trail:
                camera.draw(trail)
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player2trail[len(player2trail) - 1].top_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player2x, player2y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING NORTH BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1north = False
                    p2north = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    scoreplayer1 += 1
                    ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

    ## CONDITION FOR P1 SOUTH MOVEMENT
        if p1north == False and p1south == True and p1east == False and p1west == False:
            ## INCREASING PLAYER 1 Y POSITION
            player1y += 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player1trail.append(
                gamebox.from_color(player1x, player1y, 'red', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player1trail:
                camera.draw(trail)
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player1trail[len(player1trail) - 1].bottom_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player1x, player1y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1south = False
                    p2south = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    scoreplayer2 += 1
                    ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

    ## CONDITION for P2 SOUTH MOVEMENT
        if p2north == False and p2south == True and p2east == False and p2west == False:
            ## DECREASING PLAYER 1 Y POSITION
            player2y += 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player2trail.append(
                gamebox.from_color(player2x, player2y, 'blue', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player2trail:
                camera.draw(trail)
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player2trail[len(player2trail) - 1].bottom_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player2x, player2y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING NORTH BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1south = False
                    p2south = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    print("This ran")
                    ## INCREASING PLAYER SCORE
                    scoreplayer1 += 1
                    ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False
    ## CONDITION FOR P1 EAST MOVEMENT
        if p1north == False and p1south == False and p1east == True and p1west == False:
            ## INCREASING PLAYER 1 X POSITION
            player1x += 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player1trail.append(
                gamebox.from_color(player1x, player1y, 'red', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player1trail:
                camera.draw(trail)
                ## CODE HERE IS DIFFERENT BECAUSE OF ISSUES WITH THE .right_touches() METHOD
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player1trail[len(player1trail) -
                                1].x < trail.x and player1trail[
                                    len(player1trail) -
                                    1].right_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player1x, player1y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1east = False
                    p2east = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    if player2trail[len(player2trail) -
                                    1].x < trail.x and player2trail[
                                        len(player2trail) -
                                        1].right_touches(trail):
                        scoreplayer1 += 1
                    elif player1trail[len(player1trail) -
                                      1].x < trail.x and player1trail[
                                          len(player1trail) -
                                          1].right_touches(trail):
                        scoreplayer2 += 1
                    ## CLEARING PLAYER1TRAIL LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

        ## CONDITION for P2 EAST MOVEMENT
        if p2north == False and p2south == False and p2east == True and p2west == False:
            ## DECREASING PLAYER 1 Y POSITION
            player2x += 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player2trail.append(
                gamebox.from_color(player2x, player2y, 'blue', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player2trail:
                camera.draw(trail)
                ## CODE HERE IS DIFFERENT BECAUSE OF ISSUES WITH THE .right_touches() METHOD
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player2trail[len(player2trail) -
                                1].x < trail.x and player2trail[
                                    len(player2trail) -
                                    1].right_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player2x, player2y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING NORTH BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1east = False
                    p2east = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    scoreplayer1 += 1
                    ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

    ## CONDITION FOR P1 WEST MOVEMENT
        if p1north == False and p1south == False and p1east == False and p1west == True:
            ## DECREASING PLAYER 1 X POSITION
            player1x -= 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player1trail.append(
                gamebox.from_color(player1x, player1y, 'red', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player1trail:
                camera.draw(trail)
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player1trail[len(player1trail) - 1].left_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player1x, player1y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1west = False
                    p2west = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    scoreplayer2 += 1
                    ## CLEARING PLAYER1TRAIL LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

        ## CONDITION for P2 WEST MOVEMENT
        if p2north == False and p2south == False and p2east == False and p2west == True:
            ## DECREASING PLAYER 1 Y POSITION
            player2x -= 5
            ## CREATING PLAYER 1 TRAIL IN RELEVANT DIRECTION
            player2trail.append(
                gamebox.from_color(player2x, player2y, 'blue', 10, 10))
            ## DRAWING PLAYER 1 TRAIL
            for trail in player2trail:
                camera.draw(trail)
                ## DEFINING PLAYER 1 COLLISION CONDITION(S)
                if player2trail[len(player2trail) - 1].left_touches(trail):
                    ## CREATING EXPLOSION AT RELEVANT REGION
                    explosions.append(
                        gamebox.from_image(player2x, player2y,
                                           explosionsprite[9]))
                    ## PLAYING EXPLOSION SOUND
                    explosionsound.play()
                    ## SETTING NORTH BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                    p1west = False
                    p2west = False
                    ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                    coins[:] = []
                    ## INCREASING PLAYER SCORE
                    scoreplayer1 += 1
                    ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                    player1trail[:] = []
                    player2trail[:] = []
                    camera.draw(explosions[len(explosions) - 1])
                    ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                    camera.draw(restartmessagehighlight)
                    camera.draw(restartmessage)
                    ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                    restart = False

        ## DRAWING SCORE(s) ON SCREEN
        player1score = gamebox.from_text(
            150, 35, "PLAYER 1 SCORE: " + str(scoreplayer1), "TIMES", 20,
            "White")
        player2score = gamebox.from_text(
            150, 65, "PLAYER 2 SCORE: " + str(scoreplayer2), "TIMES", 20,
            "White")

        countuphighlight = gamebox.from_color(150, 50, 'black', 250, 75)
        camera.draw(countuphighlight)
        camera.draw(player1score)
        camera.draw(player2score)

        ## DRAWING TIMER ON SCREEN
        countuptimer = gamebox.from_text(400, 50, minutes + ":" + seconds,
                                         "TIMES", 25, "White")

        timerhighlight = gamebox.from_color(400, 50, 'black', 75, 50)
        camera.draw(timerhighlight)
        camera.draw(countuptimer)

        ## DRAWING WALLS/ARENA BOUNDARIES
        for wall in walls:
            camera.draw(wall)

    ## DEFINING PLAYER TRAIL CONDITION TO PREVENT ERRORS
    if len(player1trail) != 0 and len(player2trail) != 0:
        ## DEFINING CONDITIONS FOR PLAYER 1 COLLISION WITH PLAYER 2
        for trail in player2trail:
            if player1trail[len(player1trail) - 1].touches(trail):
                ## CREATING EXPLOSION AT RELEVANT REGION
                explosions.append(
                    gamebox.from_image(player1x, player1y, explosionsprite[9]))
                ## PLAYING EXPLOSION SOUND
                explosionsound.play()
                ## SETTING NORTH BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                p1west = False
                p2west = False
                p1east = False
                p2east = False
                p1north = False
                p2north = False
                p1south = False
                p2south = False
                ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                coins[:] = []
                ## INCREASING PLAYER SCORE
                scoreplayer2 += 5
                ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                player1trail[:] = []
                player2trail[:] = []
                camera.draw(explosions[len(explosions) - 1])
                ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                camera.draw(restartmessagehighlight)
                camera.draw(restartmessage)
                ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                restart = False

    ## DEFINING PLAYER TRAIL CONDITION TO PREVENT ERRORS
    if len(player1trail) != 0 and len(player2trail) != 0:
        ## DEFINING CONDITIONS FOR PLAYER 2 COLLISION WITH PLAYER 1

        for trail in player1trail:
            if player2trail[len(player2trail) - 1].touches(trail):
                ## CREATING EXPLOSION AT RELEVANT REGION
                explosions.append(
                    gamebox.from_image(player2x, player2y, explosionsprite[9]))
                ## PLAYING EXPLOSION SOUND
                explosionsound.play()
                ## SETTING NORTH BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
                p1west = False
                p2west = False
                p1east = False
                p2east = False
                p1north = False
                p2north = False
                p1south = False
                p2south = False
                ## CLEARING COINS LIST IN PREPARATION FOR RESTART
                coins[:] = []
                ## INCREASING PLAYER SCORE
                scoreplayer1 += 5
                ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
                player1trail[:] = []
                player2trail[:] = []
                camera.draw(explosions[len(explosions) - 1])
                ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
                camera.draw(restartmessagehighlight)
                camera.draw(restartmessage)
                ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
                restart = False

    ## DEFINING PLAYER TRAIL CONDITION TO PREVENT ERRORS
    if len(player1trail) != 0 and len(player2trail) != 0:
        ## DEFINING PLAYER COLLISION CONDITION WITH WEST WALL
        if player1trail[len(player1trail) - 1].touches(walls[0]):
            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player1x, player1y, explosionsprite[9]))
            ## PLAYING EXPLOSION SOUND
            explosionsound.play()
            ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1west = False
            p2west = False
            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer2 += 1
            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)
            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

        ## DEFINING PLAYER COLLISION CONDITION WITH WEST WALL
        elif player2trail[len(player2trail) - 1].touches(walls[0]):
            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player2x, player2y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1west = False
            p2west = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer1 += 1
            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)
            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

        ## DEFINING PLAYER COLLISION CONDITION WITH EAST WALL
        elif player1trail[len(player1trail) - 1].touches(walls[1]):

            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player1x, player1y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1east BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1east = False
            p2east = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer2 += 1

            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)

            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

        ## DEFINING PLAYER COLLISION CONDITION WITH EAST WALL
        elif player2trail[len(player2trail) - 1].touches(walls[1]):
            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player2x, player2y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1east = False
            p2east = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer1 += 1
            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)
            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

        ## DEFINING PLAYER COLLISION CONDITION WITH NORTH WALL
        elif player1trail[len(player1trail) - 1].touches(walls[2]):

            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player1x, player1y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1north BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1north = False
            p2north = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer2 += 1
            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)

            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

            ## DEFINING PLAYER COLLISION CONDITION WITH NORTH WALL
        elif player2trail[len(player2trail) - 1].touches(walls[2]):
            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player2x, player2y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1north = False
            p2north = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer1 += 1
            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)
            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

        ## DEFINING PLAYER COLLISION CONDITION WITH SOUTH WALL
        elif player1trail[len(player1trail) - 1].touches(walls[3]):
            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player1x, player1y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1south BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1south = False
            p2south = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer2 += 1

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)

            camera.draw(explosions[len(explosions) - 1])
            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

            ## DEFINING PLAYER COLLISION CONDITION WITH SOUTH WALL
        elif player2trail[len(player2trail) - 1].touches(walls[3]):
            ## CREATING EXPLOSION AT RELEVANT REGION
            explosions.append(
                gamebox.from_image(player2x, player2y, explosionsprite[9]))

            ## PLAYING EXPLOSION SOUND

            explosionsound.play()

            ## SETTING p1west BOOLEAN VARIABLE TO FALSE TO PREVENT FURTHER MOVEMENT
            p1south = False
            p2south = False

            ## CLEARING PLAYER1TRAIL and PLAYER1OUTLINE LISTS IN PREPARATION FOR RESTART
            player1trail[:] = []
            player2trail[:] = []

            ## CLEARING COINS LIST IN PREPARATION FOR RESTART
            coins[:] = []

            ## INCREASING PLAYER 2 SCORE
            scoreplayer1 += 1
            camera.draw(explosions[len(explosions) - 1])

            ## DRAWING RESTART MESSAGE TO INFORM PLAYER(S)
            camera.draw(restartmessagehighlight)
            camera.draw(restartmessage)
            ## SETTING RESTART BOOLEAN TO FALSE TO PREPARE FOR GAME RESTART
            restart = False

## DEFINING CONDITION FOR PLAYER 1 GAME WIN
    if scoreplayer1 > scoreplayer2 and scoreplayer1 >= 20:
        ## CREATING PLAYER 1 AND PLAYER 2 FINAL SCORE VARIABLES
        winner = gamebox.from_text(400, 350, "PLAYER 1 WINS! ", "TIMES", 50,
                                   "Red")
        p1score = gamebox.from_text(400, 425,
                                    "PLAYER 1 SCORE: " + str(scoreplayer1),
                                    "TIMES", 50, "Black")
        p2score = gamebox.from_text(400, 500,
                                    "PLAYER 2 SCORE: " + str(scoreplayer2),
                                    "TIMES", 50, "Black")

        ## CLEARING WHITE BACKGROUND
        camera.clear("white")

        ## DRAWING GAMEOVER IMAGE
        camera.draw(gamebox.from_image(400, 200, "gameover.png"))

        ## PLAYING BACKGROUND SOUND TO FINISH
        backgroundsound.play()

        ## DRAWING SCORES
        camera.draw(winner)
        camera.draw(p1score)
        camera.draw(p2score)

        ## PAUSING GAMEBOX
        gamebox.pause()

## DEFINING CONDITION FOR PLAYER 2 GAME WIN
    if scoreplayer2 > scoreplayer1 and scoreplayer2 >= 20:
        ## CREATING PLAYER 1 AND PLAYER 2 FINAL SCORE VARIABLES
        winner = gamebox.from_text(400, 350, "PLAYER 2 WINS! ", "TIMES", 50,
                                   "Red")
        p1score = gamebox.from_text(400, 425,
                                    "PLAYER 1 SCORE: " + str(scoreplayer1),
                                    "TIMES", 50, "Black")
        p2score = gamebox.from_text(400, 500,
                                    "PLAYER 2 SCORE: " + str(scoreplayer2),
                                    "TIMES", 50, "Black")

        ## CLEARING WHITE BACKGROUND
        camera.clear("white")

        ## DRAWING GAMEOVER IMAGE
        camera.draw(gamebox.from_image(400, 200, "gameover.png"))

        ## PLAYING BACKGROUND SOUND TO FINISH
        backgroundsound.play()

        ## DRAWING SCORES
        camera.draw(winner)
        camera.draw(p1score)
        camera.draw(p2score)
        ## PAUSING GAMEBOX
        gamebox.pause()
    ## DISPLAYING CAMERA
    camera.display()
Beispiel #35
0
def tick(keys):

    if show_splash:
        splash(keys)
        return
    else:
        camera.draw(bc1)
        camera.draw(bc2)
        bc1.x -= 10
        bc2.x -= 10
        if bc1.right < camera.left:
            # rock.y -= 600
            bc1.x += 2048
        if bc2.right < camera.left:
            # rock.y -= 600
            bc2.x += 2048

        global ticks
        global score
        global scoreboard
        ticks += 1
        global x
        x += 1

        for i in health:
            camera.draw(i)

        #camera.draw(oceanfloor)
        # if box.touches(camera.bottom):
        #     box.y -=5
        # if box.touches(camera.top):
        #     box.y +=5
        #if box.right < camera.left:
        #box.x +=5
        # if box.x < 1000:
        #     box.x +=5

        # time = gamebox.from_text(0, 0, str(ticks // 30), "Arial", 20, "red")
        # time.top = camera.top
        # time.right = camera.right
        # camera.draw(time)

    #SHARK

        shark.x -= 3
        if shark.y > box.y:
            shark.y -= 3
        if shark.y < box.y:
            shark.y += 3
        shark.speedx *= 0.95
        shark.speedy *= 0.95

        if shark.right < camera.left:
            shark.x = 2000

        if shark.touches(box, -30, -30) and x > 60:
            health.pop()
            x = 0
            bad.play()

        shark.move_speed()
        camera.draw(shark)

        #SHELLS

        for shell in shells:
            camera.draw(shell)

        for shell in shells:
            if box.touches(shell):
                shell.x += 1500
                shell.y = random.randrange(camera.y, camera.bottom)
                score += 1
                scoreboard = gamebox.from_text(750, 10,
                                               "SCORE:  " + str(score),
                                               "Arial", 20, "white")
                bubbles.play()
                #shells.append(gamebox.from_color(800,random.randrange(camera.y,camera.bottom),"yellow",20,20))

        for shell in shells:
            camera.draw(shell)
            shell.x -= 10
            if shell.right < camera.left:
                # rock.y -= 600
                shell.x += 1500
                shell.y = random.randrange(camera.top, camera.bottom)
        for shell in shells:
            for rock in rocks:
                if shell.touches(rock):
                    shell.move_to_stop_overlapping(rock)

    #ROCKS
        for rock in rocks:
            camera.draw(rock)
            rock.x -= 10
            if rock.right < camera.left:
                # rock.y -= 600
                rock.x += 1600
                #rock.scale_by(0.1,0.25)

        #
        # if (box.touches(r1,-50,-50) or box.touches(r2,-50,-50)) and x>60:
        #     health.pop()
        #     x=0
        #
        # if box.touches(r1,-50,-50):
        #     bad.play()
        #
        #
        # if box.touches(r2,-50,-50):
        #     bad.play()

#FISH

#box.x -= 10
        if pygame.K_RIGHT in keys:
            box.x += 15
        if pygame.K_LEFT in keys:
            box.x -= 15
        if pygame.K_UP in keys:
            box.y -= 10
        if pygame.K_DOWN in keys:
            box.y += 10
        # if box.x==0:
        #     camera.draw(youlose)
        #     gamebox.pause()

        if box.right < camera.left:
            camera.draw(youlose)
            gamebox.pause()
        if box.left > camera.right:
            camera.draw(youlose)
            gamebox.pause()
        if box.bottom < camera.top:
            camera.draw(youlose)
            gamebox.pause()
        if box.top > camera.bottom:
            camera.draw(youlose)
            gamebox.pause()

        box.move_speed()
        camera.draw(box)

        camera.draw(healthbar)
        camera.draw(scoreboard)

        if health == []:
            camera.draw(youlose)
            gamebox.pause()

        # usually camera.display() should be the last line of the tick method
        camera.display()