Пример #1
0
    def level_2(self):
        clock = pygame.time.Clock()

        SCREEN.blit(self.menu_image, self.menu_pos)
        SCREEN.blit(self.cursor_image, (391, 103))
        pygame.display.flip()

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return (True, True, True)
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        return (True, True, True)
                    elif event.key == pygame.K_RETURN:
                        return (True, True, False)
                    elif event.key == pygame.K_DOWN:
                        sound.cursor.play()
                        return (False, 'level5', False)
                    elif event.key == pygame.K_RIGHT:
                        sound.cursor.play()
                        return (False, 'level3', False)
                    elif event.key == pygame.K_LEFT:
                        sound.cursor.play()
                        return (False, 'level1', False)
            clock.tick(10)
Пример #2
0
    def draw(self, **kwargs):
        SCREEN.fill(self.background)

        if 'life' in kwargs:
            if kwargs['life'] != None:
                for cell in kwargs['life']:
                    if cell.pos[0] >= 0 and cell.pos[0] <= WIDTH:
                        if cell.pos[1] >= 0 and cell.pos[1] <= HEIGHT:
                            cell.draw()

        for rect in self.rects:
            pygame.draw.rect(
                SCREEN, rect['color'],
                (rect['x'], rect['y'], rect['WIDTH'], rect['HEIGHT']),
                rect['stroke'])

        for line in self.lines:
            pygame.draw.line(SCREEN, line['color'],
                             (line['startx'], line['starty']),
                             (line['endx'], line['endy']), line['width'])

        for text in self.texts:
            SCREEN.blit(text[0], (text[1]))

        button_list = self.buttons.keys()
        for button in button_list:
            self.buttons[button].draw(SCREEN)
Пример #3
0
    def __init__(self):
        TScreen = pygame.image.load('images/demo/titlescreen.png').convert()

        EXIT_GAME = Main_TitleScreen()
        while not EXIT_GAME:
            SCREEN.blit(TScreen, (0, 0))
            EXIT_GAME = Level_Select(TScreen)
Пример #4
0
    def draw(self, degrade_alpha):
        if len(self.p_list1) > 1 and len(self.p_list2) > 1 and len(
                self.p_list3) > 1:
            self.surface.fill(BLACK)
            self.init_color_length -= 1

            p_list1 = CAMERA.apply_points(self.p_list1)
            p_list2 = CAMERA.apply_points(self.p_list2)
            p_list3 = CAMERA.apply_points(self.p_list3)

            if self.init_color_length < 0:
                pygame.draw.aalines(self.surface, (self.color1), False,
                                    p_list1, 1)
                pygame.draw.aalines(self.surface, (self.color2), False,
                                    p_list2, 1)
                pygame.draw.aalines(self.surface, (self.color3), False,
                                    p_list3, 1)
            else:
                pygame.draw.aalines(self.surface, (self.init_color), False,
                                    p_list1, 1)
                pygame.draw.aalines(self.surface, (self.init_color), False,
                                    p_list2, 1)
                pygame.draw.aalines(self.surface, (self.init_color), False,
                                    p_list3, 1)

            self.surface.set_alpha(self.alpha)
            if degrade_alpha:
                self.alpha -= ALPHA_RATE
            SCREEN.blit(self.surface, (0, 0))
Пример #5
0
    def __init__(self):
        TScreen = pygame.image.load('images/demo/titlescreen.png').convert()

        self.menu_image = pygame.image.load(
            'images/demo/stageselect.png').convert()
        self.menu_rect = self.menu_image.get_rect()
        self.menu_pos = (SCREEN_WIDTH / 2 - self.menu_rect.w / 2,
                         SCREEN_HEIGHT / 2 - self.menu_rect.h / 2)

        self.cursor_image = pygame.image.load(
            'images/demo/stageselect_cursor.png').convert_alpha()
        self.cursor_rect = self.cursor_image.get_rect()

        self.state = 'level1'

        EXIT_GAME = Demo_TitleScreen()
        while not EXIT_GAME:
            if MUSIC:
                music = pygame.mixer.music.load(
                    'sound/music/s3kfileselect.mp3')
                pygame.mixer.music.play(-1)
            SCREEN.blit(TScreen, (0, 0))
            SCREEN.blit(self.menu_image, self.menu_pos)
            pygame.display.flip()

            selected = False
            while not selected:
                change = False
                while not change:
                    if self.state == 'level1':
                        selected, change, EXIT_GAME = self.level_1()
                    elif self.state == 'level2':
                        selected, change, EXIT_GAME = self.level_2()
                    elif self.state == 'level3':
                        selected, change, EXIT_GAME = self.level_3()
                    elif self.state == 'level4':
                        selected, change, EXIT_GAME = self.level_4()
                    elif self.state == 'level5':
                        selected, change, EXIT_GAME = self.level_5()
                    elif self.state == 'level6':
                        selected, change, EXIT_GAME = self.level_6()

                    if change != True:
                        self.state = change
                        change = False

            if MUSIC:
                pygame.mixer.music.fadeout(1000)
            if not EXIT_GAME:
                Finished, EXIT_GAME = Level(
                    self.state)  #Demo_Level(self.state)
                pygame.mixer.music.fadeout(250)
Пример #6
0
def help_menu():
    help_img = pygame.image.load('images/menu/help_menu.png').convert()
    help_img.set_colorkey(COLOR_KEY)
    help_rect = help_img.get_rect()
    help_pos = (0, 0)
    clock = pygame.time.Clock()
    EXIT = False

    while not EXIT:
        SCREEN.blit(help_img, help_pos)
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                    return False
        clock.tick(MAX_FPS)
Пример #7
0
def Demo_TitleScreen():
    title = pygame.image.load('images/demo/titlescreen.png').convert()
    '''
	if MUSIC:
		music = pygame.mixer.music.load('sound/music/cheetah.mp3')
		pygame.mixer.music.play(-1)
	'''
    clock = pygame.time.Clock()
    over = False
    while not over:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    return True
                elif event.key == pygame.K_RETURN:
                    return False

        SCREEN.blit(title, (0, 0))
        pygame.display.flip()
        clock.tick(10)
Пример #8
0
    def draw(self, degrade_alpha):
        if len(self.p_list1) > 1 and len(self.p_list2) > 1 and len(self.p_list3) > 1:
            self.surface.fill(BLACK)
            self.init_color_length -= 1

            p_list1 = CAMERA.apply_points(self.p_list1)
            p_list2 = CAMERA.apply_points(self.p_list2)
            p_list3 = CAMERA.apply_points(self.p_list3)

            if self.init_color_length < 0:
                pygame.draw.aalines(self.surface, (self.color1), False, p_list1, 1)
                pygame.draw.aalines(self.surface, (self.color2), False, p_list2, 1)
                pygame.draw.aalines(self.surface, (self.color3), False, p_list3, 1)
            else:
                pygame.draw.aalines(self.surface, (self.init_color), False, p_list1, 1)
                pygame.draw.aalines(self.surface, (self.init_color), False, p_list2, 1)
                pygame.draw.aalines(self.surface, (self.init_color), False, p_list3, 1)

            self.surface.set_alpha(self.alpha)
            if degrade_alpha:
                self.alpha -= ALPHA_RATE
            SCREEN.blit(self.surface, (0, 0))
Пример #9
0
def Pause_Screen(prev_screen):

    menu_image = pygame.image.load('images/gui/pause_menu.png').convert()
    menu_rect = menu_image.get_rect()
    menu_pos = (SCREEN_WIDTH / 2 - menu_rect.w / 2,
                SCREEN_HEIGHT / 2 - menu_rect.h / 2)
    menu_list = [(425, 221), (425, 269), (425, 317), (425, 365)]  #48

    cursor_image = pygame.image.load(
        'images/gui/cursor/pause_menu_cursor.png').convert()
    cursor_image.set_colorkey(CHROMA_KEY)
    cursor_rect = cursor_image.get_rect()

    cursor_state = 0

    clock = pygame.time.Clock()

    pause = True

    while pause:
        if SHOW_FPS:
            SCREEN.blit(prev_screen, (0, 0))
        SCREEN.blit(menu_image, menu_pos)
        FPS = clock.get_fps()
        if SHOW_FPS:
            show_fps(FPS)

        if cursor_state == -1:  #Precaucion para que no salga fuera de rango
            cursor_state = 3
        elif cursor_state == 4:
            cursor_state = 0
        SCREEN.blit(cursor_image, menu_list[cursor_state])
        pygame.display.flip()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False, True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    if cursor_state == 0:
                        return 'Continuar'
                    elif cursor_state == 1:
                        if Confirmation(prev_screen):
                            return 'Reiniciar'
                    elif cursor_state == 2:
                        if Confirmation(prev_screen):
                            return 'Menu'
                    elif cursor_state == 3:
                        if Confirmation(prev_screen):
                            return 'Salir'
                elif event.key == pygame.K_DOWN:
                    cursor_state += 1
                    sound.cursor.play()
                elif event.key == pygame.K_UP:
                    cursor_state -= 1
                    sound.cursor.play()

        clock.tick(MAX_FPS)
Пример #10
0
    def draw(self, **kwargs):
        SCREEN.fill(self.background)

        if 'life' in kwargs:
            if kwargs['life'] != None:
                for cell in kwargs['life']:
                    if cell.pos[0] >= 0 and cell.pos[0] <= WIDTH:
                        if cell.pos[1] >= 0 and cell.pos[1] <= HEIGHT:
                            cell.draw()

        for rect in self.rects:
            pygame.draw.rect(SCREEN, rect['color'], (rect['x'],rect['y'],rect['WIDTH'],rect['HEIGHT']), rect['stroke'])

        for line in self.lines:
            pygame.draw.line(SCREEN, line['color'], (line['startx'],line['starty']), (line['endx'],line['endy']), line['width'])


        for text in self.texts:
            SCREEN.blit(text[0], (text[1]))

        button_list = self.buttons.keys()
        for button in button_list:
            self.buttons[button].draw(SCREEN)
Пример #11
0
def start_menu():
    background = pygame.image.load('images/background/sky1.png').convert()
    startMenu_img = pygame.image.load('images/menu/start_menu.png').convert()
    startMenu_img.set_colorkey(COLOR_KEY)
    startMenu_rect = startMenu_img.get_rect()
    startMenu_pos = (SCREEN_WIDTH / 2 - startMenu_rect.w / 2,
                     SCREEN_HEIGHT / 2 - startMenu_rect.h / 2)

    menu_list = [(282, 108), (282, 216), (282, 330)]

    select_button = pygame.image.load(
        'images/menu/startMenu_btnSelect.png').convert()
    select_button.set_colorkey(COLOR_KEY)

    select_state = 0

    clock = pygame.time.Clock()

    QUIT = False

    while not QUIT:
        SCREEN.blit(background, (0, 0))
        SCREEN.blit(startMenu_img, startMenu_pos)
        SCREEN.blit(select_button, menu_list[select_state])
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    QUIT = True
                elif event.type == pygame.QUIT:
                    QUIT = True
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                        if select_state == 0:
                            QUIT = start_game()
                        elif select_state == 1:
                            QUIT = help_menu()
                        elif select_state == 2:
                            QUIT = True
                    elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
                        if select_state == 0:
                            select_state = 1
                        elif select_state == 1:
                            select_state = 2
                        elif select_state == 2:
                            select_state = 0
                    elif event.key == pygame.K_UP or event.key == pygame.K_w:
                        if select_state == 0:
                            select_state = 2
                        elif select_state == 1:
                            select_state = 0
                        elif select_state == 2:
                            select_state = 1
        clock.tick(MAX_FPS)
    return True
Пример #12
0
def DeadPlayer(prev_screen):

    menu_image = pygame.image.load('images/gui/retry.png').convert()
    menu_rect = menu_image.get_rect()
    menu_pos = (SCREEN_WIDTH / 2 - menu_rect.w / 2,
                SCREEN_HEIGHT / 2 - menu_rect.h / 2)
    menu_list = [(399, 284), (518, 284)]

    cursor_image = pygame.image.load(
        'images/gui/cursor/confirmation_cursor.png').convert()
    cursor_image.set_colorkey(CHROMA_KEY)
    cursor_rect = cursor_image.get_rect()

    cursor_state = 0

    clock = pygame.time.Clock()

    pause = True

    while pause:
        if SHOW_FPS:
            SCREEN.blit(prev_screen, (0, 0))
        SCREEN.blit(menu_image, menu_pos)
        FPS = clock.get_fps()
        if SHOW_FPS:
            show_fps(FPS)

        if cursor_state == -1:  #Precaucion para que no salga fuera de rango
            cursor_state = 1
        elif cursor_state == 2:
            cursor_state = 0
        SCREEN.blit(cursor_image, menu_list[cursor_state])
        pygame.display.flip()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False, True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    if cursor_state == 0:
                        return True, False
                    elif cursor_state == 1:
                        return False, False
                elif event.key == pygame.K_RIGHT:
                    cursor_state += 1
                    sound.cursor.play()
                elif event.key == pygame.K_LEFT:
                    cursor_state -= 1
                    sound.cursor.play()

        clock.tick(MAX_FPS)
Пример #13
0
def pause_menu(paused_screen):
    pause_img = pygame.image.load('images/menu/pause_menu.png').convert()
    pause_img.set_colorkey(COLOR_KEY)
    pause_rect = pause_img.get_rect()
    pause_pos = (SCREEN_WIDTH / 2 - pause_rect.w / 2,
                 SCREEN_HEIGHT / 2 - pause_rect.h / 2)

    menu_list = [(282, 108), (282, 216), (282, 330)]

    select_button = pygame.image.load(
        'images/menu/startMenu_btnSelect.png').convert()
    select_button.set_colorkey(COLOR_KEY)

    select_state = 0

    clock = pygame.time.Clock()
    PAUSE = True

    while PAUSE:
        SCREEN.blit(paused_screen, (0, 0))
        SCREEN.blit(pause_img, pause_pos)
        SCREEN.blit(select_button, menu_list[select_state])
        pygame.display.flip()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                    if select_state == 0:
                        return 'Continue'
                    elif select_state == 1:
                        return help_menu()
                    elif select_state == 2:
                        return 'Main'
                elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
                    if select_state == 0:
                        select_state = 1
                    elif select_state == 1:
                        select_state = 2
                    elif select_state == 2:
                        select_state = 0
                elif event.key == pygame.K_UP or event.key == pygame.K_w:
                    if select_state == 0:
                        select_state = 2
                    elif select_state == 1:
                        select_state = 0
                    elif select_state == 2:
                        select_state = 1
        clock.tick(MAX_FPS)
Пример #14
0
def show_fps(FPS):
    fonty = pygame.font.SysFont('Arial', 20)  #Pokemon FireLeaf
    image = fonty.render('FPS:' + str(int(FPS)), False, (0, 0, 0))
    SCREEN.blit(image, (0, 0))
Пример #15
0
 def draw(self, pos_x, pos_y):
     """Méthod allowing to blit an image"""
     SCREEN.blit(self.image, (pos_x, pos_y))