Example #1
0
def end_game():
    global level, game_over
    level = -2
    camera.draw(gamebox.from_image(400, 300, 'GameOver.png'))
    game_over = False
    if camera.mouseclick:
        gamebox.stop_loop()
Example #2
0
    def _tick(self, keys):
        if not self.ok: return False
        self.c.clear('black')

        for x, y in sorted(self.open):
            self.room.center = (2 * x + 1) * self.scale, (2 * y +
                                                          1) * self.scale
            self.c.draw(self.room)
            if (x - 1, y) in self.open:
                self.door.size = self.scale / 2, self.scale
                self.door.center = (2 * x) * self.scale, (2 * y +
                                                          1) * self.scale
                self.c.draw(self.door)
            if (x, y - 1) in self.open:
                self.door.size = self.scale, self.scale / 2
                self.door.center = (2 * x + 1) * self.scale, (2 *
                                                              y) * self.scale
                self.c.draw(self.door)

        self.b.move_speed()
        self.eye.center = self.b.center
        self.pupil.x = self.eye.x + self.look[0] * self.scale / 4
        self.pupil.y = self.eye.y + self.look[1] * self.scale / 4
        self.c.draw(self.eye)
        self.c.draw(self.pupil)

        if (self.b.x // (self.scale * 2),
                self.b.y // (self.scale * 2)) not in self.open:
            self.c.draw("Crash!", self.scale * 2, 'red', self.c.center)
            print("Crashed into a wall!")
            self.ok = False
            gamebox.stop_loop()
            gamebox.keys_loop(lambda x: gamebox.stop_loop())

        self.c.display()
Example #3
0
def title(keys):
    global credit_count, play_count, option_count, sound_level
    pygame.mixer.music.set_volume(sound_level)
    if pygame.K_q in keys:
        quit()
    camera.clear("red")
    camera.draw(titlebackground)
    camera.draw(char2)
    camera.draw(char4)
    camera.draw(char5)
    camera.draw(char6)
    camera.draw(char7)
    camera.draw(char3)
    if pygame.K_p in keys:
        global_stage.level += 1
    if pygame.K_o in keys:
        option_count += 1
    if pygame.K_c in keys:
        credit_count += 1
    if pygame.K_ESCAPE in keys:
        gamebox.stop_loop()
    if credit_count != 0:
        tick_creds(keys)
    if option_count != 0:
        tick_options(keys)
    if global_stage.level == 1:
        musicplayer1 = music1.play(-1)
        gamebox.timer_loop(30, game_final_1.tick)
    elif global_stage.level == 2:
        music1.stop()
        musicplayer2 = music2.play(-1)
        gamebox.timer_loop(30, sponge_run.sponge_run_function)
    if play_count == 0 and credit_count == 0 and option_count == 0:
        camera.display()
def title(keys):
    global credit_count, play_count, option_count, sound_level
    pygame.mixer.music.set_volume(sound_level)
    if pygame.K_q in keys:
        quit()
    camera.clear("red")
    camera.draw(titlebackground)
    camera.draw(char2)
    camera.draw(char4)
    camera.draw(char5)
    camera.draw(char6)
    camera.draw(char7)
    camera.draw(char3)
    if pygame.K_p in keys:
        global_stage.level += 1
    if pygame.K_o in keys:
        option_count += 1
    if pygame.K_c in keys:
        credit_count += 1
    if pygame.K_ESCAPE in keys:
        gamebox.stop_loop()
    if credit_count != 0:
        tick_creds(keys)
    if option_count != 0:
        tick_options(keys)
    if global_stage.level == 1:
        musicplayer1 = music1.play(-1)
        gamebox.timer_loop(30, game_final_1.tick)
    elif global_stage.level == 2:
        music1.stop()
        musicplayer2 = music2.play(-1)
        gamebox.timer_loop(30, sponge_run.sponge_run_function)
    if play_count == 0 and credit_count == 0 and option_count == 0:
        camera.display()
Example #5
0
def tick(keys):
    # get access to the counter
    global count_tick
    global counter
    if pygame.K_RIGHT in keys:
        character.x += 10
    if pygame.K_LEFT in keys:
        character.x -= 10
    character.yspeed += 1
    character.y = character.y + character.yspeed
    camera.clear("black")
    camera.draw(character)
    camera.draw(ground)
    if character.bottom_touches(ground):
        character.yspeed = 0
        if pygame.K_SPACE in keys:
            character.yspeed = -20
    if character.touches(ground):
        character.move_to_stop_overlapping(ground)
    camera.display()
    count_tick += 1

    for wall in walls:
        if character.bottom_touches(wall):
            character.yspeed = 0
            if pygame.K_SPACE in keys:
                character.yspeed = -22
        if character.touches(wall):
            character.move_to_stop_overlapping(wall)
        camera.draw(wall)
    for coin in coins:
        if character.touches(coin):
            counter += 1
            coins.remove(coin)

        camera.draw(coin)
    camera.draw(
        gamebox.from_text(70,
                          10,
                          "Stars collected: " + str(counter),
                          "Arial",
                          20,
                          "red",
                          italic=True))
    ticks_per_second = 30
    seconds = int(count_tick / ticks_per_second)
    camera.draw(
        gamebox.from_text(700,
                          10,
                          str(seconds) + " out of 30 seconds spent",
                          "Arial",
                          20,
                          "red",
                          italic=True))
    if seconds >= 30:
        gamebox.stop_loop()
        print("You found " + str(counter) + " stars.")

    camera.display()
Example #6
0
def restart(keys):
    '''
    This function is executed whenever the player hits a wall or hits an enemy -- it's basically a "reset".
    :param keys:
    :return:
    '''
    global time
    global level
    global points
    if pygame.K_SPACE in keys:
        gamebox.unpause()
        points = points - 10
        if points < 0:
            camera.clear('black')
            camera.draw(
                gamebox.from_text(camera.left + 400, 200, 'You Lose!', 50,
                                  'white'))
            camera.draw(
                gamebox.from_text(camera.left + 400, 300,
                                  'Quit and reopen the game to play again', 50,
                                  'white'))
        elif level == 1:
            player_sprite[0].x = 320
            player_sprite[0].y = 550
            gamebox.timer_loop(60, tick)
        elif level == 2:
            player_sprite[1].x = 0
            player_sprite[1].y = 420
            enemy_sprite2[0].x = 400
            enemy_sprite2[0].y = 420
            enemy_sprite2[1].x = 400
            enemy_sprite2[1].y = 225
            enemy_sprite2[0].xspeed = -enemy_sprite2[0].xspeed
            enemy_sprite2[1].xspeed = -enemy_sprite2[1].xspeed
            gamebox.timer_loop(60, tick)
        elif level == 3:
            player_sprite[2].x = 10
            player_sprite[2].y = 75
            gamebox.timer_loop(60, tick)
        elif level == 4:
            player_sprite[3].x = 10
            player_sprite[3].y = 300
            gamebox.timer_loop(60, tick)
        elif level == 5:
            camera.clear('black')
            camera.draw(
                gamebox.from_text(
                    400, 300,
                    'You failed to win, quit the game and reopen to try again.',
                    40, 'red'))
            gamebox.stop_loop()

    camera.display()
Example #7
0
 def say(self, num):
     if not self.ok: return
     self.look = (0, 0)
     self._tick(())
     self.c.draw(str(num), self.scale * 4, 'red', self.c.center)
     self.c.display()
     print('said', num, 'after', self.moves, 'moves and', self.looks,
           'looks')
     gamebox.keys_loop(lambda x: gamebox.stop_loop())
Example #8
0
def tick(keys):
    global count, temp, p1_direction, p2_direction, menu, p2_on, p1_stat, p2_stat, p1_death, p2_death, p1_xhitspeed, \
        p1_yhitspeed, p2_xhitspeed, p2_yhitspeed, p1_punches, p2_punches, mode, submode, winner, p1_points, p2_points, \
        p1_char, p1_showtime, p2_showtime, p1_airjump, p2_airjump, p1_hitshowtime, p2_hitshowtime, p1_hittime, \
        p2_hittime, r2, r1

    if menu == -1:
        camera.clear("white")

        # Words
        camera.draw(
            gamebox.from_text(640, 725, "Press 'Enter' to Start", "Arial", 24,
                              "blue"))
        camera.draw(
            gamebox.from_text(640, 300, "Controls:", "Arial", 48, "blue"))
        camera.draw(
            gamebox.from_text(640, 350, "Player 1       Player 2", "Arial", 24,
                              "blue"))
        camera.draw(
            gamebox.from_text(640, 375,
                              "Movement : Arrow Keys       Movement : WASD",
                              "Arial", 24, "blue"))
        camera.draw(
            gamebox.from_text(640, 400, "Attack : Z       Attack : .", "Arial",
                              24, "blue"))
        camera.draw(
            gamebox.from_text(640, 200, "Battle Royal", "Arial", 96, "blue"))

        # Player 2 Choice
        camera.draw(
            gamebox.from_text(640, 600, "Player 2:", "Arial", 24, "blue"))
        camera.draw(on_button)
        camera.draw(off_button)
        camera.draw(gamebox.from_text(550, 650, "ON", "Arial", 24, "black"))
        camera.draw(gamebox.from_text(730, 650, "OFF", "Arial", 24, "black"))

        leftmouse, middlemouse, rightmouse = pygame.mouse.get_pressed()
        mouse_x, mouse_y = pygame.mouse.get_pos()
        if 500 <= mouse_x <= 600 and 625 <= mouse_y <= 675:
            if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                p2_on = True
                on_button.color = "green"
                off_button.color = "red"
                clicksound.play()
        if 580 <= mouse_x <= 780 and 625 <= mouse_y <= 675:
            if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                p2_on = False
                on_button.color = "red"
                off_button.color = "green"
                clicksound.play()

        if pygame.K_RETURN in keys:
            menu = 1
            keys.remove(pygame.K_RETURN)

    elif menu == 1:
        camera.clear("white")
        camera.draw(gamebox.from_color(320, 300, "black", 150, 80))
        camera.draw(gamebox.from_color(960, 300, "black", 150, 80))
        camera.draw(stock_box)
        camera.draw(time_box)
        camera.draw(
            gamebox.from_text(640, 200, "Settings", "Arial", 48, "black"))
        camera.draw(gamebox.from_text(320, 300, "Lives", "Arial", 48, "black"))
        camera.draw(gamebox.from_text(960, 300, "Time", "Arial", 48, "black"))
        camera.draw(
            gamebox.from_text(640, 750, "Press 'Enter' to Start", "Arial", 48,
                              "black"))
        camera.draw(gamebox.from_color(640, 500, "black", 400, 140))
        camera.draw(gamebox.from_color(640, 500, "white", 300, 120))
        camera.draw(gamebox.from_color(800, 500, "blue", 60, 120))
        camera.draw(gamebox.from_color(480, 500, "blue", 60, 120))
        if submode == 1:
            camera.draw(gamebox.from_color(480, 500, "grey", 60, 120))
        if submode == 99:
            camera.draw(gamebox.from_color(800, 500, "grey", 60, 120))
        leftmouse, middlemouse, rightmouse = pygame.mouse.get_pressed()
        mouse_x, mouse_y = pygame.mouse.get_pos()
        if 270 <= mouse_x <= 370 and 250 <= mouse_y <= 350:
            if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                mode = "stock"
                stock_box.color = "green"
                time_box.color = "red"
                clicksound.play()
        if 910 <= mouse_x <= 1010 and 250 <= mouse_y <= 350:
            if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                mode = "time"
                time_box.color = "green"
                stock_box.color = "red"
                clicksound.play()
        if mode == "stock":
            camera.draw(
                gamebox.from_text(640, 500,
                                  str(submode) + " Lives", "Arial", 48,
                                  "black"))
            if 730 <= mouse_x <= 830 and 440 <= mouse_y <= 560 and submode != 99:
                if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                    submode += 1
                    camera.draw(gamebox.from_color(800, 500, "green", 60, 120))
            if 450 <= mouse_x <= 510 and 440 <= mouse_y <= 560 and submode != 1:
                if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                    submode -= 1
                    camera.draw(gamebox.from_color(480, 500, "green", 60, 120))
        elif mode == "time":
            camera.draw(
                gamebox.from_text(640, 500,
                                  str(submode) + ":00", "Arial", 48, "black"))
            if 730 <= mouse_x <= 830 and 440 <= mouse_y <= 560 and submode != 99:
                if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                    submode += 1
                    camera.draw(gamebox.from_color(800, 500, "green", 60, 120))
            if 450 <= mouse_x <= 510 and 440 <= mouse_y <= 560 and submode != 1:
                if leftmouse == 1 or middlemouse == 1 or rightmouse == 1:
                    submode -= 1
                    camera.draw(gamebox.from_color(480, 500, "green", 60, 120))
        if pygame.K_RETURN in keys:
            menu = 0

    elif menu == 0:
        if p1.x < -500 or p1.x > 1400 or p1.y < -200 or p1.y > 800:
            camera.center = [p2.x, p2.y]
        elif p2.x < -500 or p2.x > 1400 or p2.y < -200 or p2.y > 800:
            camera.center = [p1.x, p1.y]
        else:
            camera.center = [(p1.x + p2.x) / 2, (p1.y + p2.y) / 2]
        camera.clear("white")
        camera.draw(backgroundimg)
        # camera.draw(ground)
        for platformimage in platformimages:
            camera.draw(platformimage)
        camera.draw(groundimg)
        count += float(1 / 30)
        if p1_death is False:
            p1.yspeed += 5
        elif p1_death is True:
            p1.yspeed = 0
        if p2_death is False:
            p2.yspeed += 5
        elif p2_death is True:
            p2.yspeed = 0
        p1.y += p1.yspeed
        p2.y += p2.yspeed
        p1_punch = gamebox.from_color(400, 600, "black", 1, 1)
        p2_punch = gamebox.from_color(400, 600, "black", 1, 1)

        # Hit movement
        if p1_xhitspeed != 0:
            p1.x += p1_xhitspeed
            if p1_xhitspeed > 0:
                p1_xhitspeed -= 1
            elif p1_xhitspeed < 0:
                p1_xhitspeed += 1
        if p1_yhitspeed != 0:
            p1.y += p1_yhitspeed
            if p1_yhitspeed > 0:
                p1_yhitspeed -= 1
            elif p1_yhitspeed < 0:
                p1_yhitspeed += 1
        if p2_xhitspeed != 0:
            p2.x += p2_xhitspeed
            if p2_xhitspeed > 0:
                p2_xhitspeed -= 1
            elif p2_xhitspeed < 0:
                p2_xhitspeed += 1
        if p2_yhitspeed != 0:
            p2.y += p2_yhitspeed
            if p2_yhitspeed > 0:
                p2_yhitspeed -= 1
            elif p2_yhitspeed < 0:
                p2_yhitspeed += 1

        # p1 actions
        if p1_direction == "right":
            p1.color = "red"
        elif p1_direction == "left":
            p1.color = "green"
        if pygame.K_RIGHT in keys and p2_punch.touches(
                p1) == False and count > p1_hittime + 1 / 4:
            p1.x += 15
            p1_direction = "right"
            p1_death = False
        if pygame.K_LEFT in keys and p2_punch.touches(
                p1) == False and count > p1_hittime + 1 / 4:
            p1.x -= 15
            p1_direction = "left"
            p1_death = False
        if pygame.K_DOWN in keys:
            p1_death = False
        if pygame.K_DOWN not in keys:
            for platform in platforms:
                if p1.bottom_touches(platform):
                    p1.move_to_stop_overlapping(platform)
                    p1_airjump = True
                    if p1.yspeed > 0:
                        p1.yspeed = 0
                    if pygame.K_UP in keys and count > p1_hittime + 1 / 4:
                        p1.yspeed -= 45
                        jumpsound.play()
                        keys.remove(pygame.K_UP)
        if p1.touches(ground):
            p1.move_to_stop_overlapping(ground)
            p1.yspeed = 0
            p1_airjump = True
        if pygame.K_UP in keys and p1.touches(
                ground) and count > p1_hittime + 1 / 4:
            p1.yspeed -= 45
            keys.remove(pygame.K_UP)
            jumpsound.play()
        elif pygame.K_UP in keys and p1_airjump:
            jumpsound.play()
            p1.yspeed -= 45
            if p1.touches(ground) is False:
                p1_airjump = False
        if p1.bottom_touches(ground) and pygame.K_z in keys and p1_punches["punch3"] == 0 and \
                        count > p1_punches["punch1"] + 1/4 and count > p1_punches["punch2"] + 1/4 or pygame.K_z in \
                keys and p1.bottom_touches(ground) is False:
            p1_death = False
            if pygame.K_UP in keys:
                p1_punch = gamebox.from_color(p1.x, p1.y - 40, "blue", 30, 40)
                # camera.draw(p1_punch)
            elif pygame.K_RIGHT in keys:
                p1_punch = gamebox.from_color(p1.x + 20, p1.y, "blue", 40, 30)
                # camera.draw(p1_punch)
            elif pygame.K_LEFT in keys:
                p1_punch = gamebox.from_color(p1.x - 20, p1.y, "blue", 40, 30)
                # camera.draw(p1_punch)
            elif pygame.K_DOWN in keys and p1.touches(ground) == False:
                p1_punch = gamebox.from_color(p1.x, p1.y + 40, "blue", 30, 40)
                # camera.draw(p1_punch)
            else:
                if p1_direction == "right":
                    p1_punch = gamebox.from_color(p1.x + 20, p1.y, "blue", 40,
                                                  30)
                    # camera.draw(p1_punch)
                elif p1_direction == "left":
                    p1_punch = gamebox.from_color(p1.x - 20, p1.y, "blue", 40,
                                                  30)
                    # camera.draw(p1_punch)

        # p2 actions
        if p2_on:
            if p2_direction == "right":
                p2.color = "red"
            elif p2_direction == "left":
                p2.color = "green"
            if pygame.K_d in keys and p1_punch.touches(
                    p2) == False and count > p2_hittime + 1 / 4:
                p2.x += 15
                p2_direction = "right"
                p2_death = False
            if pygame.K_a in keys and p1_punch.touches(
                    p2) == False and count > p2_hittime + 1 / 4:
                p2.x -= 15
                p2_direction = "left"
                p2_death = False
            if pygame.K_s in keys:
                p2_death = False
            if pygame.K_s not in keys:
                for platform in platforms:
                    if p2.bottom_touches(platform):
                        p2.move_to_stop_overlapping(platform)
                        p2_airjump = True
                        if p2.yspeed > 0:
                            p2.yspeed = 0
                        if pygame.K_w in keys and count > p2_hittime + 1 / 4:
                            p2.yspeed -= 45
                            jumpsound.play()
                            keys.remove(pygame.K_w)
            if p2.touches(ground):
                p2.move_to_stop_overlapping(ground)
                p2.yspeed = 0
                p2_airjump = True
            if pygame.K_w in keys and p2.touches(
                    ground) and count > p2_hittime + 1 / 4:
                p2.yspeed -= 45
                keys.remove(pygame.K_w)
                jumpsound.play()
            elif pygame.K_w in keys and p2_airjump:
                p2.yspeed -= 45
                jumpsound.play()
                if p2.touches(ground) is False:
                    p2_airjump = False
            if p2.bottom_touches(ground) and pygame.K_PERIOD in keys and p2_punches["punch3"] == 0 and \
                            count > p2_punches["punch1"] + 1/4 and count > p2_punches["punch2"] + 1/4 or \
                            pygame.K_PERIOD in keys and p2.bottom_touches(ground) is False:
                p2_death = False
                if pygame.K_w in keys:
                    p2_punch = gamebox.from_color(p2.x, p2.y - 40, "blue", 30,
                                                  40)
                    # camera.draw(p2_punch)
                elif pygame.K_d in keys:
                    p2_punch = gamebox.from_color(p2.x + 20, p2.y, "blue", 40,
                                                  30)
                    # camera.draw(p2_punch)
                elif pygame.K_a in keys:
                    p2_punch = gamebox.from_color(p2.x - 20, p2.y, "blue", 40,
                                                  30)
                    # camera.draw(p2_punch)
                elif pygame.K_s in keys and p2.touches(ground) == False:
                    p2_punch = gamebox.from_color(p2.x, p2.y + 40, "blue", 30,
                                                  40)
                    # camera.draw(p2_punch)
                else:
                    if p2_direction == "right":
                        p2_punch = gamebox.from_color(p2.x + 20, p2.y, "blue",
                                                      40, 30)
                        # camera.draw(p2_punch)
                    elif p2_direction == "left":
                        p2_punch = gamebox.from_color(p2.x - 20, p2.y, "blue",
                                                      40, 30)
                        # camera.draw(p2_punch)
            camera.draw(
                gamebox.from_text(p2.x,
                                  p2.y - 40,
                                  "Player 2",
                                  "Arial",
                                  12,
                                  "blue",
                                  bold=True))

        elif p2_on is False:
            if p2.touches(ground):
                p2.move_to_stop_overlapping(ground)
                p2.yspeed = 0
            for platform in platforms:
                if p2.bottom_touches(platform) and p1.y <= p2.y:
                    p2.move_to_stop_overlapping(platform)
                    if p2.yspeed > 0:
                        p2.yspeed = 0
            if p2_death is False:
                p2.yspeed += 5
                if 775 > p1.x > p2.x and p1_punch.touches(
                        p2) is False and count > p2_hittime + 1 / 4:
                    p2.x += 10
                    p2_direction = "right"
                elif 25 < p1.x < p2.x and p1_punch.touches(
                        p2) is False and count > p2_hittime + 1 / 4:
                    p2.x -= 10
                    p2_direction = "left"
                if p2.touches(p1) and p1_punch.touches(
                        p2) is False and count > p2_hittime + 1 / 4:
                    p2.move_to_stop_overlapping(p1)
                    rand = random.randint(0, 70)
                    if rand < 10:
                        if p1.y < p2.y:
                            p2_punch = gamebox.from_color(
                                p2.x, p2.y - 40, "blue", 30, 40)
                            # camera.draw(p2_punch)
                        elif p1.y > p2.y:
                            p2_punch = gamebox.from_color(
                                p2.x, p2.y + 40, "blue", 30, 40)
                            # camera.draw(p2_punch)
                        elif p2_direction == "right":
                            p2_punch = gamebox.from_color(
                                p2.x + 20, p2.y, "blue", 30, 40)
                            # camera.draw(p2_punch)
                        elif p2_direction == "left":
                            p2_punch = gamebox.from_color(
                                p2.x - 20, p2.y, "blue", 30, 40)
                            # camera.draw(p2_punch)
                if p1.y < p2.y and p2.bottom_touches(
                        ground) and count > p2_hittime + 1 / 4:
                    p2.yspeed -= 60
            elif p2_death:
                p2_death = False

            camera.draw(
                gamebox.from_text(p2.x,
                                  p2.y - 40,
                                  "COMPUTER",
                                  "Arial",
                                  12,
                                  "blue",
                                  bold=True))

        # Hit Mechanics
        if p1_punch.touches(p2):
            p2_hittime = count
            hitsound.play()
        if p2_punch.touches(p1):
            p1_hittime = count
            hitsound.play()
        if p1_punch.touches(p2) and p1.bottom_touches(ground) is False:
            p2_stat += 1
            if p1.x > p2.x:
                p2_xhitspeed -= p2_stat
            elif p1.x < p2.x:
                p2_xhitspeed += p2_stat
            if p1.y >= p2.y:
                p2_yhitspeed -= p2_stat
            elif p1.y < p2.y:
                p2_yhitspeed += p2_stat
        elif p1_punch.touches(
                p2) and p1_punches["punch1"] == 0 and p2_death is False:
            p2_stat += 1
            p2.yspeed = 0
            p1_punches["punch1"] = count
        elif p1_punch.touches(p2) and p1_punches["punch1"] != 0 and p1_punches["punch2"] == 0 and \
                        count > p1_punches["punch1"] + 1/4:
            p2_stat += 2
            p2.yspeed = 0
            p1_punches["punch2"] = count
        elif p1_punch.touches(p2) and p1_punches[
                "punch2"] != 0 and count > p1_punches["punch2"] + 1 / 4:
            p2_stat += 3
            p2.yspeed = 0
            if p1.x > p2.x:
                p2_xhitspeed -= p2_stat
            elif p1.x < p2.x:
                p2_xhitspeed += p2_stat
            if p1.y >= p2.y:
                p2_yhitspeed -= p2_stat
            elif p1.y < p2.y:
                p2_yhitspeed += p2_stat
            p1_punches["punch3"] = count

        if p1_punches["punch1"] != 0 and p1_punches[
                "punch2"] == 0 and p1_punches["punch3"] == 0:
            if count > p1_punches["punch1"] + 1:
                p1_punches["punch1"] = 0
        elif p1_punches["punch2"] != 0 and p1_punches["punch3"] == 0:
            if count > p1_punches["punch2"] + 1:
                p1_punches["punch1"] = 0
                p1_punches["punch2"] = 0
        elif p1_punches["punch3"] != 0:
            if count > p1_punches["punch3"] + 1:
                p1_punches["punch1"] = 0
                p1_punches["punch2"] = 0
                p1_punches["punch3"] = 0

        if p2_punch.touches(p1) and p2.bottom_touches(ground) == False:
            p1_stat += 1
            if p2.x > p1.x:
                p1_xhitspeed -= p1_stat
            elif p2.x < p1.x:
                p1_xhitspeed += p1_stat
            if p2.y >= p1.y:
                p1_yhitspeed -= p1_stat
            elif p2.y < p1.y:
                p1_yhitspeed += p1_stat
        elif p2_punch.touches(p1) and p2_punches["punch1"] == 0 and p2_punches[
                "punch2"] == 0 and p1_death is False:
            p1_stat += 1
            p1.yspeed = 0
            p2_punches["punch1"] = count
        elif p2_punch.touches(p1) and p2_punches["punch1"] != 0 and p2_punches["punch2"] == 0 and \
                        count > p2_punches["punch1"] + 1/4:
            p1_stat += 2
            p1.yspeed = 0
            p2_punches["punch2"] = count
        elif p2_punch.touches(p1) and p2_punches[
                "punch2"] != 0 and count > p2_punches["punch2"] + 1 / 4:
            p1_stat += 3
            p1.yspeed = 0
            if p2.x > p1.x:
                p1_xhitspeed -= p1_stat
            elif p2.x < p1.x:
                p1_xhitspeed += p1_stat
            if p2.y >= p1.y:
                p1_yhitspeed -= p1_stat
            elif p2.y < p1.y:
                p1_yhitspeed += p1_stat
            p2_punches["punch3"] = count

        if p2_punches["punch1"] != 0 and p2_punches[
                "punch2"] == 0 and p2_punches["punch3"] == 0:
            if count > p2_punches["punch1"] + 1:
                p2_punches["punch1"] = 0
        elif p2_punches["punch1"] != 0 and p2_punches[
                "punch2"] != 0 and p2_punches["punch3"] == 0:
            if count > p2_punches["punch2"] + 1:
                p2_punches["punch1"] = 0
                p2_punches["punch2"] = 0
        elif p2_punches["punch1"] != 0 and p2_punches[
                "punch2"] != 0 and p2_punches["punch3"] != 0:
            if count > p2_punches["punch3"] + 1:
                p2_punches["punch1"] = 0
                p2_punches["punch2"] = 0
                p2_punches["punch3"] = 0

        # Die Mechanics
        if p1.x > 1500 or p1.x < -500 or p1.y > 1000 or p1.y < -500:
            p1.x = 350
            p1.y = 50
            p1_xhitspeed = 0
            p1_yhitspeed = 0
            p1_stat = 0
            p2_points += 1
            p1_death = True
        if p2.x > 1500 or p2.x < -500 or p2.y > 1000 or p2.y < -500:
            p2.x = 450
            p2.y = 50
            p2_xhitspeed = 0
            p2_yhitspeed = 0
            p2_stat = 0
            p1_points += 1
            p2_death = True

        # Extra Camera
        if p1_direction == "left":
            left1 = 9
            lr1 = 11
        else:
            left1 = 0
            lr1 = 0
        extra_hit1.center = (p1_punch.x, p1_punch.y)
        if p2_punch.touches(p1):
            p1_char.image = p1_charsheet[1 + left1]
            p1_hitshowtime = count
        elif count < p1_hitshowtime + 1 / 4:
            p1_char.image = p1_charsheet[1 + left1]
        elif p1.bottom_touches(
                ground
        ) is False and pygame.K_z in keys or pygame.K_UP in keys and pygame.K_z in keys:
            p1_char.image = p1_charsheet[3 + left1]
            p1_showtime = count
            camera.draw(extra_hit1)
        elif count < p1_showtime + 1 / 4:
            p1_char.image = p1_charsheet[3 + left1]
        elif p1_punches["punch2"] != 0 and count < p1_punches["punch3"] + 1 / 4:
            p1_char.image = p1_charsheet[6 + left1]
        elif p1_punches["punch1"] != 0 and count < p1_punches["punch2"] + 1 / 4:
            p1_char.image = p1_charsheet[5 + left1]
        elif pygame.K_z in keys and p1_punches[
                "punch3"] == 0 or count < p1_punches["punch1"] + 1 / 4:
            p1_char.image = p1_charsheet[4 + left1]
        elif p1.bottom_touches(ground) is False and p1_char.bottom_touches(platform_1) is False and \
                        p1_char.bottom_touches(platform_2) is False and p1_char.bottom_touches(platform_3) is False \
                and p1_char.bottom_touches(platform_4) is False and p1_char.bottom_touches(platform_5) is False:
            p1_char.image = p1_charsheet[2 + left1]
        elif pygame.K_RIGHT in keys or pygame.K_LEFT in keys:
            p1_char.image = p1_charrunning[r1 + lr1]
            r1 += 1
            if r1 == 10:
                r1 = 0
        else:
            p1_char.image = p1_charsheet[0 + left1]
            r1 = 0
        if pygame.K_z in keys:
            keys.remove(pygame.K_z)

        if p2_direction == "left":
            left2 = 9
            lr2 = 15
        else:
            left2 = 0
            lr2 = 0
        extra_hit2.center = (p2_punch.x, p2_punch.y)
        if p1_punch.touches(p2):
            p2_char.image = p2_charsheet[1 + left2]
            p2_hitshowtime = count
        elif count < p2_hitshowtime + 1 / 4:
            p2_char.image = p2_charsheet[1 + left2]
        elif p2.bottom_touches(ground) is False and pygame.K_PERIOD in keys or pygame.K_w in keys and pygame.K_PERIOD \
                in keys:
            p2_char.image = p2_charsheet[3 + left2]
            p2_showtime = count
            camera.draw(extra_hit2)
        elif count < p2_showtime + 1 / 4:
            p2_char.image = p2_charsheet[3 + left2]
        elif p2_punches["punch2"] != 0 and count < p2_punches["punch3"] + 1 / 4:
            p2_char.image = p2_charsheet[6 + left2]
        elif p2_punches["punch1"] != 0 and count < p2_punches["punch2"] + 1 / 4:
            p2_char.image = p2_charsheet[5 + left2]
        elif pygame.K_PERIOD in keys and p2_punches[
                "punch1"] == 0 or count < p2_punches["punch1"] + 1 / 4:
            p2_char.image = p2_charsheet[4 + left2]
        elif p2.bottom_touches(ground) is False and p2_char.bottom_touches(platform_1) is False and \
                        p2_char.bottom_touches(platform_2) is False and p2_char.bottom_touches(platform_3) is False \
                and p2_char.bottom_touches(platform_4) is False and p2_char.bottom_touches(platform_5) is False:
            p2_char.image = p2_charsheet[2 + left2]
        elif pygame.K_d in keys or pygame.K_a in keys:
            p2_char.image = p2_charrunning[r2 + lr2]
            r2 += 1
            if r2 == 14:
                r2 = 1
        elif p2_on is False:
            if p2.bottom_touches(ground) or p2.bottom_touches(platform_1) or p2.bottom_touches(platform_2) or \
                            p2.bottom_touches(platform_3) or p2.bottom_touches(platform_4) or \
                            p2.bottom_touches(platform_5):
                p2_char.image = p2_charrunning[r2 + lr2]
                r2 += 1
                if r2 == 14:
                    r2 = 1
        else:
            p2_char.image = p2_charsheet[0 + left2]
            r2 = 0

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

        camera.draw(
            gamebox.from_text(p1.x,
                              p1.y - 40,
                              "Player 1",
                              "Arial",
                              12,
                              "red",
                              bold=True))
        # camera.draw(p1)
        p1_char.center = (p1.x, p1.y)
        camera.draw(p1_char)
        # camera.draw(p2)
        p2_char.center = (p2.x, p2.y)
        camera.draw(p2_char)
        camera.draw(
            gamebox.from_color(camera.x - 400, camera.y + 300, "red", 150,
                               300))
        camera.draw(
            gamebox.from_color(camera.x + 400, camera.y + 300, "blue", 150,
                               300))
        camera.draw(
            gamebox.from_text(camera.x - 400,
                              camera.y + 200,
                              "Player 1",
                              "Arial",
                              24,
                              "white",
                              bold=True))
        camera.draw(
            gamebox.from_text(camera.x - 400,
                              camera.y + 250,
                              "Hit Rate",
                              "Arial",
                              24,
                              "white",
                              bold=True))
        camera.draw(
            gamebox.from_text(camera.x + 400,
                              camera.y + 250,
                              "Hit Rate",
                              "Arial",
                              24,
                              "white",
                              bold=True))
        if p1_stat < 36:
            camera.draw(
                gamebox.from_color(camera.x - 400, camera.y + 275, "green",
                                   p1_stat * 3, 30))
            camera.draw(
                gamebox.from_text(camera.x - 400,
                                  camera.y + 275,
                                  str(p1_stat * 5),
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
        else:
            camera.draw(
                gamebox.from_text(camera.x - 400,
                                  camera.y + 275,
                                  "DANGER",
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
        if p2_stat < 36:
            camera.draw(
                gamebox.from_color(camera.x + 400, camera.y + 275, "green",
                                   p2_stat * 3, 30))
            camera.draw(
                gamebox.from_text(camera.x + 400,
                                  camera.y + 275,
                                  str(p2_stat * 5),
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
        else:
            camera.draw(
                gamebox.from_text(camera.x + 400,
                                  camera.y + 275,
                                  "DANGER",
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
        if mode == "time":
            second_time = submode * 60 - count
            if second_time < 10:
                zero = "0"
            else:
                zero = ""
            timer = str(format(second_time // 60, '2.0f')) + ":" + zero + str(
                format(second_time % 60, '.0f'))
            camera.draw(
                gamebox.from_text(camera.x,
                                  camera.y - 370,
                                  timer,
                                  "Arial",
                                  48,
                                  "blue",
                                  bold=True))
            if second_time <= 0:
                if p1_points > p2_points:
                    winner = "Player 1"
                elif p2_points > p1_points:
                    winner = "Player 2"
                elif p2_points == p1_points:
                    winner = "Tie"
                menu = 2
        if mode == "stock":
            p1_lives = submode - p2_points
            p2_lives = submode - p1_points
            camera.draw(
                gamebox.from_text(camera.x - 400,
                                  camera.y + 350,
                                  str(p1_lives) + " Lives",
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
            camera.draw(
                gamebox.from_text(camera.x + 400,
                                  camera.y + 350,
                                  str(p2_lives) + " Lives",
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
            if p1_lives == 0:
                winner = "Player 2"
                menu = 2
            elif p2_lives == 0:
                winner = "Player 1"
                menu = 2

        if p2_on:
            camera.draw(
                gamebox.from_text(camera.x + 400,
                                  camera.y + 200,
                                  "Player 2",
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
        elif p2_on is False:
            camera.draw(
                gamebox.from_text(camera.x + 400,
                                  camera.y + 200,
                                  "COM",
                                  "Arial",
                                  24,
                                  "white",
                                  bold=True))
    elif menu == 2:
        camera.clear("white")
        camera.draw(
            gamebox.from_text(camera.x,
                              camera.y - 100,
                              "Winner:",
                              "Arial",
                              24,
                              "black",
                              bold=True))
        if winner == "Player 1":
            camera.draw(
                gamebox.from_text(camera.x,
                                  camera.y,
                                  winner + " with " + str(p1_points) +
                                  " kills",
                                  "Arial",
                                  48,
                                  "black",
                                  bold=True))
        elif winner == "Player 2":
            camera.draw(
                gamebox.from_text(camera.x,
                                  camera.y,
                                  winner + " with " + str(p2_points) +
                                  " kills",
                                  "Arial",
                                  48,
                                  "black",
                                  bold=True))
        elif winner == "Tie":
            camera.draw(
                gamebox.from_text(camera.x,
                                  camera.y,
                                  winner + " by " + str(p1_points) + " kills",
                                  "Arial",
                                  48,
                                  "black",
                                  bold=True))
        camera.draw(
            gamebox.from_text(camera.x, camera.y + 300, "Press 'Enter' to End",
                              "Arial", 24, "black"))
        if pygame.K_RETURN in keys:
            gamebox.stop_loop()
    camera.display()
Example #9
0
def splash_end():
    global button
    gamebox.stop_loop()
    button.deactivate()
Example #10
0
def tick(keys):
    global start_game
    global game_over
    global fail_over
    b3 = gamebox.from_text(400,
                           300,
                           "Welcome to Yeti Jump! Get 10 points to win!",
                           "Arial",
                           40,
                           'red',
                           italic=True)
    b4 = gamebox.from_text(400,
                           400,
                           "Press s to start!",
                           "Arial",
                           40,
                           'red',
                           italic=True)
    camera.draw(b3)
    camera.draw(b4)
    if pygame.K_s in keys:
        start_game = True
    if start_game is True:
        if fail_over is False:
            if game_over is False:
                global counter
                global lives
                global character_score
                if pygame.K_RIGHT in keys:
                    character.x += 10
                if pygame.K_LEFT in keys:
                    character.x -= 10
                character.yspeed += 1
                character.y = character.y + character.yspeed
                camera.clear("cyan")
                camera.draw(b1)
                camera.draw("Lives: " + str(lives), "Arial", 24, "red", 100,
                            100)

                camera.draw(character)
                if character.y > 600 or 800 >= character.x <= 0:
                    lives -= 1
                    charater_score = 0
                    character.x = walls[-1].x
                    character.y = walls[-1].y
                    camera.draw(character)

                camera.draw("Character Score: " + str(character_score),
                            "Arial", 24, "red", 100, 30)

                camera.y -= 3
                b1.y = camera.y

                global counter
                counter += 1
                if counter % 50 == 0:
                    new_wall = gamebox.from_color(random.randint(100, 700),
                                                  camera.y - 300, "black",
                                                  random.randint(100, 250), 10)
                    walls.append(new_wall)
                    if character.y >= new_wall.y + 600 or character.x < 0 or character.x > 800:
                        lives -= 1
                        character.x = walls[-1].x
                        character.y = walls[-1].y
                        camera.draw(character)
                if counter % 40 == 0:
                    coins.append(
                        gamebox.from_color(random.randint(100, 550),
                                           (character.y - 200), "yellow", 10,
                                           10))
                for coin in coins:
                    camera.draw(coin)
                    if character.touches(coin):
                        coins.remove(coin)
                        coin_sound = gamebox.load_sound(
                            'http://theodoregray.com/PeriodicTable/Sounds/029.2.wav'
                        )
                        musicplayer0 = coin_sound.play()
                        character_score += 1
                        camera.draw("Character Score: " + str(character_score),
                                    "Arial", 24, "red", 100, 30)

                if counter % 45 == 0:
                    enemy.append(
                        gamebox.from_color(random.randint(100, 550),
                                           (character.y - 200), "red", 5, 5))
                multiplier = 1
                for thing in enemy:
                    thing.x += 10 * multiplier
                    if thing.x > 500 or thing.x < 300:
                        multiplier = multiplier * -1

                    camera.draw(thing)
                    if character.touches(thing):
                        enemy.remove(thing)
                        character_score -= 5
                        lives -= 1
                        camera.draw("Character Score: " + str(character_score),
                                    "Arial", 24, "red", 100, 30)

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

                if lives == 0:
                    fail_over = True
                if character_score is 10:
                    game_over = True

            else:
                camera.clear("white")
                camera.draw("You Win! Snooooow good", "Arial", 30, "red", 400,
                            300)
                camera.draw("Press q to quit", "Arial", 30, "red", 400, 500)
                if pygame.K_q in keys:
                    gamebox.stop_loop()
        else:
            camera.clear('white')
            camera.draw("Sorry you lost!", "Arial", 30, "red", 400, 250)
            camera.draw("Press q to quit", "Arial", 30, "red", 400, 450)

            if pygame.K_q in keys:
                gamebox.stop_loop()
    camera.display()
Example #11
0
def tick(keys):
    global level, room, char_health, char_speed, frames, half_frames, attack_cooldown, attack_burst, flipped, \
        ability_burst, ability, kill_count, dead_enemies, level_screen, game_over, boss_appear, boss_health, dead_boss

    if game_over:
        end_game()

    half_frames += 1
    if half_frames % 2 == 0:
        frames += 1

    attacking = False
    walking = False
    left = False
    ability = False

    # causes an error, quitting the game when F1 hit
    if pygame.K_F1 in keys:
        level = -3
        gamebox.stop_loop()

    # home screen
    if level == -1:
        if camera.mouseclick:
            if clicking(start):
                gamebox.stop_loop()
    # select char screen
    if level == 0:
        # depending on which character is clicked, sets variables for future use. Then, stops loop to go to next level
        if camera.mouseclick:
            if clicking(knight):
                character = knight
                char_sheet = knight_sheet
                ability_sheet = knight_ability_sheet
                global char_sheet
                global ability_sheet
                gamebox.stop_loop()
            if clicking(ranger):
                character = ranger
                char_sheet = ranger_sheet
                ability_sheet = ranger_ability_sheet
                global char_sheet, ability_sheet
                gamebox.stop_loop()
            global character
    # setup is over, we're ready to play! These are the controls for actual gameplay
    if 0 < level <= 2 and not level_screen:
        # level one setup
        if level == 1:
            camera.draw(background)
            room_setup()
        # level two setup
        if level == 2:
            camera.draw(background)
            room_setup()

        # use the arrows to move
        if pygame.K_w in keys:
            character.y -= char_speed
            walking = True
        if pygame.K_s in keys:
            character.y += char_speed
            walking = True
        if pygame.K_d in keys:
            character.x += char_speed
            walking = True
        if pygame.K_a in keys:
            character.x -= char_speed
            walking = True
            left = True
        # space bar to attack
        if camera.mouseclick:
            if attack_burst <= 20 and attack_cooldown <= 0:  # can't attack continuously. Can attack for 1/3 sec at time
                attacking = True
                attack_burst += 1
            if attack_burst >= 20:
                attack_cooldown = 15  # cooldown before you're allowed to attack again
            if attack_burst == 1 and character == ranger:
                fire_arrow()
        else:
            attack_burst = 0
        attack_cooldown -= 1
        # Q to use abilities
        if pygame.K_q in keys:
            if kill_count >= 3:  # can use ability if ability bar is full enough
                ability = True
                kill_count -= 3
                ability_burst = 0
        ability_burst += 1
        if ability_burst <= 60:  # can't use ability continuously. Can use 2 sec at a time
            ability = True

        # arrow animations and removal
        moving_arrows(arrows)
        moving_arrows(skeleton_arrows)
        moving_arrows(boss_arrows)

        # enemy AI, boss AI
        enemy_movement()
        if boss_appear and not dead_boss:
            boss_movement(frames)

        # running into doors
        room_movement()

        # collecting hearts
        for heart in life:
            if character.touches(heart):
                life.remove(heart)
                # you can't have more than 100% health, silly
                if char_health > 90:
                    char_health = 100
                else:
                    char_health += 20

        # interactions with enemies. If knight is attacking, they die. If not, you take damage and get knocked back
        # arrows kill enemies
        for room_num, where in enumerate(enemies):
            if room_num == room:
                for index, (enemy, alive, species) in enumerate(where):
                    if character.touches(enemy) and alive:
                        if not ability:
                            rebound(character, enemy, attacking)
                            if not attacking or character == ranger:
                                char_health = take_damage(20, char_health)
                            else:
                                enemies[room_num][index][1] = False
                                dead_enemy(enemy)
                        if ability and (attacking or character == knight):
                            enemies[room_num][index][1] = False
                            dead_enemy(enemy)
                    for sharp in arrows:
                        if sharp[0].touches(enemy) and alive:
                            enemies[room_num][index][1] = False
                            dead_enemy(enemy)
                    for sharp in skeleton_arrows:
                        if sharp[0].touches(character):
                            skeleton_arrows.remove(sharp)
                            char_health = take_damage(20, char_health)

        # only draws living enemies. Also, checks to see if all enemies are dead
        num_enemies = 0
        for room_num, where in enumerate(enemies):
            for index, (enemy, alive, species) in enumerate(where):
                if alive:
                    num_enemies += 1
                    if room_num == room:
                        camera.draw(enemy)
        if num_enemies == 0:
            dead_enemies = True

        # handles interactions between character and bosses. Boss must be
        if character.touches(boss) and boss_appear:
            if not attacking and not ability:
                char_health = take_damage(20, char_health)
                rebound(character, boss, attacking)
            if attacking and character == knight:
                boss_health = take_damage(20, boss_health)
                rebound(character, boss, attacking)
        # ranger arrow interactions with bosses
        for arrow in arrows:
            if arrow[0].touches(boss) and boss_appear:
                boss_health = take_damage(10, boss_health)
                arrows.remove(arrow)
        # boss arrow interactions with character
        for sharp in boss_arrows:
            if sharp[0].touches(character):
                boss_arrows.remove(sharp)
                char_health = take_damage(20, char_health)

        # you can't run through walls
        [character.move_to_stop_overlapping(wall) for wall in border]
        [boss.move_to_stop_overlapping(wall) for wall in border]

        # draws walls, hearts after enemy death
        [camera.draw(wall) for wall in border]
        [camera.draw(heart) for heart in life]

        # exits level once you get to the end of the level. Also resets room to 0
        if character.touches(ladder) and dead_enemies and dead_boss:
            level_screen = True
            gamebox.stop_loop()

        # your health. Game pauses when you run out of life
        if char_health <= 0:
            game_over = True
        if character == ranger:
            char_health_bar = gamebox.from_image(
                75, 550, char_health_sheet[5 - int(char_health / 20)])
        if character == knight:
            char_health_bar = gamebox.from_image(
                75, 550, char_health_sheet[5 - int(char_health / 40)])
        camera.draw(char_health_bar)
        if boss_health <= 0:
            dead_boss = True
            boss_appear = False

        char_ability_bar = gamebox.from_image(
            75, 50, ability_bar_sheet[5 - kill_count])
        char_ability_bar.height = 20
        camera.draw(char_ability_bar)

        who_walking(char_sheet, attacking, walking, left, ability,
                    ability_sheet)

        camera.draw(character)

    if level == 3:
        camera.draw(
            gamebox.from_text(400, 300, "You Win!", "Arial", 40, "gray"))
        if camera.mouseclick:
            gamebox.stop_loop()

    camera.display()

    # adds a level screen between each level. Click to continue
    if level_screen and level > 0:
        camera.clear('black')
        room = 0
        camera.draw(gamebox.from_image(400, 300,
                                       'Level' + str(level) + '.png'))
        camera.display()
        if camera.mouseclick:
            level_screen = False
Example #12
0
        char_select()
        character.height = 60
        if character == ranger:
            char_health = 100  # you start off healthy. Lucky you
        if character == knight:
            char_health = 200  # it's way harder to play as the knight. You get extra health
        room = 0  # keeps track of which room you're in
        kill_count = 0  # for abilities bar. Maximum of 5. Using ability decreases by 3
        life = []  # list of hearts generated from dead enemies
        arrows = [
        ]  # list of all ranger arrows. Are deleted as they move off the screen
        skeleton_arrows = [
        ]  # list of all skeleton arrows. Again, deleted as they move off the screen
        boss_arrows = []
        dead_enemies = False  # ladder doesn't appear until all enemies killed (and boss is killed. Handled elsewhere)
        boss_appear = False  # boss only appears in room 3
        flipped = True  # is the char flipped?
        level += 1

    # setup for all levels of actual gameplay
    while 0 < level <= 2:
        levels()

    if level == 3:
        camera.clear("black")
        gamebox.timer_loop(ticks_per_second, tick)
        level = -1
    else:  # throws an error that stops the game. Hit F1 to get here
        pygame.quit()
        gamebox.stop_loop()
Example #13
0
def tick(keys):
    global start_game
    global game_over
    global fail_over
    b3= gamebox.from_text(400,300,"Welcome to Yeti Jump! Get 10 points to win!", "Arial", 40, 'red', italic=True)
    b4 = gamebox.from_text(400,400, "Press s to start!","Arial", 40, 'red', italic=True)
    camera.draw(b3)
    camera.draw(b4)
    if pygame.K_s in keys:
        start_game = True
    if start_game is True:
        if fail_over is False:
            if game_over is False:
                global counter
                global lives
                global character_score
                if pygame.K_RIGHT in keys:
                    character.x += 10
                if pygame.K_LEFT in keys:
                    character.x -= 10
                character.yspeed += 1
                character.y = character.y + character.yspeed
                camera.clear("cyan")
                camera.draw(b1)
                camera.draw("Lives: " + str(lives), "Arial", 24, "red", 100, 100)

                camera.draw(character)
                if character.y > 600 or 800 >= character.x <= 0:
                    lives -= 1
                    charater_score = 0
                    character.x = walls[-1].x
                    character.y = walls[-1].y
                    camera.draw(character)

                camera.draw("Character Score: "+ str(character_score), "Arial", 24, "red", 100, 30)

                camera.y -= 3
                b1.y = camera.y

                global counter
                counter += 1
                if counter % 50 == 0:
                    new_wall = gamebox.from_color(random.randint(100,700), camera.y-300,  "black", random.randint(100,250), 10)
                    walls.append(new_wall)
                    if character.y >= new_wall.y + 600 or character.x < 0 or character.x > 800     :
                        lives -= 1
                        character.x = walls[-1].x
                        character.y = walls[-1].y
                        camera.draw(character)
                if counter%40 == 0:
                    coins.append(gamebox.from_color(random.randint(100,550),(character.y-200),"yellow",10,10))
                for coin in coins:
                    camera.draw(coin)
                    if character.touches(coin):
                        coins.remove(coin)
                        coin_sound = gamebox.load_sound('http://theodoregray.com/PeriodicTable/Sounds/029.2.wav')
                        musicplayer0=coin_sound.play()
                        character_score += 1
                        camera.draw("Character Score: " + str(character_score), "Arial", 24, "red", 100, 30)

                if counter%45 == 0:
                    enemy.append(gamebox.from_color(random.randint(100,550),(character.y-200),"red",5,5))
                multiplier = 1
                for thing in enemy:
                    thing.x += 10*multiplier
                    if thing.x >500 or thing.x<300:
                        multiplier = multiplier*-1

                    camera.draw(thing)
                    if character.touches(thing):
                        enemy.remove(thing)
                        character_score -= 5
                        lives -= 1
                        camera.draw("Character Score: " + str(character_score), "Arial", 24, "red", 100, 30)

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


                if lives == 0:
                    fail_over = True
                if character_score is 10:
                    game_over = True



            else:
                camera.clear("white")
                camera.draw("You Win! Snooooow good", "Arial", 30,"red", 400, 300)
                camera.draw("Press q to quit", "Arial", 30, "red", 400, 500)
                if pygame.K_q in keys:
                    gamebox.stop_loop()
        else:
            camera.clear('white')
            camera.draw("Sorry you lost!", "Arial", 30, "red", 400, 250)
            camera.draw("Press q to quit", "Arial", 30, "red", 400, 450)
   
            if pygame.K_q in keys:
                gamebox.stop_loop()
    camera.display()
Example #14
0
def tick(keys):

    camera.clear("green")

    global char
    global counter
    global score
    global timer
    global scorebox
    global gems_found
    global frame
    global direction

    if boolean_start == True:

        if char.x > 800:
            camera.x = 1200
            camera.draw(background2)
            score.x = camera.x
            scorebox.x = camera.x

        else:
            camera.x = 400
            camera.draw(background)

        arrow = gamebox.from_text(750, 550, '>', 100, 'yellow')
        camera.draw(arrow)
        camera.draw(char)

        # drawing of the obstacles
        camera.draw(start_obstacle)
        if char.touches(start_obstacle):
            char.move_to_stop_overlapping(start_obstacle)
        camera.draw(start_obstacle2)
        if char.touches(start_obstacle2):
            char.move_to_stop_overlapping(start_obstacle2)

        for aq_draw in fences:
            camera.draw(aq_draw)
            if char.touches(aq_draw):
                char.move_to_stop_overlapping(aq_draw)

        for j in lower_left:
            camera.draw(j)
            if char.touches(j):
                char.move_to_stop_overlapping(j)
        for a in right:
            camera.draw(a)
            if char.touches(a):
                char.move_to_stop_overlapping(a)
        for t in middle:
            camera.draw(t)
            if char.touches(t):
                char.move_to_stop_overlapping(t)
        for q in middle2:
            camera.draw(q)
            if char.touches(q):
                char.move_to_stop_overlapping(q)
        for e in top_left:
            camera.draw(e)
            if char.touches(e):
                char.move_to_stop_overlapping(e)
        for r in top_middle:
            camera.draw(r)
            if char.touches(r):
                char.move_to_stop_overlapping(r)

        #obstacles of scene 2
        for i in scn2:
            camera.draw(i)
            if char.touches(i):
                char.move_to_stop_overlapping(i)

        camera.draw(fence_scn2)
        if char.touches(fence_scn2):
            char.move_to_stop_overlapping(fence_scn2)

        for err in water_left:
            camera.draw(err)
            if char.touches(err):
                char.move_to_stop_overlapping(err)

        for ert5 in middle_scn2:
            camera.draw(ert5)
            if char.touches(ert5):
                char.move_to_stop_overlapping(ert5)

        for ert6 in middle_scn3:
            camera.draw(ert6)
            if char.touches(ert6):
                char.move_to_stop_overlapping(ert6)

        for mnt in fence_scn3:
            camera.draw(mnt)
            if char.touches(mnt):
                char.move_to_stop_overlapping(mnt)

        for mnt1 in right_most:
            camera.draw(mnt1)
            if char.touches(mnt1):
                char.move_to_stop_overlapping(mnt1)

        for mnt2 in bottom_scn2:
            camera.draw(mnt2)
            if char.touches(mnt2):
                char.move_to_stop_overlapping(mnt2)

        camera.draw(start_obstacle_s2)
        if char.touches(start_obstacle_s2):
            char.move_to_stop_overlapping(start_obstacle_s2)

        camera.draw(start_obstacles_s2)
        if char.touches(start_obstacles_s2):
            char.move_to_stop_overlapping(start_obstacles_s2)

        for mnt3 in fences_s2:
            camera.draw(mnt3)
            if char.touches(mnt3):
                char.move_to_stop_overlapping(mnt3)
        '''final obstacle'''
        for s1a in final_boundary:
            camera.draw(s1a)
            if char.touches(s1a):
                char.move_to_stop_overlapping(s1a)

        # keys and animation
        lsheet = [sht[9], sht[10], sht[11]]
        rsheet = [sht[3], sht[4], sht[5]]
        usheet = [sht[6], sht[7], sht[8]]
        dsheet = [sht[0], sht[1], sht[2]]
        idle = sht[1]

        #keys
        if pygame.K_UP in keys:
            char.y -= 5
            char.image = usheet[(counter // 3) % len(usheet)]
            camera.draw(char)
        if pygame.K_DOWN in keys:
            char.y += 5
            char.image = dsheet[(counter // 3) % len(dsheet)]
            camera.draw(char)
        if pygame.K_RIGHT in keys:
            char.x += 5
            char.image = rsheet[(counter // 3) % len(rsheet)]
            camera.draw(char)
        if pygame.K_LEFT in keys:
            char.x -= 5
            char.image = lsheet[(counter // 3) % len(lsheet)]
            camera.draw(char)
        # char.speedx == 0 and char.speedy == 0
        if (not pygame.K_UP in keys) and (not pygame.K_DOWN in keys) and (
                not pygame.K_RIGHT in keys) and (not pygame.K_LEFT in keys):
            char.image = idle
            camera.draw(char)
        if pygame.K_ESCAPE in keys:
            gamebox.stop_loop()

        #character moving to screen edge

        if char.y == 600:
            char.y = 0
        elif char.x == 0:
            char.x = width
        elif char.y == 0:
            char.y = height

        #gem function where character collects the gems
        for i in drawn:
            camera.draw(i)

        for i in char_del:
            if pygame.K_0 in keys:
                camera.draw(i)

        if len(drawn) > 0:
            for gem in drawn:
                if char.touches(gem):
                    char_del.append(gem)
                    drawn.remove(gem)
                    gems_found += 1
        # else:
        #     if char.touches(char_del[0]):
        #         drawn.append(char_del[0])
        #         char_del.remove(char_del[0])

        if counter % 300 == 0:
            if len(gems):
                drawn.append(gems[0])
                gems.remove(gems[0])

        counter += 1
        timer = str(round((counter / 25), 1))
        score = gamebox.from_text(400,
                                  500,
                                  'Gems Found: ' + str(gems_found) +
                                  '/7    Time: ' + timer + ' s',
                                  24,
                                  "white",
                                  italic=False)
        scorebox = gamebox.from_color(400, 500, "black", 270, 30)
        camera.draw(scorebox)
        camera.draw(score)

        scorebox_scene2 = gamebox.from_color(1200, 500, "black", 270, 30)
        score2 = gamebox.from_text(1200,
                                   500,
                                   'Gems Found: ' + str(gems_found) +
                                   '/7    Time: ' + timer + ' s',
                                   24,
                                   "white",
                                   italic=False)
        camera.draw(scorebox_scene2)
        camera.draw(score2)

        # When the game is won:
        if gems_found == 7:
            camera.clear('black')
            camera.x = 400
            camera.draw(background)
            logo2 = gamebox.from_image(400, 150, 'All_Gems.png')
            camera.draw(logo2)
            ending_note = gamebox.from_text(camera.x, 300, 'Congratulations!',
                                            80, 'Gold')
            camera.draw(ending_note)
            fin_time = gamebox.from_text(
                camera.x, 400, 'Time procrastinated: ' + timer + ' s', 60,
                'Gold')
            camera.draw(fin_time)
            end_instructions = gamebox.from_text(camera.x, 500,
                                                 'Press ESC to EXIT', 40,
                                                 'white')
            camera.draw(end_instructions)
            gamebox.pause()
        camera.display()

    else:
        splashscreen(keys)